Debian Codegraph @

js/src/jit-test/tests/debug/Object-getOwnPrivateProperties.js

raw
1 // private fields
2
3 var g = newGlobal({ newCompartment: true });
4 var dbg = Debugger();
5 var gobj = dbg.addDebuggee(g);
6
7 g.eval(`
8 class MyClass {
9 constructor() {
10 this.publicProperty = 1;
11 this.publicSymbol = Symbol("public");
12 this[this.publicSymbol] = 2;
13 this.#privateProperty1 = 3;
14 this.#privateProperty2 = 4;
15 }
16 static #privateStatic1
17 static #privateStatic2
18 #privateProperty1
19 #privateProperty2
20 #privateMethod() {}
21 publicMethod(){}
22 }
23 obj = new MyClass();
24 klass = MyClass`);
25
26 var privatePropertiesSymbolsDescriptions = gobj
27 .getOwnPropertyDescriptor("obj")
28 .value.getOwnPrivateProperties()
29 .map(sym => sym.description);
30
31 assertEq(
32 JSON.stringify(privatePropertiesSymbolsDescriptions),
33 JSON.stringify([`#privateProperty1`, `#privateProperty2`])
34 );
35
36 var classPrivatePropertiesSymbolsDescriptions = gobj
37 .getOwnPropertyDescriptor("klass")
38 .value.getOwnPrivateProperties()
39 .map(sym => sym.description);
40
41 assertEq(
42 JSON.stringify(classPrivatePropertiesSymbolsDescriptions),
43 JSON.stringify([`#privateStatic1`, `#privateStatic2`])
44 );