From 53926d7fbf4232cdef0449b5b515404085fea3f1 Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Fri, 27 May 2022 16:21:50 -0500 Subject: [JS:Engine] Implement support for nullish coalescing in the JS parser - UXP Parts 1, 2, 4, 5, and 7 based on Bug 1566141 - UXP Part 3 partially based on Bugs 1566141 and 1593415 - UXP Part 6 partly based on Bugs 1566141 and 1599163 with a different approach by modifying the `Boolish` function directly to act differently if we're checking for nullish values. --- .../coalesce/chainable-with-bitwise-or.js | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 js/src/tests/test262/language/expressions/coalesce/chainable-with-bitwise-or.js (limited to 'js/src/tests/test262/language/expressions/coalesce/chainable-with-bitwise-or.js') diff --git a/js/src/tests/test262/language/expressions/coalesce/chainable-with-bitwise-or.js b/js/src/tests/test262/language/expressions/coalesce/chainable-with-bitwise-or.js new file mode 100644 index 000000000..214d4fd9a --- /dev/null +++ b/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); -- cgit v1.2.3