mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 10:07:40 +00:00
LibJS: Switch is_array to ThrowCompletionOr
This commit is contained in:
parent
0b9e633482
commit
1db7e096e2
6 changed files with 15 additions and 26 deletions
|
@ -213,7 +213,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
|
|||
JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::is_array)
|
||||
{
|
||||
auto value = vm.argument(0);
|
||||
return Value(value.is_array(global_object));
|
||||
return Value(TRY_OR_DISCARD(value.is_array(global_object)));
|
||||
}
|
||||
|
||||
// 23.1.2.3 Array.of ( ...items ), https://tc39.es/ecma262/#sec-array.of
|
||||
|
|
|
@ -107,9 +107,7 @@ static Object* array_species_create(GlobalObject& global_object, Object& origina
|
|||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
auto is_array = Value(&original_array).is_array(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto is_array = TRY_OR_DISCARD(Value(&original_array).is_array(global_object));
|
||||
|
||||
if (!is_array) {
|
||||
auto array = Array::create(global_object, length);
|
||||
|
@ -593,7 +591,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
|
|||
size_t n = 0;
|
||||
|
||||
// 23.1.3.1.1 IsConcatSpreadable ( O ), https://tc39.es/ecma262/#sec-isconcatspreadable
|
||||
auto is_concat_spreadable = [&vm, &global_object](Value const& val) {
|
||||
auto is_concat_spreadable = [&vm, &global_object](Value const& val) -> bool {
|
||||
if (!val.is_object()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -608,7 +606,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
|
|||
if (!spreadable.is_undefined())
|
||||
return spreadable.to_boolean();
|
||||
|
||||
return val.is_array(global_object);
|
||||
return TRY_OR_DISCARD(val.is_array(global_object));
|
||||
};
|
||||
|
||||
auto append_to_new_array = [&vm, &is_concat_spreadable, &new_array, &global_object, &n](Value arg) {
|
||||
|
@ -1895,7 +1893,7 @@ static size_t flatten_into_array(GlobalObject& global_object, Object& new_array,
|
|||
return {};
|
||||
}
|
||||
|
||||
if (depth > 0 && value.is_array(global_object)) {
|
||||
if (depth > 0 && TRY_OR_DISCARD(value.is_array(global_object))) {
|
||||
if (vm.did_reach_stack_space_limit()) {
|
||||
vm.throw_exception<Error>(global_object, ErrorType::CallStackSizeExceeded);
|
||||
return {};
|
||||
|
|
|
@ -54,9 +54,7 @@ String JSONObject::stringify_impl(GlobalObject& global_object, Value value, Valu
|
|||
if (replacer.as_object().is_function()) {
|
||||
state.replacer_function = &replacer.as_function();
|
||||
} else {
|
||||
auto is_array = replacer.is_array(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto is_array = TRY_OR_DISCARD(replacer.is_array(global_object));
|
||||
if (is_array) {
|
||||
auto& replacer_object = replacer.as_object();
|
||||
auto replacer_length = TRY_OR_DISCARD(length_of_array_like(global_object, replacer_object));
|
||||
|
@ -200,9 +198,7 @@ String JSONObject::serialize_json_property(GlobalObject& global_object, Stringif
|
|||
return {};
|
||||
}
|
||||
if (value.is_object() && !value.is_function()) {
|
||||
auto is_array = value.is_array(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto is_array = TRY_OR_DISCARD(value.is_array(global_object));
|
||||
if (is_array) {
|
||||
auto result = serialize_json_array(global_object, state, static_cast<Array&>(value.as_object()));
|
||||
if (vm.exception())
|
||||
|
@ -479,9 +475,7 @@ Value JSONObject::internalize_json_property(GlobalObject& global_object, Object*
|
|||
if (vm.exception())
|
||||
return {};
|
||||
if (value.is_object()) {
|
||||
auto is_array = value.is_array(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto is_array = TRY_OR_DISCARD(value.is_array(global_object));
|
||||
|
||||
auto& value_object = value.as_object();
|
||||
auto process_property = [&](const PropertyName& key) {
|
||||
|
|
|
@ -87,9 +87,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string)
|
|||
VERIFY(object);
|
||||
|
||||
// 4. Let isArray be ? IsArray(O).
|
||||
auto is_array = Value(object).is_array(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto is_array = TRY_OR_DISCARD(Value(object).is_array(global_object));
|
||||
|
||||
String builtin_tag;
|
||||
|
||||
|
|
|
@ -192,8 +192,10 @@ static String double_to_string(double d)
|
|||
}
|
||||
|
||||
// 7.2.2 IsArray ( argument ), https://tc39.es/ecma262/#sec-isarray
|
||||
bool Value::is_array(GlobalObject& global_object) const
|
||||
ThrowCompletionOr<bool> Value::is_array(GlobalObject& global_object) const
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
if (!is_object())
|
||||
return false;
|
||||
auto& object = as_object();
|
||||
|
@ -201,11 +203,8 @@ bool Value::is_array(GlobalObject& global_object) const
|
|||
return true;
|
||||
if (is<ProxyObject>(object)) {
|
||||
auto& proxy = static_cast<ProxyObject const&>(object);
|
||||
if (proxy.is_revoked()) {
|
||||
auto& vm = global_object.vm();
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::ProxyRevoked);
|
||||
return false;
|
||||
}
|
||||
if (proxy.is_revoked())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::ProxyRevoked);
|
||||
return Value(&proxy.target()).is_array(global_object);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
bool is_bigint() const { return m_type == Type::BigInt; };
|
||||
bool is_nullish() const { return is_null() || is_undefined(); }
|
||||
bool is_cell() const { return is_string() || is_accessor() || is_object() || is_bigint() || is_symbol(); }
|
||||
bool is_array(GlobalObject&) const;
|
||||
ThrowCompletionOr<bool> is_array(GlobalObject&) const;
|
||||
bool is_function() const;
|
||||
bool is_constructor() const;
|
||||
bool is_regexp(GlobalObject&) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue