Debian Codegraph @

js/src/tests/non262/PrivateName/illegal-delete.js

raw
1 // |reftest| skip-if(!xulRuntime.shell) -- needs newGlobal()
2
3 class A {
4 #x = {a: 1};
5 b = null;
6 es(s) {
7 eval(s);
8 }
9 }
10
11 var a = new A;
12 a.b = new A;
13
14 assertThrowsInstanceOf(() => a.es('delete this.#x'), SyntaxError);
15 assertThrowsInstanceOf(() => a.es('delete (this.#x)'), SyntaxError);
16 assertThrowsInstanceOf(() => a.es('delete this?.#x'), SyntaxError);
17 assertThrowsInstanceOf(() => a.es('delete this?.b.#x'), SyntaxError);
18 // Should be OK
19 a.es('delete (0, this.#x.a)')
20 a.es('delete this?.b.#x.a')
21
22
23 // Make sure the above works in a different context, with emphasis on
24 // lazy/syntax parsing.
25 function eval_and_report(str) {
26 var classTest = `
27 class B {
28 #x = {a: 1};
29 b = null;
30 test() {
31 ${str};
32 }
33 }
34 var b = new B;
35 b.b = new B;
36 b.test();
37 `;
38
39 var str = `
40 function f(run) {
41 if (run) {
42 ${classTest}
43 }
44 }
45 f(run)`;
46
47
48 var throws = [];
49 // Evalutate in a new global; has the advantage that it makes successes
50 // idempotent.
51 var g = newGlobal();
52 g.run = false;
53
54 try {
55 // The idea is that this is a full parse
56 evaluate(classTest, {global: g});
57 } catch (e) {
58 throws.push(e);
59 }
60
61 try {
62 // The idea is this is a lazy parse; however, fields currently
63 // disable lazy parsing, so right now
64 evaluate(str, {global: g});
65 } catch (e) {
66 throws.push(e);
67 }
68
69 return throws;
70 }
71
72 function assertSyntaxError(str) {
73 var exceptions = eval_and_report(str);
74 assertEq(exceptions.length, 2);
75 for (var e of exceptions) {
76 assertEq(/SyntaxError/.test(e.name), true);
77 }
78 }
79
80 function assertNoSyntaxError(str) {
81 var exceptions = eval_and_report(str);
82 assertEq(exceptions.length, 0);
83 }
84
85 assertSyntaxError('delete this.#x');
86 assertSyntaxError('delete (this.#x)');
87 assertSyntaxError('delete this?.#x');
88 assertSyntaxError('delete this?.b.#x');
89 // Should be OK
90 assertNoSyntaxError('delete (0, this.#x.a)')
91 assertNoSyntaxError('delete this?.b.#x.a')
92
93
94 if (typeof reportCompare === 'function') reportCompare(0, 0);