Bug 1916260 - Part 8: Evaluate ComputedPropertyName first. r=spidermonkey-reviewers,jandem

Computed property names are evaluated first in destructuring contexts.

Differential Revision: https://phabricator.services.mozilla.com/D220827
This commit is contained in:
André Bargull
2024-09-05 05:35:06 +00:00
parent 0cee76ac6d
commit e1387210b7
2 changed files with 16 additions and 8 deletions

View File

@@ -3833,6 +3833,7 @@ bool BytecodeEmitter::emitDestructuringOpsObject(ListNode* pattern,
for (ParseNode* member : pattern->contents()) {
ParseNode* subpattern;
bool hasKeyOnStack = false;
if (member->isKind(ParseNodeKind::MutateProto) ||
member->isKind(ParseNodeKind::Spread)) {
subpattern = member->as<UnaryNode>().kid();
@@ -3843,6 +3844,16 @@ bool BytecodeEmitter::emitDestructuringOpsObject(ListNode* pattern,
MOZ_ASSERT(member->isKind(ParseNodeKind::PropertyDefinition) ||
member->isKind(ParseNodeKind::Shorthand));
subpattern = member->as<BinaryNode>().right();
// Computed property names are evaluated before the subpattern.
ParseNode* key = member->as<BinaryNode>().left();
if (key->isKind(ParseNodeKind::ComputedName)) {
if (!emitComputedPropertyName(&key->as<UnaryNode>())) {
// [stack] ... SET? RHS KEY
return false;
}
hasKeyOnStack = true;
}
}
ParseNode* lhs = subpattern;
@@ -3857,13 +3868,13 @@ bool BytecodeEmitter::emitDestructuringOpsObject(ListNode* pattern,
// Spec requires LHS reference to be evaluated first.
if (!emitDestructuringLHSRef(lhs, &emitted)) {
// [stack] ... SET? RHS LREF*
// [stack] ... SET? RHS KEY? LREF*
return false;
}
// Duplicate the value being destructured to use as a reference base.
if (!emitDupAt(emitted)) {
// [stack] ... SET? RHS LREF* RHS
if (!emitDupAt(emitted + hasKeyOnStack)) {
// [stack] ... SET? RHS KEY? LREF* RHS
return false;
}
@@ -3939,8 +3950,9 @@ bool BytecodeEmitter::emitDestructuringOpsObject(ListNode* pattern,
// Otherwise this is a computed property name. BigInt keys are parsed
// as (synthetic) computed property names, too.
MOZ_ASSERT(key->isKind(ParseNodeKind::ComputedName));
MOZ_ASSERT(hasKeyOnStack);
if (!emitComputedPropertyName(&key->as<UnaryNode>())) {
if (!emit2(JSOp::Pick, emitted + 1)) {
// [stack] ... SET? RHS LREF* RHS KEY
return false;
}

View File

@@ -562,10 +562,6 @@ skip script test262/language/statements/with/cptn-nrml.js
# https://bugzilla.mozilla.org/show_bug.cgi?id=1339123
skip script test262/annexB/language/function-code/block-decl-func-skip-arguments.js
# https://bugzilla.mozilla.org/show_bug.cgi?id=1407587
skip script test262/language/expressions/assignment/destructuring/keyed-destructuring-property-reference-target-evaluation-order.js
skip script test262/language/expressions/assignment/destructuring/iterator-destructuring-property-reference-target-evaluation-order.js
# https://bugzilla.mozilla.org/show_bug.cgi?id=1321616
skip script test262/annexB/built-ins/Function/createdynfn-no-line-terminator-html-close-comment-body.js