1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:17:34 +00:00

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
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")) { if (attribute.extended_attributes.contains("Unscopable")) {
attribute_generator.append(R"~~~( 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")) { if (function.extended_attributes.contains("Unscopable")) {
function_generator.append(R"~~~( 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); auto element = internalize_json_property(global_object, &value_object, key, reviver);
if (auto* exception = vm.exception()) if (auto* exception = vm.exception())
return throw_completion(exception->value()); return throw_completion(exception->value());
if (element.is_undefined()) { if (element.is_undefined())
TRY(value_object.internal_delete(key)); TRY(value_object.internal_delete(key));
} else { else
value_object.create_data_property(key, element); TRY(value_object.create_data_property(key, element));
if (auto* exception = vm.exception())
return throw_completion(exception->value());
}
return {}; 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 // 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. // 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). // 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 // 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()); VERIFY(property_name.is_valid());
// 3. Let success be ? CreateDataProperty(O, P, V). // 3. Let success be ? CreateDataProperty(O, P, V).
auto success = create_data_property(property_name, value); auto success = TRY_OR_DISCARD(create_data_property(property_name, value));
if (vm.exception())
return {};
// 4. If success is false, throw a TypeError exception. // 4. If success is false, throw a TypeError exception.
if (!success) { 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)); VERIFY(!receiver.as_object().storage_has(property_name));
// ii. Return ? CreateDataProperty(Receiver, P, V). // 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<Value> get(PropertyName const&) const;
ThrowCompletionOr<bool> set(PropertyName const&, Value, ShouldThrowExceptions); 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_method_property(PropertyName const&, Value);
bool create_data_property_or_throw(PropertyName const&, Value); bool create_data_property_or_throw(PropertyName const&, Value);
bool create_non_enumerable_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()) if (match_indices.has_value())
match_indices_array = get_match_indices_array(global_object, string, *match_indices); match_indices_array = get_match_indices_array(global_object, string, *match_indices);
array->create_data_property(i, match_indices_array); TRY_OR_DISCARD(array->create_data_property(i, match_indices_array));
if (vm.exception())
return {};
} }
for (auto const& entry : group_names) { for (auto const& entry : group_names) {
auto match_indices_array = get_match_indices_array(global_object, string, entry.value); auto match_indices_array = get_match_indices_array(global_object, string, entry.value);
groups.as_object().create_data_property(entry.key, match_indices_array); TRY_OR_DISCARD(groups.as_object().create_data_property(entry.key, match_indices_array));
if (vm.exception())
return {};
} }
array->create_data_property(vm.names.groups, groups); TRY_OR_DISCARD(array->create_data_property(vm.names.groups, groups));
if (vm.exception())
return {};
return array; return array;
} }
@ -257,9 +251,7 @@ static Value regexp_builtin_exec(GlobalObject& global_object, RegExpObject& rege
if (has_indices) { if (has_indices) {
auto indices_array = make_indices_array(global_object, string_view, indices, group_names, has_groups); auto indices_array = make_indices_array(global_object, string_view, indices, group_names, has_groups);
array->create_data_property(vm.names.indices, indices_array); TRY_OR_DISCARD(array->create_data_property(vm.names.indices, indices_array));
if (vm.exception())
return {};
} }
array->create_data_property_or_throw(vm.names.index, Value(match_index)); array->create_data_property_or_throw(vm.names.index, Value(match_index));