From 5a307836c1d17592182d0fd4b11694c40c303066 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 12 Nov 2020 10:32:46 +0000 Subject: [PATCH] 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. --- Libraries/LibJS/Runtime/Reference.cpp | 2 +- Libraries/LibJS/Tests/strict-mode-errors.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Libraries/LibJS/Runtime/Reference.cpp b/Libraries/LibJS/Runtime/Reference.cpp index ee13097681..6b6b06f80f 100644 --- a/Libraries/LibJS/Runtime/Reference.cpp +++ b/Libraries/LibJS/Runtime/Reference.cpp @@ -50,7 +50,7 @@ void Reference::put(GlobalObject& global_object, Value value) } if (!base().is_object() && vm.in_strict_mode()) { - vm.throw_exception(global_object, ErrorType::ReferencePrimitiveAssignment, m_name.to_string()); + vm.throw_exception(global_object, ErrorType::ReferencePrimitiveAssignment, m_name.to_value(global_object.vm()).to_string_without_side_effects()); return; } diff --git a/Libraries/LibJS/Tests/strict-mode-errors.js b/Libraries/LibJS/Tests/strict-mode-errors.js index c5e8b86414..2b640d1f3c 100644 --- a/Libraries/LibJS/Tests/strict-mode-errors.js +++ b/Libraries/LibJS/Tests/strict-mode-errors.js @@ -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"); }); });