LibJS: Convert create_data_property() to ThrowCompletionOr

This commit is contained in:
Linus Groh 2021-10-03 00:53:06 +01:00
parent 1d45541278
commit fb443b3fb4
Notes: sideshowbarker 2024-07-18 03:07:33 +09:00
5 changed files with 14 additions and 27 deletions

View file

@ -2880,7 +2880,7 @@ void @prototype_class@::initialize(JS::GlobalObject& global_object)
if (attribute.extended_attributes.contains("Unscopable")) {
attribute_generator.append(R"~~~(
unscopable_object->create_data_property("@attribute.name@", JS::Value(true));
MUST(unscopable_object->create_data_property("@attribute.name@", JS::Value(true)));
)~~~");
}
@ -2911,7 +2911,7 @@ void @prototype_class@::initialize(JS::GlobalObject& global_object)
if (function.extended_attributes.contains("Unscopable")) {
function_generator.append(R"~~~(
unscopable_object->create_data_property("@function.name@", JS::Value(true));
MUST(unscopable_object->create_data_property("@function.name@", JS::Value(true)));
)~~~");
}

View file

@ -468,13 +468,10 @@ Value JSONObject::internalize_json_property(GlobalObject& global_object, Object*
auto element = internalize_json_property(global_object, &value_object, key, reviver);
if (auto* exception = vm.exception())
return throw_completion(exception->value());
if (element.is_undefined()) {
if (element.is_undefined())
TRY(value_object.internal_delete(key));
} else {
value_object.create_data_property(key, element);
if (auto* exception = vm.exception())
return throw_completion(exception->value());
}
else
TRY(value_object.create_data_property(key, element));
return {};
};

View file

@ -117,7 +117,7 @@ ThrowCompletionOr<bool> Object::set(PropertyName const& property_name, Value val
}
// 7.3.5 CreateDataProperty ( O, P, V ), https://tc39.es/ecma262/#sec-createdataproperty
bool Object::create_data_property(PropertyName const& property_name, Value value)
ThrowCompletionOr<bool> Object::create_data_property(PropertyName const& property_name, Value value)
{
// 1. Assert: Type(O) is Object.
@ -133,7 +133,7 @@ bool Object::create_data_property(PropertyName const& property_name, Value value
};
// 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
return TRY_OR_DISCARD(internal_define_own_property(property_name, new_descriptor));
return internal_define_own_property(property_name, new_descriptor);
}
// 7.3.6 CreateMethodProperty ( O, P, V ), https://tc39.es/ecma262/#sec-createmethodproperty
@ -170,9 +170,7 @@ bool Object::create_data_property_or_throw(PropertyName const& property_name, Va
VERIFY(property_name.is_valid());
// 3. Let success be ? CreateDataProperty(O, P, V).
auto success = create_data_property(property_name, value);
if (vm.exception())
return {};
auto success = TRY_OR_DISCARD(create_data_property(property_name, value));
// 4. If success is false, throw a TypeError exception.
if (!success) {
@ -779,7 +777,7 @@ bool Object::ordinary_set_with_own_descriptor(PropertyName const& property_name,
VERIFY(!receiver.as_object().storage_has(property_name));
// ii. Return ? CreateDataProperty(Receiver, P, V).
return receiver.as_object().create_data_property(property_name, value);
return TRY_OR_DISCARD(receiver.as_object().create_data_property(property_name, value));
}
}

View file

@ -77,7 +77,7 @@ public:
ThrowCompletionOr<Value> get(PropertyName const&) const;
ThrowCompletionOr<bool> set(PropertyName const&, Value, ShouldThrowExceptions);
bool create_data_property(PropertyName const&, Value);
ThrowCompletionOr<bool> create_data_property(PropertyName const&, Value);
bool create_method_property(PropertyName const&, Value);
bool create_data_property_or_throw(PropertyName const&, Value);
bool create_non_enumerable_data_property_or_throw(PropertyName const&, Value);

View file

@ -144,22 +144,16 @@ static Value make_indices_array(GlobalObject& global_object, Utf16View const& st
if (match_indices.has_value())
match_indices_array = get_match_indices_array(global_object, string, *match_indices);
array->create_data_property(i, match_indices_array);
if (vm.exception())
return {};
TRY_OR_DISCARD(array->create_data_property(i, match_indices_array));
}
for (auto const& entry : group_names) {
auto match_indices_array = get_match_indices_array(global_object, string, entry.value);
groups.as_object().create_data_property(entry.key, match_indices_array);
if (vm.exception())
return {};
TRY_OR_DISCARD(groups.as_object().create_data_property(entry.key, match_indices_array));
}
array->create_data_property(vm.names.groups, groups);
if (vm.exception())
return {};
TRY_OR_DISCARD(array->create_data_property(vm.names.groups, groups));
return array;
}
@ -257,9 +251,7 @@ static Value regexp_builtin_exec(GlobalObject& global_object, RegExpObject& rege
if (has_indices) {
auto indices_array = make_indices_array(global_object, string_view, indices, group_names, has_groups);
array->create_data_property(vm.names.indices, indices_array);
if (vm.exception())
return {};
TRY_OR_DISCARD(array->create_data_property(vm.names.indices, indices_array));
}
array->create_data_property_or_throw(vm.names.index, Value(match_index));