FranklinDM 1 month ago committed by roytam1
parent
commit
f0e208a861
  1. 35
      js/src/tests/js1_8_5/reflect-parse/expression.js
  2. 112
      js/src/tests/non262/expressions/nullish-coalescing.js
  3. 60
      js/src/tests/test262/language/expressions/coalesce/abrupt-is-a-short-circuit.js
  4. 0
      js/src/tests/test262/language/expressions/coalesce/browser.js
  5. 30
      js/src/tests/test262/language/expressions/coalesce/cannot-chain-head-with-logical-and.js
  6. 30
      js/src/tests/test262/language/expressions/coalesce/cannot-chain-head-with-logical-or.js
  7. 31
      js/src/tests/test262/language/expressions/coalesce/cannot-chain-tail-with-logical-and.js
  8. 31
      js/src/tests/test262/language/expressions/coalesce/cannot-chain-tail-with-logical-or.js
  9. 55
      js/src/tests/test262/language/expressions/coalesce/chainable-if-parenthesis-covered-logical-and.js
  10. 63
      js/src/tests/test262/language/expressions/coalesce/chainable-if-parenthesis-covered-logical-or.js
  11. 51
      js/src/tests/test262/language/expressions/coalesce/chainable-with-bitwise-and.js
  12. 51
      js/src/tests/test262/language/expressions/coalesce/chainable-with-bitwise-or.js
  13. 51
      js/src/tests/test262/language/expressions/coalesce/chainable-with-bitwise-xor.js
  14. 52
      js/src/tests/test262/language/expressions/coalesce/chainable.js
  15. 51
      js/src/tests/test262/language/expressions/coalesce/follows-null.js
  16. 51
      js/src/tests/test262/language/expressions/coalesce/follows-undefined.js
  17. 0
      js/src/tests/test262/language/expressions/coalesce/shell.js
  18. 83
      js/src/tests/test262/language/expressions/coalesce/short-circuit-number-0.js
  19. 83
      js/src/tests/test262/language/expressions/coalesce/short-circuit-number-42.js
  20. 84
      js/src/tests/test262/language/expressions/coalesce/short-circuit-number-empty-string.js
  21. 83
      js/src/tests/test262/language/expressions/coalesce/short-circuit-number-false.js
  22. 91
      js/src/tests/test262/language/expressions/coalesce/short-circuit-number-object.js
  23. 84
      js/src/tests/test262/language/expressions/coalesce/short-circuit-number-string.js
  24. 84
      js/src/tests/test262/language/expressions/coalesce/short-circuit-number-symbol.js
  25. 83
      js/src/tests/test262/language/expressions/coalesce/short-circuit-number-true.js
  26. 58
      js/src/tests/test262/language/expressions/coalesce/short-circuit-prevents-evaluation.js
  27. 30
      js/src/tests/test262/language/expressions/coalesce/tco-pos-null-strict.js
  28. 30
      js/src/tests/test262/language/expressions/coalesce/tco-pos-undefined-strict.js
  29. 0
      js/src/tests/test262/language/expressions/conditional/browser.js
  30. 75
      js/src/tests/test262/language/expressions/conditional/coalesce-expr-ternary.js
  31. 0
      js/src/tests/test262/language/expressions/conditional/shell.js

35
js/src/tests/js1_8_5/reflect-parse/expression.js

@ -15,6 +15,31 @@ assertExpr("foo[bar]", memExpr(ident("foo"), ident("bar")));
assertExpr("foo['bar']", memExpr(ident("foo"), lit("bar")));
assertExpr("foo[42]", memExpr(ident("foo"), lit(42)));
// optional member expressions
assertExpr("foo?.bar", optExpr(optDotExpr(ident("foo"), ident("bar"))));
assertExpr("foo?.bar.baz", optExpr(dotExpr(optDotExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("foo.bar?.baz", optExpr(optDotExpr(dotExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("foo?.bar?.baz", optExpr(optDotExpr(optDotExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("foo?.[bar].baz", optExpr(dotExpr(optMemExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("foo.bar?.[baz]", optExpr(optMemExpr(dotExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("foo[bar]?.[baz]", optExpr(optMemExpr(memExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("foo?.[bar][baz]", optExpr(memExpr(optMemExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("foo?.['bar']?.['baz']", optExpr(optMemExpr(optMemExpr(ident("foo"), lit("bar")), lit("baz"))));
assertExpr("foo?.[bar]?.baz", optExpr(optDotExpr(optMemExpr(ident("foo"), ident("bar")), ident("baz"))));
// delete optional expressions
assertExpr("\ndelete [] ?. [1]", delOptExpr(optMemExpr(arrExpr([]), lit(1))));
assertExpr("delete foo?.bar", delOptExpr(optDotExpr(ident("foo"), ident("bar"))));
assertExpr("delete foo?.bar.baz", delOptExpr(dotExpr(optDotExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("delete foo.bar?.baz", delOptExpr(optDotExpr(dotExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("delete foo?.bar?.baz", delOptExpr(optDotExpr(optDotExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("delete foo?.[bar].baz", delOptExpr(dotExpr(optMemExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("delete foo.bar?.[baz]", delOptExpr(optMemExpr(dotExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("delete foo[bar]?.[baz]", delOptExpr(optMemExpr(memExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("delete foo?.[bar][baz]", delOptExpr(memExpr(optMemExpr(ident("foo"), ident("bar")), ident("baz"))));
assertExpr("delete foo?.['bar']?.['baz']", delOptExpr(optMemExpr(optMemExpr(ident("foo"), lit("bar")), lit("baz"))));
assertExpr("delete foo?.[bar]?.baz", delOptExpr(optDotExpr(optMemExpr(ident("foo"), ident("bar")), ident("baz"))));
// function expressions
assertExpr("(function(){})", funExpr(null, [], blockStmt([])));
assertExpr("(function f() {})", funExpr(ident("f"), [], blockStmt([])));
@ -86,6 +111,7 @@ assertExpr("(x &= y)", aExpr("&=", ident("x"), ident("y")));
// Conditional expressions
assertExpr("(x || y)", logExpr("||", ident("x"), ident("y")));
assertExpr("(x && y)", logExpr("&&", ident("x"), ident("y")));
assertExpr("(x ?? y)", logExpr("??", ident("x"), ident("y")));
assertExpr("(w || x || y || z)", logExpr("||", logExpr("||", logExpr("||", ident("w"), ident("x")), ident("y")), ident("z")))
assertExpr("(x ? y : z)", condExpr(ident("x"), ident("y"), ident("z")));
@ -103,6 +129,15 @@ assertExpr("(String())", callExpr(ident("String"), []));
assertExpr("(String(42))", callExpr(ident("String"), [lit(42)]));
assertExpr("(String(1,2,3))", callExpr(ident("String"), [lit(1),lit(2),lit(3)]));
// Optional Call expressions
assertExpr("(String?.())", optExpr(optCallExpr(ident("String"), [])));
assertExpr("(String?.(42))", optExpr(optCallExpr(ident("String"), [lit(42)])));
assertExpr("(String?.(1,2,3))", optExpr(optCallExpr(ident("String"), [lit(1),lit(2),lit(3)])));
assertExpr("(String?.foo?.())", optExpr(optCallExpr(optDotExpr(ident("String"), ident("foo")), [])));
assertExpr("(String.foo?.())", optExpr(optCallExpr(dotExpr(ident("String"), ident("foo")), [])));
assertExpr("(String?.foo)()", callExpr(optExpr(optDotExpr(ident("String"), ident("foo"))), []));
assertExpr("(String?.foo)?.()", optExpr(optCallExpr(optExpr(optDotExpr(ident("String"), ident("foo"))), [])));
// Array expressions
assertExpr("[]", arrExpr([]));
assertExpr("[1]", arrExpr([lit(1)]));

112
js/src/tests/non262/expressions/nullish-coalescing.js

@ -0,0 +1,112 @@
var BUGNUMBER = 1566141;
var summary = "Implement the Nullish Coalescing operator (??) proposal";
print(BUGNUMBER + ": " + summary);
// These tests are originally from webkit.
// webkit specifics have been removed and a test for `document.all` has
// been added.
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`expected ${expected} but got ${actual}`);
}
function shouldNotThrow(script) {
eval(script);
}
function shouldThrowSyntaxError(script) {
let error;
try {
eval(script);
} catch (e) {
error = e;
}
if (!(error instanceof SyntaxError))
throw new Error('Expected SyntaxError!');
}
function testBasicCases() {
shouldBe(undefined ?? 3, 3);
shouldBe(null ?? 3, 3);
shouldBe(true ?? 3, true);
shouldBe(false ?? 3, false);
shouldBe(0 ?? 3, 0);
shouldBe(1 ?? 3, 1);
shouldBe('' ?? 3, '');
shouldBe('hi' ?? 3, 'hi');
shouldBe(({} ?? 3) instanceof Object, true);
shouldBe(({ x: 'hi' } ?? 3).x, 'hi');
shouldBe(([] ?? 3) instanceof Array, true);
shouldBe((['hi'] ?? 3)[0], 'hi');
// test document.all, which has odd behavior
//shouldBe(typeof(createIsHTMLDDA() ?? 3), "undefined");
}
for (let i = 0; i < 1e5; i++)
testBasicCases();
shouldBe(1 | null ?? 3, 1);
shouldBe(1 ^ null ?? 3, 1);
shouldBe(1 & null ?? 3, 0);
shouldBe(3 == null ?? 3, false);
shouldBe(3 != null ?? 3, true);
shouldBe(3 === null ?? 3, false);
shouldBe(3 !== null ?? 3, true);
shouldBe(1 < null ?? 3, false);
shouldBe(1 > null ?? 3, true);
shouldBe(1 <= null ?? 3, false);
shouldBe(1 >= null ?? 3, true);
shouldBe(1 << null ?? 3, 1);
shouldBe(1 >> null ?? 3, 1);
shouldBe(1 >>> null ?? 3, 1);
shouldBe(1 + null ?? 3, 1);
shouldBe(1 - null ?? 3, 1);
shouldBe(1 * null ?? 3, 0);
shouldBe(1 / null ?? 3, Infinity);
shouldBe(isNaN(1 % null ?? 3), true);
shouldBe(1 ** null ?? 3, 1);
shouldBe((void 0) ?? 3, 3);
const obj = {
count: 0,
get x() { this.count++; return 'x'; }
};
false ?? obj.x;
shouldBe(obj.count, 0);
null ?? obj.x;
shouldBe(obj.count, 1);
obj.x ?? obj.x;
shouldBe(obj.count, 2);
shouldThrowSyntaxError('0 || 1 ?? 2');
shouldThrowSyntaxError('0 && 1 ?? 2');
shouldThrowSyntaxError('0 ?? 1 || 2');
shouldThrowSyntaxError('0 ?? 1 && 2');
shouldNotThrow('(0 || 1) ?? 2');
shouldNotThrow('0 || (1 ?? 2)');
shouldNotThrow('(0 && 1) ?? 2');
shouldNotThrow('0 && (1 ?? 2)');
shouldNotThrow('(0 ?? 1) || 2');
shouldNotThrow('0 ?? (1 || 2)');
shouldNotThrow('(0 ?? 1) && 2');
shouldNotThrow('0 ?? (1 && 2)');
shouldNotThrow('0 || 1 && 2 | 3 ^ 4 & 5 == 6 != 7 === 8 !== 9 < 0 > 1 <= 2 >= 3 << 4 >> 5 >>> 6 + 7 - 8 * 9 / 0 % 1 ** 2');
shouldThrowSyntaxError('0 || 1 && 2 | 3 ^ 4 & 5 == 6 != 7 === 8 !== 9 < 0 > 1 <= 2 >= 3 << 4 >> 5 >>> 6 + 7 - 8 * 9 / 0 % 1 ** 2 ?? 3');
shouldThrowSyntaxError('3 ?? 2 ** 1 % 0 / 9 * 8 - 7 + 6 >>> 5 >> 4 << 3 >= 2 <= 1 > 0 < 9 !== 8 === 7 != 6 == 5 & 4 ^ 3 | 2 && 1 || 0');
shouldBe(null?.x ?? 3, 3);
shouldBe(({})?.x ?? 3, 3);
shouldBe(({ x: 0 })?.x ?? 3, 0);
shouldBe(null?.() ?? 3, 3);
shouldBe((() => 0)?.() ?? 3, 0);
shouldBe(({ x: 0 })?.[null?.a ?? 'x'] ?? 3, 0);
shouldBe((() => 0)?.(null?.a ?? 'x') ?? 3, 0);
if (typeof reportCompare === "function")
reportCompare(true, true);
print("Tests complete");

60
js/src/tests/test262/language/expressions/coalesce/abrupt-is-a-short-circuit.js

@ -0,0 +1,60 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Abrupt completions are also a Short circuit and prevent evaluation of the right-side expressions
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
function poison() {
throw new Test262Error('poison handled');
}
function morePoison() {
throw 'poison!!!!';
}
x = undefined;
assert.throws(Test262Error, function() {
undefined ?? poison() ?? morePoison();
}, 'undefined ?? poison() ?? morePoison();');
x = undefined;
assert.throws(Test262Error, function() {
null ?? poison() ?? morePoison();
}, 'null ?? poison() ?? morePoison();');
assert.throws(Test262Error, function() {
poison() ?? morePoison();
}, 'poison() ?? morePoison();');
reportCompare(0, 0);

0
js/src/tests/test262/language/expressions/coalesce/browser.js

30
js/src/tests/test262/language/expressions/coalesce/cannot-chain-head-with-logical-and.js

@ -0,0 +1,30 @@
// |reftest| error:SyntaxError
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Cannot immediately contain, or be contained within, an && or || operation.
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
features: [coalesce-expression]
negative:
phase: early
type: SyntaxError
---*/
0 && 0 ?? true;

30
js/src/tests/test262/language/expressions/coalesce/cannot-chain-head-with-logical-or.js

@ -0,0 +1,30 @@
// |reftest| error:SyntaxError
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Cannot immediately contain, or be contained within, an && or || operation.
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
features: [coalesce-expression]
negative:
phase: early
type: SyntaxError
---*/
0 || 0 ?? true;

31
js/src/tests/test262/language/expressions/coalesce/cannot-chain-tail-with-logical-and.js

@ -0,0 +1,31 @@
// |reftest| error:SyntaxError
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
If the CoalesceExpressionHead is undefined or null, follow return the right-side value.
Otherwise, return the left-side value.
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
features: [coalesce-expression]
negative:
phase: early
type: SyntaxError
---*/
0 ?? 0 && true;

31
js/src/tests/test262/language/expressions/coalesce/cannot-chain-tail-with-logical-or.js

@ -0,0 +1,31 @@
// |reftest| error:SyntaxError
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
If the CoalesceExpressionHead is undefined or null, follow return the right-side value.
Otherwise, return the left-side value.
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
features: [coalesce-expression]
negative:
phase: early
type: SyntaxError
---*/
0 ?? 0 || true;

55
js/src/tests/test262/language/expressions/coalesce/chainable-if-parenthesis-covered-logical-and.js

@ -0,0 +1,55 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
CoalesceExpression is chainable with the LogicalANDExpression is any is covered.
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = undefined;
x = (null ?? 41) && 42;
assert.sameValue(x, 42, '(null ?? 41) && 42');
x = undefined;
x = null ?? (41 && 42);
assert.sameValue(x, 42, 'null ?? (41 && 42)`');
x = undefined;
x = (41 && 42) ?? null;
assert.sameValue(x, 42, '(41 && 42) ?? null');
x = undefined;
x = 41 && (null ?? 42);
assert.sameValue(x, 42, '41 && (null ?? 42)`');
reportCompare(0, 0);

63
js/src/tests/test262/language/expressions/coalesce/chainable-if-parenthesis-covered-logical-or.js

@ -0,0 +1,63 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
CoalesceExpression is chainable with the LogicalORExpression is any is covered.
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = undefined;
x = (null ?? 42) || 43;
assert.sameValue(x, 42, '(null ?? 42) || 43');
x = undefined;
x = null ?? (42 || 43);
assert.sameValue(x, 42, 'null ?? (42 || 43)`');
x = undefined;
x = (null || 42) ?? 43;
assert.sameValue(x, 42, '(null || 42) ?? 43');
x = undefined;
x = null || (42 ?? 43);
assert.sameValue(x, 42, 'null || (42 ?? 43)`');
x = undefined;
x = (42 || 43) ?? null;
assert.sameValue(x, 42, '(42 || 43) ?? null');
x = undefined;
x = 42 || (null ?? 43);
assert.sameValue(x, 42, '42 || (null ?? 43)');
reportCompare(0, 0);

51
js/src/tests/test262/language/expressions/coalesce/chainable-with-bitwise-and.js

@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
CoalesceExpression is chainable with the BitwiseANDExpression
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = null ?? 42 & 43;
assert.sameValue(x, 42, 'null ?? 42 & 43');
x = undefined ?? 42 & 43;
assert.sameValue(x, 42, 'null ?? 42 & 43');
x = false ?? 42 & 43;
assert.sameValue(x, false, 'false ?? 42 & 43');
x = true ?? 42 & 43;
assert.sameValue(x, true, 'true ?? 42 & 43');
reportCompare(0, 0);

51
js/src/tests/test262/language/expressions/coalesce/chainable-with-bitwise-or.js

@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
CoalesceExpression is chainable with the BitwiseORExpression
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = null ?? 1 | 42;
assert.sameValue(x, 43, 'null ?? 1 | 42');
x = undefined ?? 1 | 42;
assert.sameValue(x, 43, 'null ?? 1 | 42');
x = false ?? 1 | 42;
assert.sameValue(x, false, 'false ?? 1 | 42');
x = true ?? 1 | 42;
assert.sameValue(x, true, 'true ?? 1 | 42');
reportCompare(0, 0);

51
js/src/tests/test262/language/expressions/coalesce/chainable-with-bitwise-xor.js

@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
CoalesceExpression is chainable with the BitwiseXORExpression
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = null ?? 1 ^ 42;
assert.sameValue(x, 43, 'null ?? 1 ^ 42');
x = undefined ?? 1 ^ 42;
assert.sameValue(x, 43, 'null ?? 1 ^ 42');
x = false ?? 1 ^ 42;
assert.sameValue(x, false, 'false ?? 1 ^ 42');
x = true ?? 1 ^ 42;
assert.sameValue(x, true, 'true ?? 1 ^ 42');
reportCompare(0, 0);

52
js/src/tests/test262/language/expressions/coalesce/chainable.js

@ -0,0 +1,52 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
If the CoalesceExpressionHead is undefined or null, follow return the right-side value.
Otherwise, return the left-side value.
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = null ?? undefined ?? 42;
assert.sameValue(x, 42, 'null ?? undefined ?? 42');
x = undefined ?? null ?? 42;
assert.sameValue(x, 42, 'undefined ?? null ?? 42');
x = null ?? null ?? 42;
assert.sameValue(x, 42, 'null ?? null ?? 42');
x = undefined ?? undefined ?? 42;
assert.sameValue(x, 42, 'null ?? null ?? 42');
reportCompare(0, 0);

51
js/src/tests/test262/language/expressions/coalesce/follows-null.js

@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
If the CoalesceExpressionHead is null, follow return the right-side eval.
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = null ?? 42;
assert.sameValue(x, 42, 'null ?? 42');
x = null ?? undefined;
assert.sameValue(x, undefined, 'null ?? undefined');
x = null ?? null;
assert.sameValue(x, null, 'null ?? null');
x = null ?? false;
assert.sameValue(x, false, 'null ?? false');
reportCompare(0, 0);

51
js/src/tests/test262/language/expressions/coalesce/follows-undefined.js

@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
If the CoalesceExpressionHead is undefined, follow return the right-side eval.
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = undefined ?? 42;
assert.sameValue(x, 42, 'undefined ?? 42');
x = undefined ?? undefined;
assert.sameValue(x, undefined, 'undefined ?? undefined');
x = undefined ?? null;
assert.sameValue(x, null, 'undefined ?? null');
x = undefined ?? false;
assert.sameValue(x, false, 'undefined ?? false');
reportCompare(0, 0);

0
js/src/tests/test262/language/expressions/coalesce/shell.js

83
js/src/tests/test262/language/expressions/coalesce/short-circuit-number-0.js

@ -0,0 +1,83 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Short circuit if the CoalesceExpressionHead is not undefined or null (0)
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = undefined;
x = 0 ?? 1;
assert.sameValue(x, 0, '0 ?? 1');
x = undefined;
x = 0 ?? null;
assert.sameValue(x, 0, '0 ?? null');
x = undefined;
x = 0 ?? undefined;
assert.sameValue(x, 0, '0 ?? undefined');
x = undefined;
x = 0 ?? null ?? undefined;
assert.sameValue(x, 0, '0 ?? null ?? undefined');
x = undefined;
x = 0 ?? undefined ?? null;
assert.sameValue(x, 0, '0 ?? undefined ?? null');
x = undefined;
x = 0 ?? null ?? null;
assert.sameValue(x, 0, '0 ?? null ?? null');
x = undefined;
x = 0 ?? undefined ?? undefined;
assert.sameValue(x, 0, '0 ?? null ?? null');
x = undefined;
x = null ?? 0 ?? null;
assert.sameValue(x, 0, 'null ?? 0 ?? null');
x = undefined;
x = null ?? 0 ?? undefined;
assert.sameValue(x, 0, 'null ?? 0 ?? undefined');
x = undefined;
x = undefined ?? 0 ?? null;
assert.sameValue(x, 0, 'undefined ?? 0 ?? null');
x = undefined;
x = undefined ?? 0 ?? undefined;
assert.sameValue(x, 0, 'undefined ?? 0 ?? undefined');
reportCompare(0, 0);

83
js/src/tests/test262/language/expressions/coalesce/short-circuit-number-42.js

@ -0,0 +1,83 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Short circuit if the CoalesceExpressionHead is not undefined or null (42)
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = undefined;
x = 42 ?? 1;
assert.sameValue(x, 42, '42 ?? 1');
x = undefined;
x = 42 ?? null;
assert.sameValue(x, 42, '42 ?? null');
x = undefined;
x = 42 ?? undefined;
assert.sameValue(x, 42, '42 ?? undefined');
x = undefined;
x = 42 ?? null ?? undefined;
assert.sameValue(x, 42, '42 ?? null ?? undefined');
x = undefined;
x = 42 ?? undefined ?? null;
assert.sameValue(x, 42, '42 ?? undefined ?? null');
x = undefined;
x = 42 ?? null ?? null;
assert.sameValue(x, 42, '42 ?? null ?? null');
x = undefined;
x = 42 ?? undefined ?? undefined;
assert.sameValue(x, 42, '42 ?? null ?? null');
x = undefined;
x = null ?? 42 ?? null;
assert.sameValue(x, 42, 'null ?? 42 ?? null');
x = undefined;
x = null ?? 42 ?? undefined;
assert.sameValue(x, 42, 'null ?? 42 ?? undefined');
x = undefined;
x = undefined ?? 42 ?? null;
assert.sameValue(x, 42, 'undefined ?? 42 ?? null');
x = undefined;
x = undefined ?? 42 ?? undefined;
assert.sameValue(x, 42, 'undefined ?? 42 ?? undefined');
reportCompare(0, 0);

84
js/src/tests/test262/language/expressions/coalesce/short-circuit-number-empty-string.js

@ -0,0 +1,84 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Short circuit if the CoalesceExpressionHead is not undefined or null (the empty string)
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
var str = '';
x = undefined;
x = str ?? 1;
assert.sameValue(x, str, 'str ?? 1');
x = undefined;
x = str ?? null;
assert.sameValue(x, str, 'str ?? null');
x = undefined;
x = str ?? undefined;
assert.sameValue(x, str, 'str ?? undefined');
x = undefined;
x = str ?? null ?? undefined;
assert.sameValue(x, str, 'str ?? null ?? undefined');
x = undefined;
x = str ?? undefined ?? null;
assert.sameValue(x, str, 'str ?? undefined ?? null');
x = undefined;
x = str ?? null ?? null;
assert.sameValue(x, str, 'str ?? null ?? null');
x = undefined;
x = str ?? undefined ?? undefined;
assert.sameValue(x, str, 'str ?? null ?? null');
x = undefined;
x = null ?? str ?? null;
assert.sameValue(x, str, 'null ?? str ?? null');
x = undefined;
x = null ?? str ?? undefined;
assert.sameValue(x, str, 'null ?? str ?? undefined');
x = undefined;
x = undefined ?? str ?? null;
assert.sameValue(x, str, 'undefined ?? str ?? null');
x = undefined;
x = undefined ?? str ?? undefined;
assert.sameValue(x, str, 'undefined ?? str ?? undefined');
reportCompare(0, 0);

83
js/src/tests/test262/language/expressions/coalesce/short-circuit-number-false.js

@ -0,0 +1,83 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Short circuit if the CoalesceExpressionHead is not undefined or null (false)
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
x = undefined;
x = false ?? 1;
assert.sameValue(x, false, 'false ?? 1');
x = undefined;
x = false ?? null;
assert.sameValue(x, false, 'false ?? null');
x = undefined;
x = false ?? undefined;
assert.sameValue(x, false, 'false ?? undefined');
x = undefined;
x = false ?? null ?? undefined;
assert.sameValue(x, false, 'false ?? null ?? undefined');
x = undefined;
x = false ?? undefined ?? null;
assert.sameValue(x, false, 'false ?? undefined ?? null');
x = undefined;
x = false ?? null ?? null;
assert.sameValue(x, false, 'false ?? null ?? null');
x = undefined;
x = false ?? undefined ?? undefined;
assert.sameValue(x, false, 'false ?? null ?? null');
x = undefined;
x = null ?? false ?? null;
assert.sameValue(x, false, 'null ?? false ?? null');
x = undefined;
x = null ?? false ?? undefined;
assert.sameValue(x, false, 'null ?? false ?? undefined');
x = undefined;
x = undefined ?? false ?? null;
assert.sameValue(x, false, 'undefined ?? false ?? null');
x = undefined;
x = undefined ?? false ?? undefined;
assert.sameValue(x, false, 'undefined ?? false ?? undefined');
reportCompare(0, 0);

91
js/src/tests/test262/language/expressions/coalesce/short-circuit-number-object.js

@ -0,0 +1,91 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Short circuit if the CoalesceExpressionHead is not undefined or null (object)
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
var obj = {
toString() {
return null;
},
valueOf() {
return null;
}
};
x = undefined;
x = obj ?? 1;
assert.sameValue(x, obj, 'obj ?? 1');
x = undefined;
x = obj ?? null;
assert.sameValue(x, obj, 'obj ?? null');
x = undefined;
x = obj ?? undefined;
assert.sameValue(x, obj, 'obj ?? undefined');
x = undefined;
x = obj ?? null ?? undefined;
assert.sameValue(x, obj, 'obj ?? null ?? undefined');
x = undefined;
x = obj ?? undefined ?? null;
assert.sameValue(x, obj, 'obj ?? undefined ?? null');
x = undefined;
x = obj ?? null ?? null;
assert.sameValue(x, obj, 'obj ?? null ?? null');
x = undefined;
x = obj ?? undefined ?? undefined;
assert.sameValue(x, obj, 'obj ?? null ?? null');
x = undefined;
x = null ?? obj ?? null;
assert.sameValue(x, obj, 'null ?? obj ?? null');
x = undefined;
x = null ?? obj ?? undefined;
assert.sameValue(x, obj, 'null ?? obj ?? undefined');
x = undefined;
x = undefined ?? obj ?? null;
assert.sameValue(x, obj, 'undefined ?? obj ?? null');
x = undefined;
x = undefined ?? obj ?? undefined;
assert.sameValue(x, obj, 'undefined ?? obj ?? undefined');
reportCompare(0, 0);

84
js/src/tests/test262/language/expressions/coalesce/short-circuit-number-string.js

@ -0,0 +1,84 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Short circuit if the CoalesceExpressionHead is not undefined or null (string)
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
var str = 'undefined';
x = undefined;
x = str ?? 1;
assert.sameValue(x, str, 'str ?? 1');
x = undefined;
x = str ?? null;
assert.sameValue(x, str, 'str ?? null');
x = undefined;
x = str ?? undefined;
assert.sameValue(x, str, 'str ?? undefined');
x = undefined;
x = str ?? null ?? undefined;
assert.sameValue(x, str, 'str ?? null ?? undefined');
x = undefined;
x = str ?? undefined ?? null;
assert.sameValue(x, str, 'str ?? undefined ?? null');
x = undefined;
x = str ?? null ?? null;
assert.sameValue(x, str, 'str ?? null ?? null');
x = undefined;
x = str ?? undefined ?? undefined;
assert.sameValue(x, str, 'str ?? null ?? null');
x = undefined;
x = null ?? str ?? null;
assert.sameValue(x, str, 'null ?? str ?? null');
x = undefined;
x = null ?? str ?? undefined;
assert.sameValue(x, str, 'null ?? str ?? undefined');
x = undefined;
x = undefined ?? str ?? null;
assert.sameValue(x, str, 'undefined ?? str ?? null');
x = undefined;
x = undefined ?? str ?? undefined;
assert.sameValue(x, str, 'undefined ?? str ?? undefined');
reportCompare(0, 0);

84
js/src/tests/test262/language/expressions/coalesce/short-circuit-number-symbol.js

@ -0,0 +1,84 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Short circuit if the CoalesceExpressionHead is not undefined or null (Symbol)
esid: sec-conditional-operator
info: |
ConditionalExpression :
ShortCircuitExpression
ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
ShortCircuitExpression :
LogicalORExpression
CoalesceExpression
CoalesceExpression :
CoalesceExpressionHead ?? BitwiseORExpression
CoalesceExpressionHead :
CoalesceExpression
BitwiseORExpression
Runtime Semantics: Evaluation
CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
1. Let lref be the result of evaluating CoalesceExpressionHead.
2. Let lval be ? GetValue(lref).
3. If lval is undefined or null,
a. Let rref be the result of evaluating BitwiseORExpression.
b. Return ? GetValue(rref).
4. Otherwise, return lval.
features: [coalesce-expression]
---*/
var x;
var s = Symbol();
x = undefined;
x = s ?? 1;
assert.sameValue(x, s, 's ?? null');
x = undefined;
x = s ?? null;
assert.sameValue(x, s, 's ?? null');
x = undefined;
x = s ?? undefined;
assert.sameValue(x, s, 's ?? undefined');
x = undefined;
x = s ?? null ?? undefined;
assert.sameValue(x, s, 's ?? null ?? undefined');
x = undefined;