mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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:
parent
3f73b0f896
commit
5a307836c1
Notes:
sideshowbarker
2024-07-19 01:25:33 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/5a307836c1d Pull-request: https://github.com/SerenityOS/serenity/pull/4063 Issue: https://github.com/SerenityOS/serenity/issues/4062
2 changed files with 4 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue