From a4897ed7b2fb15d637b3ddfaf896ca7c0cb6b4d2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 2 Jul 2021 00:32:23 +0200 Subject: [PATCH] LibJS: Throw on failed PutValue into an environment reference This should really be handled at a different layer of the stack, but this allows us to make progress on the Object rewrite without breaking strict mode assignment tests. --- Userland/Libraries/LibJS/Runtime/Reference.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/Reference.cpp b/Userland/Libraries/LibJS/Runtime/Reference.cpp index 4e3265ce0d..f87c8d64ba 100644 --- a/Userland/Libraries/LibJS/Runtime/Reference.cpp +++ b/Userland/Libraries/LibJS/Runtime/Reference.cpp @@ -60,7 +60,15 @@ void Reference::put_value(GlobalObject& global_object, Value value) return; } - m_base_environment->put_into_environment(m_name.as_string(), variable); + bool succeeded = m_base_environment->put_into_environment(m_name.as_string(), variable); + if (vm.exception()) + return; + + if (!succeeded && m_strict) { + // FIXME: This is a hack and will disappear when we support proper variable bindings. + vm.throw_exception(global_object, ErrorType::DescWriteNonWritable, m_name.to_value(vm).to_string_without_side_effects()); + return; + } } void Reference::throw_reference_error(GlobalObject& global_object)