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

Unified Diff: test/mjsunit/harmony/class-privates-visibility.js

Issue 2329703002: Private fields
Patch Set: some comments Created 4 years, 3 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/harmony/class-privates-scoping.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/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');
+ }
+}
« no previous file with comments | « test/mjsunit/harmony/class-privates-scoping.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698