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() { | |
17 return (() => this)(); | |
18 }; | |
19 var strictFunctionArrow = function() { | |
20 "use strict"; | |
21 return (() => this)(); | |
22 }; | |
23 var sloppyFunctionEvalArrow = function() { | |
24 return eval("(() => this)()"); | |
25 }; | |
26 var strictFunctionEvalArrow = function() { | |
27 "use strict"; | |
28 return eval("(() => this)()"); | |
29 }; | |
30 var sloppyFunctionArrowEval = function(s) { | |
31 return (() => eval(s))(); | |
32 }; | |
33 var strictFunctionArrowEval = function(s) { | |
34 "use strict"; | |
35 return (() => eval(s))(); | |
36 }; | |
37 | |
38 var withObject = { 'this': object } | |
39 var arrowInsideWith, arrowInsideWithEval; | |
40 with (withObject) { | |
41 arrowInsideWith = () => this; | |
42 arrowInsideWithEval = (s) => eval(s); | |
43 } | |
44 | |
45 assertEquals(global, call(globalSloppyArrow, object)); | |
46 assertEquals(global, call(globalStrictArrow, object)); | |
47 assertEquals(global, call(globalSloppyArrowEval, object, "this")); | |
48 assertEquals(global, call(globalStrictArrowEval, object, "this")); | |
49 assertEquals(global, call(globalSloppyArrowEval, object, "(() => this)()")); | |
50 assertEquals(global, call(globalStrictArrowEval, object, "(() => this)()")); | |
51 | |
52 assertEquals(object, call(sloppyFunctionArrow, object)); | |
53 assertEquals(global, call(sloppyFunctionArrow, undefined)); | |
54 assertEquals(object, call(strictFunctionArrow, object)); | |
55 assertEquals(undefined, call(strictFunctionArrow, undefined)); | |
56 | |
57 assertEquals(object, call(sloppyFunctionEvalArrow, object)); | |
58 assertEquals(global, call(sloppyFunctionEvalArrow, undefined)); | |
59 assertEquals(object, call(strictFunctionEvalArrow, object)); | |
60 assertEquals(undefined, call(strictFunctionEvalArrow, undefined)); | |
61 | |
62 assertEquals(object, call(sloppyFunctionArrowEval, object, "this")); | |
63 assertEquals(global, call(sloppyFunctionArrowEval, undefined, "this")); | |
64 assertEquals(object, call(strictFunctionArrowEval, object, "this")); | |
65 assertEquals(undefined, call(strictFunctionArrowEval, undefined, "this")); | |
66 | |
67 assertEquals(object, | |
68 call(sloppyFunctionArrowEval, object, "(() => this)()")); | |
69 assertEquals(global, | |
70 call(sloppyFunctionArrowEval, undefined, "(() => this)()")); | |
71 assertEquals(object, | |
72 call(strictFunctionArrowEval, object, "(() => this)()")); | |
73 assertEquals(undefined, | |
74 call(strictFunctionArrowEval, undefined, "(() => this)()")); | |
75 | |
76 assertEquals(global, call(arrowInsideWith, undefined)); | |
77 assertEquals(global, call(arrowInsideWith, object)); | |
78 assertEquals(global, call(arrowInsideWithEval, undefined, "this")); | |
79 assertEquals(global, call(arrowInsideWithEval, object, "this")); | |
80 assertEquals(global, call(arrowInsideWithEval, undefined, "(() => this)()")); | |
81 assertEquals(global, call(arrowInsideWithEval, object, "(() => this)()")); | |
OLD | NEW |