1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

LibJS: Handle Proxy with Array target in IsArray() abstract operation

This was missing from Value::is_array(), which is equivalent to the
spec's IsArray() abstract operation - it treats a Proxy value with an
Array target object as being an Array.
It can throw, so needs both the global object and an exception check
now.
This commit is contained in:
Linus Groh 2021-06-08 21:53:36 +01:00 committed by Andreas Kling
parent 9b35231453
commit 83be39c91a
11 changed files with 52 additions and 24 deletions

View file

@ -48,7 +48,7 @@ String JSONObject::stringify_impl(GlobalObject& global_object, Value value, Valu
if (replacer.is_object()) {
if (replacer.as_object().is_function()) {
state.replacer_function = &replacer.as_function();
} else if (replacer.is_array()) {
} else if (replacer.is_array(global_object)) {
auto& replacer_object = replacer.as_object();
auto replacer_length = length_of_array_like(global_object, replacer_object);
if (vm.exception())
@ -77,6 +77,8 @@ String JSONObject::stringify_impl(GlobalObject& global_object, Value value, Valu
}
state.property_list = list;
}
if (vm.exception())
return {};
}
if (space.is_object()) {
@ -172,8 +174,10 @@ String JSONObject::serialize_json_property(GlobalObject& global_object, Stringif
return "null";
}
if (value.is_object() && !value.is_function()) {
if (value.is_array())
if (value.is_array(global_object))
return serialize_json_array(global_object, state, static_cast<Array&>(value.as_object()));
if (vm.exception())
return {};
return serialize_json_object(global_object, state, value.as_object());
}
if (value.is_bigint())