Skip to content

Commit a33799e

Browse files
Check for null not truthy
1 parent 6538ef0 commit a33799e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/Runtime/ByteCode/ByteCodeEmitter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ void VisitClearTmpRegs(ParseNode * pnode, ByteCodeGenerator * byteCodeGenerator,
2424
* This function generates the common code for null-propagation / optional-chaining.
2525
* This works similar to how the c# compiler emits byte-code for optional-chaining.
2626
*/
27-
static void EmitNullPropagation(Js::RegSlot targetObjectSlot, ByteCodeGenerator *byteCodeGenerator, FuncInfo* funcInfo, bool isNullPropagating) {
27+
static void EmitNullPropagation(Js::RegSlot targetObjectSlot, ByteCodeGenerator *byteCodeGenerator, FuncInfo *funcInfo, bool isNullPropagating) {
2828
if (!isNullPropagating)
2929
return;
3030

3131
Assert(funcInfo->currentOptionalChain != 0);
3232

3333
Js::ByteCodeLabel continueLabel = byteCodeGenerator->Writer()->DefineLabel();
34-
byteCodeGenerator->Writer()->BrReg1(Js::OpCode::BrTrue_A, continueLabel, targetObjectSlot); // if (targetObject)
34+
byteCodeGenerator->Writer()->BrReg2(Js::OpCode::BrNeq_A, continueLabel, targetObjectSlot, funcInfo->nullConstantRegister);
35+
// if (targetObject == null)
3536
{
3637
byteCodeGenerator->Writer()->Reg1(Js::OpCode::LdUndef, funcInfo->currentOptionalChain->resultSlot); // result = undefined
3738
byteCodeGenerator->Writer()->Br(funcInfo->currentOptionalChain->skipLabel);

lib/Runtime/ByteCode/ByteCodeGenerator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4962,6 +4962,7 @@ void AssignRegisters(ParseNode *pnode, ByteCodeGenerator *byteCodeGenerator)
49624962
CheckMaybeEscapedUse(pnode->AsParseNodeUni()->pnode1, byteCodeGenerator);
49634963
break;
49644964
case knopCoalesce:
4965+
case knopOptChain:
49654966
case knopObject:
49664967
byteCodeGenerator->AssignNullConstRegister();
49674968
break;

0 commit comments

Comments
 (0)