summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-10-03 00:53:06 +0100
committerLinus Groh <mail@linusgroh.de>2021-10-03 20:14:03 +0100
commitfb443b3fb45d26d5275600a3eda7f4ea4abb82da (patch)
treee6fdbf62795c0e0d5965f2900f119119ca37128d /Userland
parent1d45541278abc95f3ef996b5629a3a0cc9cf8461 (diff)
downloadserenity-fb443b3fb45d26d5275600a3eda7f4ea4abb82da.zip
LibJS: Convert create_data_property() to ThrowCompletionOr
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/JSONObject.cpp9
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Object.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp16
4 files changed, 12 insertions, 25 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
index 41e26403b6..7473125bdc 100644
--- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
@@ -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 {};
};
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp
index f269026aec..3b95ee4104 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Object.cpp
@@ -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));
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h
index 345eafefc4..68a4df79a5 100644
--- a/Userland/Libraries/LibJS/Runtime/Object.h
+++ b/Userland/Libraries/LibJS/Runtime/Object.h
@@ -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);
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
index fe4aaae8db..9e774befc3 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
@@ -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));