mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibJS: Make length_of_array_like() take an Object rather than Value
The pseudo-code from the spec says "Assert: Type(obj) is Object.", so we can just enforce this at compile time rather than taking it literally and doing "ASSERT(value.is_object())". Also fix an issue where the absence of a "length" property on the object would cause a crash (to_number() on empty value).
This commit is contained in:
parent
a5e557472c
commit
9be0b664e3
3 changed files with 10 additions and 9 deletions
|
@ -1222,14 +1222,15 @@ TriState abstract_relation(GlobalObject& global_object, bool left_first, Value l
|
|||
return TriState::False;
|
||||
}
|
||||
|
||||
size_t length_of_array_like(GlobalObject& global_object, Value value)
|
||||
size_t length_of_array_like(GlobalObject& global_object, const Object& object)
|
||||
{
|
||||
ASSERT(value.is_object());
|
||||
// 7.3.18 LengthOfArrayLike, https://tc39.es/ecma262/#sec-lengthofarraylike
|
||||
|
||||
auto& vm = global_object.vm();
|
||||
auto result = value.as_object().get(vm.names.length);
|
||||
auto result = object.get(vm.names.length).value_or(js_undefined());
|
||||
if (vm.exception())
|
||||
return 0;
|
||||
return result.to_size_t(global_object);
|
||||
return INVALID;
|
||||
return result.to_length(global_object);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue