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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « test/mjsunit/harmony/class-privates-scoping.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 2016 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-class-fields --harmony-private-class-fields
6
7 {
8 class Base {
9 #prop = 0;
10 static m = o => o.#prop;
11 }
12
13 class Derived extends Base {
14 #prop = 1;
15 static m = o => o.#prop;
16 }
17
18 let c = new Derived;
19 assertEquals(0, Base.m(c));
20 assertEquals(1, Derived.m(c));
21 }
22
23 {
24 class C {
25 constructor() {
26 assertEquals(0, #a);
27 assertEquals(undefined, #b);
28 }
29
30 #a = 0;
31 #b;
32 }
33
34 new C;
35 }
36
37 {
38 let effects = [];
39 let C = class {};
40
41 for (let i = 0; i < 10; ++i) {
42 C = class extends C {
43 #prop = i;
44 m() {
45 if (super.m) super.m();
46 effects.push(#prop);
47 }
48 }
49 }
50
51 let c = new C;
52 c.m();
53 assertArrayEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], effects);
54 }
55
56 {
57 let getter;
58
59 class C {
60 static _ = getter = o => o.#a;
61 #a = 0;
62 }
63
64 let c = new C;
65 assertEquals(0, getter(c));
66 }
67
68 {
69 assertThrows(() => class {
70 #prop;
71 static _ = #prop;
72 }, TypeError);
73
74 assertThrows(() => class {
75 static _ = #prop;
76 #prop;
77 }, TypeError);
78 }
79
80 {
81 assertThrows(() => new class {
82 _ = #prop;
83 }, ReferenceError);
84
85 try {
86 new class {
87 _ = #prop;
88 }
89 assertUnreachable();
90 } catch(e) {
91 assertEquals(e.message, '#prop is not defined');
92 }
93 }
OLDNEW
« 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