Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 0dde5cddb126e5c9fc51f61d9984a389c19b3c71
https://github.com/WebKit/WebKit/commit/0dde5cddb126e5c9fc51f61d9984a389c19b3c71
Author: Sosuke Suzuki <[email protected]>
Date: 2026-06-13 (Sat, 13 Jun 2026)
Changed paths:
A JSTests/stress/nullish-coalescing-in-condition-context-edge-cases.js
A JSTests/stress/nullish-coalescing-in-condition-context.js
M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
M Source/JavaScriptCore/parser/Nodes.h
Log Message:
-----------
[JSC] Add `emitBytecodeInConditionContext` for nullish coalescing
https://bugs.webkit.org/show_bug.cgi?id=316090
Reviewed by Yusuke Suzuki.
`if (a ?? b)` materialized the result into a temporary and tested it
with `jfalse`, defeating the condition-context lowering of the
right-hand side (e.g. `&&`, `||`, `!`).
Implement CoalesceNode::emitBytecodeInConditionContext: test the
left-hand side with a fused `jundefined_or_null`, branch directly on
its truthiness when non-nullish, and otherwise emit the right-hand
side in the condition context. When the coalesce has absorbed an
optional chain (`o?.x ?? b`), the nullish label doubles as the chain's
bail-out target.
Before:
if (a ?? b)
[ 0] enter
[ 1] mov loc5, arg1
[ 4] jnundefined_or_null loc5, ->10
[ 7] mov loc5, arg2
[10] jfalse loc5, ->15
After:
[ 0] enter
[ 1] jundefined_or_null arg1, ->9
[ 4] jfalse arg1, ->14
[ 7] jmp ->12
[ 9] jfalse arg2, ->14
Tests: JSTests/stress/nullish-coalescing-in-condition-context-edge-cases.js
JSTests/stress/nullish-coalescing-in-condition-context.js
* JSTests/stress/nullish-coalescing-in-condition-context-edge-cases.js: Added.
(shouldBe):
(testMasqLhs):
(testMasqRhs):
(testMasqNot):
(testMasqWhile):
(testMasqOSR):
(const.counting.get x):
(testGetterOnce):
(testCallOnce):
(i.shouldBe.testCallOnce.f):
(rhsEffect):
(testRhsSkipped):
(const.trapped.valueOf):
(const.trapped.toString):
(const.trapped.Symbol.toPrimitive):
(testNoToPrimitive):
(testPrim):
(testAssignLhs):
(testNestedChains):
(testThisBinding):
(const.thisObj.m):
(testDeleteChain):
(testThrowingGetter):
(const.throwing.get x):
(testWithScope):
(testDirectEval):
(clobber):
(testRegisterPressure):
(testComposed):
* JSTests/stress/nullish-coalescing-in-condition-context.js: Added.
(shouldBe):
(testNot):
(testRhsAnd):
(testRhsOr):
(testRhsNot):
(testRhsRel):
(testRhsEq):
(testNested):
(testTernaryCond):
(testOuterAnd):
(testOuterOr):
(testWhile):
(testFor):
(testDoWhile):
(testCommaLhs):
(i.shouldBe.testWhile.next):
(testOptChain):
(testOptChainCall):
(testOptChainDeep):
(testOptChainRhsAnd):
(i.shouldBe.testOptChainCall.f):
(testOrder):
(testOrderShortCircuit):
(testOrderInRhsAnd):
(testThrowLhs):
(testThrowRhs):
(gen):
(async asyncFn):
(async for):
(testSwitch):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::CoalesceNode::emitBytecodeInConditionContext):
* Source/JavaScriptCore/parser/Nodes.h:
Canonical link: https://commits.webkit.org/315176@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications