Skip to content

Commit 5d4ca7b

Browse files
devsnekCommit Bot
authored andcommitted
fix delete + optional chain jump condition
The optional chaining bytecode in delete expressions was unconditionally jumping if the receiver was nullish, instead of just when the property was an actual optional chain link. This change adds the missing check around the jump. Change-Id: Ic7bed58be4ae62d157e63e4f77666b1abd1f802d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1755264 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/master@{#63251}
1 parent 6070193 commit 5d4ca7b

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/interpreter/bytecode-generator.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4860,11 +4860,14 @@ void BytecodeGenerator::VisitDelete(UnaryOperation* unary) {
48604860
BytecodeLabel done;
48614861
OptionalChainNullLabelScope label_scope(this);
48624862
VisitForAccumulatorValue(property->obj());
4863-
builder()->JumpIfUndefinedOrNull(label_scope.labels()->New());
4863+
if (property->is_optional_chain_link()) {
4864+
builder()->JumpIfUndefinedOrNull(label_scope.labels()->New());
4865+
}
48644866
Register object = register_allocator()->NewRegister();
48654867
builder()->StoreAccumulatorInRegister(object);
48664868
VisitForAccumulatorValue(property->key());
4867-
builder()->Delete(object, language_mode()).Jump(&done);
4869+
builder()->Delete(object, language_mode());
4870+
builder()->Jump(&done);
48684871
label_scope.labels()->Bind(builder());
48694872
builder()->LoadTrue();
48704873
builder()->Bind(&done);

test/mjsunit/harmony/optional-chaining.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ assertEquals(delete o1?.['y'], true);
8888
assertEquals(o1.y, undefined);
8989
assertEquals(delete o1?.['y'], true);
9090
assertEquals(delete o1.z?.(), true);
91+
assertThrows(() => { delete ({})?.foo.bar; });
9192

9293
shouldThrowSyntaxError('class C {} class D extends C { foo() { return super?.bar; } }');
9394
shouldThrowSyntaxError('class C {} class D extends C { foo() { return super?.["bar"]; } }');

0 commit comments

Comments
 (0)