test(ecmascript): add comments and tests for cases where ToPropertyKey throws an error (#9429)

This commit is contained in:
sapphi-red committed 2025-02-28 07:49:24 +00:00
1 parent fb8a93de63
commit c187b11d86
2 files changed
+7

No files matched your search

@@ -340,6 +340,8 @@ impl MayHaveSideEffects for PropertyKey<'_> {
match self {
PropertyKey::StaticIdentifier(_) | PropertyKey::PrivateIdentifier(_) => false,
match_expression!(PropertyKey) => {
// ToPropertyKey(key) throws an error when ToPrimitive(key) throws an Error
// But we can ignore that by using the assumption.
self.to_expression().may_have_side_effects(is_global_reference)
}
}
@@ -560,6 +560,11 @@ fn test_object_expression() {
test("({[1]: 1})", false);
test("({[1n]: 1})", false);
test("({['1']: 1})", false);
// These actually have a side effect, but this treated as side-effect free.
test("({[{ toString() { console.log('sideeffect') } }]: 1})", false);
test("({[{ valueOf() { console.log('sideeffect') } }]: 1})", false);
test("({[{ [s]() { console.log('sideeffect') } }]: 1})", false); // assuming s is Symbol.toPrimitive
test("({[foo]: 1})", false);
test("({[foo()]: 1 })", true);
test("({a: foo()})", true);
test("({...a})", true);