Index: test/mjsunit/harmony/class-privates-scoping.js |
diff --git a/test/mjsunit/harmony/class-privates-scoping.js b/test/mjsunit/harmony/class-privates-scoping.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..54d3ffe556397384765600ccabe525ad926dba1e |
--- /dev/null |
+++ b/test/mjsunit/harmony/class-privates-scoping.js |
@@ -0,0 +1,114 @@ |
+// Copyright 2016 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-private-class-fields |
+ |
+// this |
+{ |
+ class C { |
+ #a = this; |
+ a() { return #a; } |
+ } |
+ |
+ let c = new C; |
+ assertEquals(c, c.a()); |
+} |
+ |
+// super |
+{ |
+ class Base { |
+ m() { |
+ return 0; |
+ } |
+ } |
+ |
+ class Derived extends Base { |
+ m() { |
+ return 1; |
+ } |
+ #a = super.m(); |
+ a() { return #a; } |
+ } |
+ |
+ let c = new Derived; |
+ assertEquals(0, c.a()); |
+} |
+ |
+// new.target |
+{ |
+ function outer() { |
+ class C { |
+ #a = new.target; |
+ a() { return #a; } |
+ } |
+ |
+ let c = new C; |
+ assertEquals(undefined, c.a()); |
+ } |
+ |
+ new outer; |
+} |
+ |
+// arguments |
+{ |
+ function outer() { |
+ let stored_outer = arguments; |
+ let stored_ctor; |
+ |
+ class C { |
+ #a = arguments; |
+ a() { return #a; } |
+ |
+ constructor() { |
+ stored_ctor = arguments; |
+ } |
+ } |
+ |
+ let c = new C; |
+ assertEquals('[object Arguments]', Object.prototype.toString.call(c.a())); |
+ assertFalse(stored_outer === c.a()); |
+ assertFalse(stored_ctor === c.a()); |
+ } |
+ |
+ outer(); |
+} |
+ |
+// ctor params |
+{ |
+ let b = 0; |
+ class C { |
+ #a = b; |
+ a() { return #a; } |
+ |
+ constructor(b) {} |
+ } |
+ |
+ let c = new C(1); |
+ assertEquals(0, c.a()); |
+} |
+ |
+// class declaration name |
+{ |
+ class C { |
+ #a = C; |
+ a() { return #a; } |
+ } |
+ let stored_class = C; |
+ C = null; |
+ |
+ let c = new stored_class; |
+ assertEquals(stored_class, c.a()); |
+} |
+ |
+// class expression name |
+{ |
+ let C = null; |
+ let stored_class = class C { |
+ #a = C; |
+ a() { return #a; } |
+ } |
+ |
+ let c = new stored_class; |
+ assertEquals(stored_class, c.a()); |
+} |