summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/fields/ergonomic-1.js
blob: 7aa75ab30b378bce9ce1bce7f3486e99785fd71f (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
class Base {
  constructor(o) {
    return o;
  }
}

class A extends Base {
  #x = 12;
  #y = 13;
  static has(o) {
    return A.evalStr(o, '#x in o');
  }

  static evalStr(o, str) {
    return eval(str);
  }
}

var obj = {};
assertEq(A.has(obj), false);
new A(obj);
assertEq(A.has(obj), true);

A.evalStr(obj, `#x in o in o`)  // 'false' in o

function assertSyntaxError(functionText) {
  let threw = false;
  let exception = undefined;
  try {
    A.evalStr({}, functionText)
  } catch (e) {
    exception = e;
    threw = true;
  }
  assertEq(threw, true);
  assertEq(exception instanceof SyntaxError, true);
}

assertSyntaxError(`#x`);
assertSyntaxError(`#x == undefined`);
assertSyntaxError(`1 + #x in o`)
assertSyntaxError(`#z in o`);

assertSyntaxError(`for (#x in o) { return 1;}`)
assertSyntaxError(`!#x in o`)
assertSyntaxError(`+#x in o`)
assertSyntaxError(`-#x in o`)
assertSyntaxError(`~#x in o`)
assertSyntaxError(`void #x in o`)
assertSyntaxError(`typeof #x in o`)
assertSyntaxError(`++#x in o`)
assertSyntaxError(`--#x in o`)

assertSyntaxError(`#x in #y in o`)
assertSyntaxError(`{} instanceof #x in o`)
assertSyntaxError(`10 > #x in o`)
var threw = true
try {
  eval(`class Async {
    #x;
    async func(o) {
      await #x in o;
    }
  }`);
  threw = false;
} catch (e) {
  assertEq(e instanceof SyntaxError, true);
}
assertEq(threw, true);