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 } |
| 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 assertEquals(object, call(strictFunctionArrowEval, object, "this")); |
| 53 assertEquals(undefined, call(strictFunctionArrowEval, undefined, "this")); |
| 54 |
| 55 assertEquals(object, |
| 56 call(sloppyFunctionArrowEval, object, "(()=>this)()")); |
| 57 assertEquals(global, |
| 58 call(sloppyFunctionArrowEval, undefined, "(()=>this)()")); |
| 59 assertEquals(object, |
| 60 call(strictFunctionArrowEval, object, "(()=>this)()")); |
| 61 assertEquals(undefined, |
| 62 call(strictFunctionArrowEval, undefined, "(()=>this)()")); |
| 63 |
| 64 assertEquals(global, call(arrowInsideWith, undefined)); |
| 65 assertEquals(global, call(arrowInsideWith, object)); |
| 66 assertEquals(global, call(arrowInsideWithEval, undefined, "this")); |
| 67 assertEquals(global, call(arrowInsideWithEval, object, "this")); |
| 68 assertEquals(global, call(arrowInsideWithEval, undefined, "(()=>this)()")); |
| 69 assertEquals(global, call(arrowInsideWithEval, object, "(()=>this)()")); |
OLD | NEW |