Index: test/mjsunit/harmony/class-privates-visibility.js |
diff --git a/test/mjsunit/harmony/class-privates-visibility.js b/test/mjsunit/harmony/class-privates-visibility.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f75fb03b1c47418ac731e55e1de743e445fef99a |
--- /dev/null |
+++ b/test/mjsunit/harmony/class-privates-visibility.js |
@@ -0,0 +1,93 @@ |
+// 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-class-fields --harmony-private-class-fields |
+ |
+{ |
+ class Base { |
+ #prop = 0; |
+ static m = o => o.#prop; |
+ } |
+ |
+ class Derived extends Base { |
+ #prop = 1; |
+ static m = o => o.#prop; |
+ } |
+ |
+ let c = new Derived; |
+ assertEquals(0, Base.m(c)); |
+ assertEquals(1, Derived.m(c)); |
+} |
+ |
+{ |
+ class C { |
+ constructor() { |
+ assertEquals(0, #a); |
+ assertEquals(undefined, #b); |
+ } |
+ |
+ #a = 0; |
+ #b; |
+ } |
+ |
+ new C; |
+} |
+ |
+{ |
+ let effects = []; |
+ let C = class {}; |
+ |
+ for (let i = 0; i < 10; ++i) { |
+ C = class extends C { |
+ #prop = i; |
+ m() { |
+ if (super.m) super.m(); |
+ effects.push(#prop); |
+ } |
+ } |
+ } |
+ |
+ let c = new C; |
+ c.m(); |
+ assertArrayEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], effects); |
+} |
+ |
+{ |
+ let getter; |
+ |
+ class C { |
+ static _ = getter = o => o.#a; |
+ #a = 0; |
+ } |
+ |
+ let c = new C; |
+ assertEquals(0, getter(c)); |
+} |
+ |
+{ |
+ assertThrows(() => class { |
+ #prop; |
+ static _ = #prop; |
+ }, TypeError); |
+ |
+ assertThrows(() => class { |
+ static _ = #prop; |
+ #prop; |
+ }, TypeError); |
+} |
+ |
+{ |
+ assertThrows(() => new class { |
+ _ = #prop; |
+ }, ReferenceError); |
+ |
+ try { |
+ new class { |
+ _ = #prop; |
+ } |
+ assertUnreachable(); |
+ } catch(e) { |
+ assertEquals(e.message, '#prop is not defined'); |
+ } |
+} |