summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/PrivateName/illegal-delete.js
blob: 464b7dd68574c2e66c21d548bc2a8088c2c888fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// |reftest| skip-if(!xulRuntime.shell) -- needs newGlobal()

class A {
  #x = {a: 1};
  b = null;
  es(s) {
    eval(s);
  }
}

var a = new A;
a.b = new A;

assertThrowsInstanceOf(() => a.es('delete this.#x'), SyntaxError);
assertThrowsInstanceOf(() => a.es('delete (this.#x)'), SyntaxError);
assertThrowsInstanceOf(() => a.es('delete this?.#x'), SyntaxError);
assertThrowsInstanceOf(() => a.es('delete this?.b.#x'), SyntaxError);
// Should be OK
a.es('delete (0, this.#x.a)')
a.es('delete this?.b.#x.a')


// Make sure the above works in a different context, with emphasis on
// lazy/syntax parsing.
function eval_and_report(str) {
  var classTest = `
  class B {
    #x = {a: 1};
    b = null;
    test() {
      ${str};
    }
  }
  var b = new B;
  b.b = new B;
  b.test();
 `;

  var str = `
  function f(run) {
    if (run) {
      ${classTest}
    }
  }
  f(run)`;


  var throws = [];
  // Evalutate in a new global; has the advantage that it makes successes
  // idempotent.
  var g = newGlobal();
  g.run = false;

  try {
    // The idea is that this is a full parse
    evaluate(classTest, {global: g});
  } catch (e) {
    throws.push(e);
  }

  try {
    // The idea is this is a lazy parse; however, fields currently
    // disable lazy parsing, so right now
    evaluate(str, {global: g});
  } catch (e) {
    throws.push(e);
  }

  return throws;
}

function assertSyntaxError(str) {
  var exceptions = eval_and_report(str);
  assertEq(exceptions.length, 2);
  for (var e of exceptions) {
    assertEq(/SyntaxError/.test(e.name), true);
  }
}

function assertNoSyntaxError(str) {
  var exceptions = eval_and_report(str);
  assertEq(exceptions.length, 0);
}

assertSyntaxError('delete this.#x');
assertSyntaxError('delete (this.#x)');
assertSyntaxError('delete this?.#x');
assertSyntaxError('delete this?.b.#x');
// Should be OK
assertNoSyntaxError('delete (0, this.#x.a)')
assertNoSyntaxError('delete this?.b.#x.a')


if (typeof reportCompare === 'function') reportCompare(0, 0);