1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:18:12 +00:00

LibJS/Bytecode: Move GetByValue implementation to CommonImplementations

This commit is contained in:
Andreas Kling 2023-10-20 12:38:43 +02:00
parent 1c0efbec6b
commit e8190105db
4 changed files with 30 additions and 31 deletions

View file

@ -60,4 +60,30 @@ ThrowCompletionOr<Value> get_by_id(Bytecode::Interpreter& interpreter, Identifie
return value;
}
ThrowCompletionOr<Value> get_by_value(Bytecode::Interpreter& interpreter, Value base_value, Value property_key_value)
{
auto& vm = interpreter.vm();
auto object = TRY(base_object_for_get(interpreter, base_value));
// OPTIMIZATION: Fast path for simple Int32 indexes in array-like objects.
if (property_key_value.is_int32()
&& property_key_value.as_i32() >= 0
&& !object->may_interfere_with_indexed_property_access()
&& object->indexed_properties().has_index(property_key_value.as_i32())) {
auto value = object->indexed_properties().get(property_key_value.as_i32())->value;
if (!value.is_accessor())
return value;
}
auto property_key = TRY(property_key_value.to_property_key(vm));
if (base_value.is_string()) {
auto string_value = TRY(base_value.as_string().get(vm, property_key));
if (string_value.has_value())
return *string_value;
}
return TRY(object->internal_get(property_key, base_value));
}
}