Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/mjsunit/harmony/arrow-functions-this.js

Issue 1097283003: Resolve references to "this" the same way as normal variables (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Add tests for "this" scoping in arrow functions Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/x64/full-codegen-x64.cc ('K') | « test/mjsunit/debug-scopes.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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)()"));
OLDNEW
« src/x64/full-codegen-x64.cc ('K') | « test/mjsunit/debug-scopes.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698