1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 19:05:08 +00:00

LibJS: Implement the GetMethod() abstract operation as a Value method

This was a standalone function previously (get_method()), but instead of
passing a Value to it, we can just make it a method.

Also add spec step comments and fix the receiver value by using GetV().
This commit is contained in:
Linus Groh 2021-06-26 19:24:35 +01:00
parent 31f5797e89
commit 337ad6d15c
8 changed files with 48 additions and 41 deletions

View file

@ -39,25 +39,6 @@ Value require_object_coercible(GlobalObject& global_object, Value value)
return value;
}
// 7.3.10 GetMethod ( V, P ), https://tc39.es/ecma262/#sec-getmethod
Function* get_method(GlobalObject& global_object, Value value, PropertyName const& property_name)
{
auto& vm = global_object.vm();
auto* object = value.to_object(global_object);
if (vm.exception())
return nullptr;
auto property_value = object->get(property_name);
if (vm.exception())
return nullptr;
if (property_value.is_empty() || property_value.is_nullish())
return nullptr;
if (!property_value.is_function()) {
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, property_value.to_string_without_side_effects());
return nullptr;
}
return &property_value.as_function();
}
// 7.3.18 LengthOfArrayLike ( obj ), https://tc39.es/ecma262/#sec-lengthofarraylike
size_t length_of_array_like(GlobalObject& global_object, Object const& object)
{