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

Unified Diff: test/mjsunit/harmony/arrow-functions-scoping.js

Issue 883823002: Implement proper scoping for "this" in arrow functions Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased against master, plus fixes. Only 4 tests failing (+2 in TurboFan) Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/debug-scopes.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/arrow-functions-scoping.js
diff --git a/test/mjsunit/harmony/arrow-functions-scoping.js b/test/mjsunit/harmony/arrow-functions-scoping.js
new file mode 100644
index 0000000000000000000000000000000000000000..c2433552896d63ec3ca41f3b0313ca6fd5fbf7f7
--- /dev/null
+++ b/test/mjsunit/harmony/arrow-functions-scoping.js
@@ -0,0 +1,36 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-arrow-functions
+
+// The following are tests from:
+// http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax
+var obj = {
+ method: function () {
+ return () => this;
+ }
+};
+assertSame(obj, obj.method()());
+
+var fake = { steal: obj.method() };
+assertSame(obj, fake.steal());
+
+var real = { borrow: obj.method };
+assertSame(real, real.borrow()());
+
+// Same, but using eval() for the arrow function.
+obj = {
+ method: function () {
+ return eval("() => this");
+ }
+};
+assertSame(obj, obj.method()());
+
+// Using eval() to define the whole object.
+eval('obj = { method: function () { return () => this } }');
+assertSame(obj, obj.method()());
+
+// Nested eval().
+eval('obj = { method: function () { return eval("() => this") } }');
+assertSame(obj, obj.method()());
« no previous file with comments | « test/mjsunit/debug-scopes.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698