mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:37:35 +00:00
LibJS: Avoid unnecessary ToObject conversion when resolving references
When performing GetValue on a primitive type we do not need to perform the ToObject conversion as it will resolve to a property on the prototype object. To avoid this we skip the initial ToObject conversion on the base value as it only serves to get the primitive's boxed prototype. We further specialize on PrimitiveString in order to get efficient behaviour behaviour for the direct properties. Depending on the tests anywhere from 20 to 60%, with significant loop overhead.
This commit is contained in:
parent
3a184f7841
commit
d1cc67bbe1
7 changed files with 77 additions and 24 deletions
|
@ -63,15 +63,26 @@ ThrowCompletionOr<Value> Reference::get_value(GlobalObject& global_object) const
|
|||
return throw_reference_error(global_object);
|
||||
|
||||
if (is_property_reference()) {
|
||||
auto* base_obj = TRY(m_base_value.to_object(global_object));
|
||||
|
||||
if (is_private_reference()) {
|
||||
// FIXME: We need to be able to specify the receiver for this
|
||||
// if we want to use it in error messages in future
|
||||
// as things currently stand this does the "wrong thing" but
|
||||
// the error is unobservable
|
||||
auto base_obj = TRY(m_base_value.to_object(global_object));
|
||||
return base_obj->private_get(m_private_name);
|
||||
}
|
||||
Object* base_obj = nullptr;
|
||||
if (m_base_value.is_string()) {
|
||||
auto string_value = m_base_value.as_string().get(global_object, m_name);
|
||||
if (string_value.has_value())
|
||||
return *string_value;
|
||||
base_obj = global_object.string_prototype();
|
||||
} else if (m_base_value.is_number())
|
||||
base_obj = global_object.number_prototype();
|
||||
else if (m_base_value.is_boolean())
|
||||
base_obj = global_object.boolean_prototype();
|
||||
else
|
||||
base_obj = TRY(m_base_value.to_object(global_object));
|
||||
|
||||
return base_obj->internal_get(m_name, m_base_value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue