From c90bf22d296f9f1b58a17526d22ffb7e3ba3d89a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 21 Jul 2023 07:18:30 +0200 Subject: [PATCH] LibJS/Bytecode: Use primitive `this` for strict mode GetByValue GetByValue now shares code with GetById to elide the synthetic wrapper objects for primitive values in strict mode. Fixes 2 test-js tests in bytecode mode. :^) --- Userland/Libraries/LibJS/Bytecode/Op.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index b450b6296c..9de0101f4d 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -1180,11 +1180,19 @@ ThrowCompletionOr GetByValue::execute_impl(Bytecode::Interpreter& interpre // NOTE: Get the property key from the accumulator before side effects have a chance to overwrite it. auto property_key_value = interpreter.accumulator(); - auto object = TRY(interpreter.reg(m_base).to_object(vm)); - + auto base_value = interpreter.reg(m_base); + auto object = TRY(base_object_for_get(interpreter, base_value)); auto property_key = TRY(property_key_value.to_property_key(vm)); - interpreter.accumulator() = TRY(object->get(property_key)); + if (base_value.is_string()) { + auto string_value = TRY(base_value.as_string().get(vm, property_key)); + if (string_value.has_value()) { + interpreter.accumulator() = *string_value; + return {}; + } + } + + interpreter.accumulator() = TRY(object->internal_get(property_key, base_value)); return {}; }