1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:58:11 +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:
Linus Groh 2021-01-10 14:08:27 +01:00 committed by Andreas Kling
parent a5e557472c
commit 9be0b664e3
3 changed files with 10 additions and 9 deletions

View file

@ -70,7 +70,7 @@ String JSONObject::stringify_impl(GlobalObject& global_object, Value value, Valu
state.replacer_function = &replacer.as_function();
} else if (replacer.is_array()) {
auto& replacer_object = replacer.as_object();
auto replacer_length = length_of_array_like(global_object, replacer);
auto replacer_length = length_of_array_like(global_object, replacer_object);
if (vm.exception())
return {};
Vector<String> list;
@ -298,7 +298,7 @@ String JSONObject::serialize_json_array(GlobalObject& global_object, StringifySt
state.indent = String::formatted("{}{}", state.indent, state.gap);
Vector<String> property_strings;
auto length = length_of_array_like(global_object, Value(&object));
auto length = length_of_array_like(global_object, object);
if (vm.exception())
return {};
for (size_t i = 0; i < length; ++i) {
@ -476,7 +476,7 @@ Value JSONObject::internalize_json_property(GlobalObject& global_object, Object*
};
if (value_object.is_array()) {
auto length = length_of_array_like(global_object, value);
auto length = length_of_array_like(global_object, value_object);
for (size_t i = 0; i < length; ++i) {
process_property(i);
if (vm.exception())