diff --git a/js/src/frontend/FoldConstants.cpp b/js/src/frontend/FoldConstants.cpp index 75bd36e8b46f..ff25a397f70d 100644 --- a/js/src/frontend/FoldConstants.cpp +++ b/js/src/frontend/FoldConstants.cpp @@ -718,6 +718,7 @@ static bool FoldAndOrCoalesce(JSContext* cx, ParseNode** nodePtr) { bool isTruthyCoalesceNode = isCoalesceNode && !((*elem)->isKind(ParseNodeKind::NullExpr) || + (*elem)->isKind(ParseNodeKind::VoidExpr) || (*elem)->isKind(ParseNodeKind::RawUndefinedExpr)); bool canShortCircuit = (isOrNode && t == Truthy) || (isAndNode && t == Falsy) || isTruthyCoalesceNode; diff --git a/js/src/tests/non262/expressions/nullish-coalescing.js b/js/src/tests/non262/expressions/nullish-coalescing.js index 97d38d23dc1c..1f44b00b214c 100644 --- a/js/src/tests/non262/expressions/nullish-coalescing.js +++ b/js/src/tests/non262/expressions/nullish-coalescing.js @@ -67,6 +67,7 @@ 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,