Browse Source

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. :^)
Andreas Kling 1 year ago
parent
commit
c90bf22d29
1 changed files with 11 additions and 3 deletions
  1. 11 3
      Userland/Libraries/LibJS/Bytecode/Op.cpp

+ 11 - 3
Userland/Libraries/LibJS/Bytecode/Op.cpp

@@ -1180,11 +1180,19 @@ ThrowCompletionOr<void> 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 {};
 }