blob: dea105f296c925d0d1cc9c133fb3759652f03ae3 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
5var object = {};
6var global = this;
7var call = Function.call.bind(Function.call);
8
9var globalSloppyArrow = () => this;
10var globalStrictArrow = () => { "use strict"; return this; };
11var globalSloppyArrowEval = (s) => eval(s);
12var globalStrictArrowEval = (s) => { "use strict"; return eval(s); };
13
14var sloppyFunctionArrow = function() {
15 return (() => this)();
16};
17var strictFunctionArrow = function() {
18 "use strict";
19 return (() => this)();
20};
21var sloppyFunctionEvalArrow = function() {
22 return eval("(() => this)()");
23};
24var strictFunctionEvalArrow = function() {
25 "use strict";
26 return eval("(() => this)()");
27};
28var sloppyFunctionArrowEval = function(s) {
29 return (() => eval(s))();
30};
31var strictFunctionArrowEval = function(s) {
32 "use strict";
33 return (() => eval(s))();
34};
35
36var withObject = { 'this': object }
37var arrowInsideWith, arrowInsideWithEval;
38with (withObject) {
39 arrowInsideWith = () => this;
40 arrowInsideWithEval = (s) => eval(s);
41}
42
43assertEquals(global, call(globalSloppyArrow, object));
44assertEquals(global, call(globalStrictArrow, object));
45assertEquals(global, call(globalSloppyArrowEval, object, "this"));
46assertEquals(global, call(globalStrictArrowEval, object, "this"));
47assertEquals(global, call(globalSloppyArrowEval, object, "(() => this)()"));
48assertEquals(global, call(globalStrictArrowEval, object, "(() => this)()"));
49
50assertEquals(object, call(sloppyFunctionArrow, object));
51assertEquals(global, call(sloppyFunctionArrow, undefined));
52assertEquals(object, call(strictFunctionArrow, object));
53assertEquals(undefined, call(strictFunctionArrow, undefined));
54
55assertEquals(object, call(sloppyFunctionEvalArrow, object));
56assertEquals(global, call(sloppyFunctionEvalArrow, undefined));
57assertEquals(object, call(strictFunctionEvalArrow, object));
58assertEquals(undefined, call(strictFunctionEvalArrow, undefined));
59
60assertEquals(object, call(sloppyFunctionArrowEval, object, "this"));
61assertEquals(global, call(sloppyFunctionArrowEval, undefined, "this"));
62assertEquals(object, call(strictFunctionArrowEval, object, "this"));
63assertEquals(undefined, call(strictFunctionArrowEval, undefined, "this"));
64
65assertEquals(object,
66 call(sloppyFunctionArrowEval, object, "(() => this)()"));
67assertEquals(global,
68 call(sloppyFunctionArrowEval, undefined, "(() => this)()"));
69assertEquals(object,
70 call(strictFunctionArrowEval, object, "(() => this)()"));
71assertEquals(undefined,
72 call(strictFunctionArrowEval, undefined, "(() => this)()"));
73
74assertEquals(global, call(arrowInsideWith, undefined));
75assertEquals(global, call(arrowInsideWith, object));
76assertEquals(global, call(arrowInsideWithEval, undefined, "this"));
77assertEquals(global, call(arrowInsideWithEval, object, "this"));
78assertEquals(global, call(arrowInsideWithEval, undefined, "(() => this)()"));
79assertEquals(global, call(arrowInsideWithEval, object, "(() => this)()"));