Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Flags: --harmony-arrow-functions | |
| 6 | |
| 7 var object = {}; | |
| 8 var global = this; | |
| 9 var call = Function.call.bind(Function.call); | |
| 10 | |
| 11 var globalSloppyArrow = ()=>this; | |
| 12 var globalStrictArrow = ()=>{ "use strict"; return this; }; | |
| 13 var globalSloppyArrowEval = (s)=>eval(s); | |
| 14 var globalStrictArrowEval = (s)=>{ "use strict"; return eval(s); }; | |
| 15 | |
| 16 var sloppyFunctionArrow = function(){ return (()=>this)(); }; | |
| 17 var strictFunctionArrow = function(){ "use strict"; | |
| 18 return (()=>this)(); }; | |
| 19 var sloppyFunctionEvalArrow = function(){ return eval("(()=>this)()"); }; | |
| 20 var strictFunctionEvalArrow = function(){ "use strict"; | |
| 21 return eval("(()=>this)()"); }; | |
| 22 var sloppyFunctionArrowEval = function(s) { return (()=>eval(s))(); }; | |
| 23 var strictFunctionArrowEval = function(s) { "use strict"; | |
| 24 return (()=>eval(s))(); }; | |
| 25 | |
| 26 var withObject = { ['this']: object } | |
|
rossberg
2015/04/23 13:31:45
Nit: you don't need the brackets
| |
| 27 var arrowInsideWith, arrowInsideWithEval; | |
| 28 with (withObject) { | |
| 29 arrowInsideWith = ()=>this; | |
| 30 arrowInsideWithEval = (s)=>eval(s); | |
| 31 } | |
| 32 | |
| 33 assertEquals(global, call(globalSloppyArrow, object)); | |
| 34 assertEquals(global, call(globalStrictArrow, object)); | |
| 35 assertEquals(global, call(globalSloppyArrowEval, object, "this")); | |
| 36 assertEquals(global, call(globalStrictArrowEval, object, "this")); | |
| 37 assertEquals(global, call(globalSloppyArrowEval, object, "(()=>this)()")); | |
| 38 assertEquals(global, call(globalStrictArrowEval, object, "(()=>this)()")); | |
| 39 | |
| 40 assertEquals(object, call(sloppyFunctionArrow, object)); | |
| 41 assertEquals(global, call(sloppyFunctionArrow, undefined)); | |
| 42 assertEquals(object, call(strictFunctionArrow, object)); | |
| 43 assertEquals(undefined, call(strictFunctionArrow, undefined)); | |
| 44 | |
| 45 assertEquals(object, call(sloppyFunctionEvalArrow, object)); | |
| 46 assertEquals(global, call(sloppyFunctionEvalArrow, undefined)); | |
| 47 assertEquals(object, call(strictFunctionEvalArrow, object)); | |
| 48 assertEquals(undefined, call(strictFunctionEvalArrow, undefined)); | |
| 49 | |
| 50 assertEquals(object, call(sloppyFunctionArrowEval, object, "this")); | |
| 51 assertEquals(global, call(sloppyFunctionArrowEval, undefined, "this")); | |
| 52 // TODO(wingo): Scoping of "this" appears to be fine, but oddly the "s" | |
| 53 // in function(s) { return ()=>eval(s) } doesn't resolve to the "s" | |
| 54 // parameter in strict mode. Re-enable these tests once that bug is | |
| 55 // fixed. | |
| 56 //assertEquals(object, call(strictFunctionArrowEval, object, "this")); | |
| 57 //assertEquals(undefined, call(strictFunctionArrowEval, undefined, "this")); | |
| 58 | |
| 59 assertEquals(object, | |
| 60 call(sloppyFunctionArrowEval, object, "(()=>this)()")); | |
| 61 assertEquals(global, | |
| 62 call(sloppyFunctionArrowEval, undefined, "(()=>this)()")); | |
| 63 // TODO(wingo): Same as above. | |
| 64 //assertEquals(object, | |
| 65 // call(strictFunctionArrowEval, object, "(()=>this)()")); | |
| 66 //assertEquals(undefined, | |
| 67 // call(strictFunctionArrowEval, undefined, "(()=>this)()")); | |
| 68 | |
| 69 assertEquals(global, call(arrowInsideWith, undefined)); | |
| 70 assertEquals(global, call(arrowInsideWith, object)); | |
| 71 assertEquals(global, call(arrowInsideWithEval, undefined, "this")); | |
| 72 assertEquals(global, call(arrowInsideWithEval, object, "this")); | |
| 73 assertEquals(global, call(arrowInsideWithEval, undefined, "(()=>this)()")); | |
| 74 assertEquals(global, call(arrowInsideWithEval, object, "(()=>this)()")); | |
| OLD | NEW |