LibJS: Fix evaluation order of computed property keys in object literals

The spec for PropertyDefinitionEvaluation requires that when evaluating
a property definition with a computed key (PropertyDefinition :
PropertyName : AssignmentExpression), the PropertyName is fully
evaluated (including ToPropertyKey, which calls ToPrimitive) before the
value's AssignmentExpression is evaluated.

Our bytecode compiler was evaluating the key expression first, then
the value expression, and only performing ToPropertyKey later inside
PutByValue at runtime. This meant user-observable side effects from
ToPrimitive (such as calling Symbol.toPrimitive or toString on the key
object) would fire after the value expression had already been
evaluated.

Fix this by using a new ToPrimitiveWithStringHint instruction that
performs ToPrimitive with string hint(!), and emitting it between the
key and value evaluations in ObjectExpression codegen.
After ToPrimitive, the key is already a primitive, so the subsequent
ToPropertyKey inside PutByValue becomes a no-op from the perspective
of user-observable side
effects.

Also update an existing test that was asserting the old (incorrect)
evaluation order, and add comprehensive new tests for computed property
key evaluation order.
This commit is contained in:
Andreas Kling
2026-02-08 12:32:38 +01:00
committed by Andreas Kling
parent bef09b899c
commit 5cefa59116
Notes: github-actions[bot] 2026-02-09 00:24:46 +00:00
5 changed files with 255 additions and 4 deletions

View File

@@ -62,6 +62,11 @@ op ToString < Instruction
m_value: Operand
endop
op ToPrimitiveWithStringHint < Instruction
m_dst: Operand
m_value: Operand
endop
op BitwiseXor < Instruction
m_dst: Operand
m_lhs: Operand