summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/expressions/exponentiation-unparenthesised-unary.js
blob: a673521264aa80d82affbe6196ba892b85214798 (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
95
96
97
98
99
100
101
102
103
104
105
106
const AsyncFunction = async function(){}.constructor;

function assertNoError(f, msg) {
  try {
    f();
  } catch (e) {
    assertEq(true, false, `${msg}: ${e}`);
  }
}

function assertSyntaxError(code) {
  assertThrowsInstanceOf(function () { Function(code); }, SyntaxError, "Function:" + code);
  assertThrowsInstanceOf(function () { AsyncFunction(code); }, SyntaxError, "AsyncFunction:" + code);
}

function assertNoSyntaxError(code) {
  assertNoError(function () { Function(code); }, "Function:" + code);
  assertNoError(function () { AsyncFunction(code); }, "AsyncFunction:" + code);
}

function assertNoSyntaxErrorAsyncContext(code) {
  assertNoError(function () { AsyncFunction(code); }, "AsyncFunction:" + code);
}

const invalidTestCases = [
  // UnaryExpression : delete UnaryExpression
  //
  // Test all possible `delete` expression kinds.
  "delete a ** 0",
  "delete a.prop ** 0",
  "delete a[0] ** 0",
  "delete a?.prop ** 0",
  "delete 0 ** 0",

  // UnaryExpression : void UnaryExpression
  "void a ** 0",

  // UnaryExpression : typeof UnaryExpression
  //
  // Test all possible `typeof` expression kinds.
  "typeof a ** 0",
  "typeof 0 ** 0",

  // UnaryExpression : + UnaryExpression
  "+a ** 0",

  // UnaryExpression : - UnaryExpression
  "-a ** 0",

  // UnaryExpression : ~ UnaryExpression
  "~a ** 0",

  // UnaryExpression : ! UnaryExpression
  "!a ** 0",

  // UnaryExpression : AwaitExpression
  "await a ** 0",
];

for (let source of invalidTestCases) {
  assertSyntaxError(source);
}

const validTestCases = [
  // UnaryExpression : delete UnaryExpression
  "(delete a) ** 0",
  "(delete a.prop) ** 0",
  "(delete a[0]) ** 0",
  "(delete a?.prop) ** 0",
  "(delete 0) ** 0",

  // UnaryExpression : void UnaryExpression
  "(void a) ** 0",

  // UnaryExpression : typeof UnaryExpression
  "(typeof a) ** 0",
  "(typeof 0) ** 0",

  // UnaryExpression : + UnaryExpression
  "(+a) ** 0",

  // UnaryExpression : - UnaryExpression
  "(-a) ** 0",

  // UnaryExpression : ~ UnaryExpression
  "(~a) ** 0",

  // UnaryExpression : ! UnaryExpression
  "(!a) ** 0",
];

for (let source of validTestCases) {
  assertNoSyntaxError(source);
}

const validTestCasesAsync = [
  // UnaryExpression : AwaitExpression
  "(await a) ** 0",
];

for (let source of validTestCasesAsync) {
  assertNoSyntaxErrorAsyncContext(source);
}

if (typeof reportCompare === "function")
  reportCompare(true, true);