LibJS: Handle symbol PropertyName in primitive assignment error

We can't just to_string() the PropertyName, it might be a symbol.
Instead to_value() it and then use to_string_without_side_effects() as
usual.

Fixes #4062.
This commit is contained in:
Linus Groh 2020-11-12 10:32:46 +00:00 committed by Andreas Kling
parent 3f73b0f896
commit 5a307836c1
Notes: sideshowbarker 2024-07-19 01:25:33 +09:00
2 changed files with 4 additions and 1 deletions

View file

@ -50,7 +50,7 @@ void Reference::put(GlobalObject& global_object, Value value)
}
if (!base().is_object() && vm.in_strict_mode()) {
vm.throw_exception<TypeError>(global_object, ErrorType::ReferencePrimitiveAssignment, m_name.to_string());
vm.throw_exception<TypeError>(global_object, ErrorType::ReferencePrimitiveAssignment, m_name.to_value(global_object.vm()).to_string_without_side_effects());
return;
}

View file

@ -5,5 +5,8 @@ test("basic functionality", () => {
expect(() => {
primitive.foo = "bar";
}).toThrowWithMessage(TypeError, "Cannot assign property foo to primitive value");
expect(() => {
primitive[Symbol.hasInstance] = 123;
}).toThrowWithMessage(TypeError, "Cannot assign property Symbol(Symbol.hasInstance) to primitive value");
});
});