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

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 TODO to fix fat-fingered "this" scoping in script context Created 5 years, 7 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/parser.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;
arv (Not doing code reviews) 2015/05/05 14:59:10 no aligning of = whitespace around => var global
wingo 2015/05/05 15:49:29 Done.
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";
arv (Not doing code reviews) 2015/05/05 14:59:10 indent blocks two spaces whitespace between ) and
wingo 2015/05/05 15:49:29 Done.
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)()"));
OLDNEW
« src/parser.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