Skip to content

Commit 364dd42

Browse files
committed
LibJS: Convert create_data_property_or_throw() to ThrowCompletionOr
1 parent bb2499c commit 364dd42

30 files changed

+148
-167
lines changed

Userland/Libraries/LibJS/AST.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,9 +1300,7 @@ ThrowCompletionOr<Value> ClassExpression::class_definition_evaluation(Interprete
13001300
if (initializer)
13011301
field_value = TRY(interpreter.vm().call(*initializer, class_constructor_value));
13021302

1303-
class_constructor->create_data_property_or_throw(property_key, field_value);
1304-
if (auto* exception = interpreter.exception())
1305-
return throw_completion(exception->value());
1303+
TRY(class_constructor->create_data_property_or_throw(property_key, field_value));
13061304
} else {
13071305
class_constructor->add_field(property_key, initializer);
13081306
}

Userland/Libraries/LibJS/Bytecode/Op.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void IteratorToArray::execute_impl(Bytecode::Interpreter& interpreter) const
154154
if (vm.exception())
155155
return;
156156

157-
array->create_data_property_or_throw(index, value);
157+
MUST(array->create_data_property_or_throw(index, value));
158158
index++;
159159
}
160160
}

Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,7 @@ Object* create_unmapped_arguments_object(GlobalObject& global_object, Span<Value
694694
auto value = arguments[index];
695695

696696
// b. Perform ! CreateDataPropertyOrThrow(obj, ! ToString(𝔽(index)), val).
697-
object->create_data_property_or_throw(index, value);
698-
VERIFY(!vm.exception());
697+
MUST(object->create_data_property_or_throw(index, value));
699698

700699
// c. Set index to index + 1.
701700
}
@@ -742,8 +741,7 @@ Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObje
742741
auto value = arguments[index];
743742

744743
// b. Perform ! CreateDataPropertyOrThrow(obj, ! ToString(𝔽(index)), val).
745-
object->create_data_property_or_throw(index, value);
746-
VERIFY(!vm.exception());
744+
MUST(object->create_data_property_or_throw(index, value));
747745

748746
// c. Set index to index + 1.
749747
}

Userland/Libraries/LibJS/Runtime/Array.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ Array* Array::create_from(GlobalObject& global_object, Vector<Value> const& elem
4040
// 4. For each element e of elements, do
4141
for (u32 n = 0; n < elements.size(); ++n) {
4242
// a. Perform ! CreateDataPropertyOrThrow(array, ! ToString(𝔽(n)), e).
43-
array->create_data_property_or_throw(n, elements[n]);
43+
MUST(array->create_data_property_or_throw(n, elements[n]));
44+
4445
// b. Set n to n + 1.
4546
}
4647

Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Value ArrayConstructor::construct(FunctionObject& new_target)
6565
auto* array = Array::create(global_object(), 0, proto);
6666
size_t int_length;
6767
if (!length.is_number()) {
68-
array->create_data_property_or_throw(0, length);
68+
MUST(array->create_data_property_or_throw(0, length));
6969
int_length = 1;
7070
} else {
7171
int_length = length.to_u32(global_object());
@@ -83,7 +83,7 @@ Value ArrayConstructor::construct(FunctionObject& new_target)
8383
return {};
8484

8585
for (size_t k = 0; k < vm.argument_count(); ++k)
86-
array->create_data_property_or_throw(k, vm.argument(k));
86+
MUST(array->create_data_property_or_throw(k, vm.argument(k)));
8787

8888
return array;
8989
}
@@ -155,8 +155,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
155155
mapped_value = next_value;
156156
}
157157

158-
array_object.create_data_property_or_throw(k, mapped_value);
159-
if (vm.exception()) {
158+
auto result_or_error = array_object.create_data_property_or_throw(k, mapped_value);
159+
if (result_or_error.is_error()) {
160160
iterator_close(*iterator);
161161
return {};
162162
}
@@ -191,7 +191,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
191191
mapped_value = TRY_OR_DISCARD(vm.call(*map_fn, this_arg, k_value, Value(k)));
192192
else
193193
mapped_value = k_value;
194-
array_object.create_data_property_or_throw(k, mapped_value);
194+
TRY_OR_DISCARD(array_object.create_data_property_or_throw(k, mapped_value));
195195
}
196196

197197
TRY_OR_DISCARD(array_object.set(vm.names.length, Value(length), Object::ShouldThrowExceptions::Yes));
@@ -223,11 +223,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::of)
223223
return {};
224224
}
225225
auto& array_object = array.as_object();
226-
for (size_t k = 0; k < vm.argument_count(); ++k) {
227-
array_object.create_data_property_or_throw(k, vm.argument(k));
228-
if (vm.exception())
229-
return {};
230-
}
226+
for (size_t k = 0; k < vm.argument_count(); ++k)
227+
TRY_OR_DISCARD(array_object.create_data_property_or_throw(k, vm.argument(k)));
231228
TRY_OR_DISCARD(array_object.set(vm.names.length, Value(vm.argument_count()), Object::ShouldThrowExceptions::Yes));
232229
return array;
233230
}

Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ void ArrayPrototype::initialize(GlobalObject& global_object)
8282
// 23.1.3.34 Array.prototype [ @@unscopables ], https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
8383
// With proposal, https://tc39.es/proposal-array-find-from-last/index.html#sec-array.prototype-@@unscopables
8484
auto* unscopable_list = Object::create(global_object, nullptr);
85-
unscopable_list->create_data_property_or_throw(vm.names.copyWithin, Value(true));
86-
unscopable_list->create_data_property_or_throw(vm.names.entries, Value(true));
87-
unscopable_list->create_data_property_or_throw(vm.names.fill, Value(true));
88-
unscopable_list->create_data_property_or_throw(vm.names.find, Value(true));
89-
unscopable_list->create_data_property_or_throw(vm.names.findIndex, Value(true));
90-
unscopable_list->create_data_property_or_throw(vm.names.findLast, Value(true));
91-
unscopable_list->create_data_property_or_throw(vm.names.findLastIndex, Value(true));
92-
unscopable_list->create_data_property_or_throw(vm.names.flat, Value(true));
93-
unscopable_list->create_data_property_or_throw(vm.names.flatMap, Value(true));
94-
unscopable_list->create_data_property_or_throw(vm.names.includes, Value(true));
95-
unscopable_list->create_data_property_or_throw(vm.names.keys, Value(true));
96-
unscopable_list->create_data_property_or_throw(vm.names.values, Value(true));
85+
MUST(unscopable_list->create_data_property_or_throw(vm.names.copyWithin, Value(true)));
86+
MUST(unscopable_list->create_data_property_or_throw(vm.names.entries, Value(true)));
87+
MUST(unscopable_list->create_data_property_or_throw(vm.names.fill, Value(true)));
88+
MUST(unscopable_list->create_data_property_or_throw(vm.names.find, Value(true)));
89+
MUST(unscopable_list->create_data_property_or_throw(vm.names.findIndex, Value(true)));
90+
MUST(unscopable_list->create_data_property_or_throw(vm.names.findLast, Value(true)));
91+
MUST(unscopable_list->create_data_property_or_throw(vm.names.findLastIndex, Value(true)));
92+
MUST(unscopable_list->create_data_property_or_throw(vm.names.flat, Value(true)));
93+
MUST(unscopable_list->create_data_property_or_throw(vm.names.flatMap, Value(true)));
94+
MUST(unscopable_list->create_data_property_or_throw(vm.names.includes, Value(true)));
95+
MUST(unscopable_list->create_data_property_or_throw(vm.names.keys, Value(true)));
96+
MUST(unscopable_list->create_data_property_or_throw(vm.names.values, Value(true)));
9797

9898
define_direct_property(*vm.well_known_symbol_unscopables(), unscopable_list, Attribute::Configurable);
9999
}
@@ -205,7 +205,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::filter)
205205
// iii. If selected is true, then
206206
if (selected) {
207207
// 1. Perform ? CreateDataPropertyOrThrow(A, ! ToString(𝔽(to)), kValue).
208-
array->create_data_property_or_throw(to, k_value);
208+
TRY_OR_DISCARD(array->create_data_property_or_throw(to, k_value));
209209

210210
// 2. Set to to to + 1.
211211
++to;
@@ -313,9 +313,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::map)
313313
auto mapped_value = TRY_OR_DISCARD(vm.call(callback_function.as_function(), this_arg, k_value, Value(k), object));
314314

315315
// iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue).
316-
array->create_data_property_or_throw(property_name, mapped_value);
317-
if (vm.exception())
318-
return {};
316+
TRY_OR_DISCARD(array->create_data_property_or_throw(property_name, mapped_value));
319317
}
320318

321319
// d. Set k to k + 1.
@@ -581,8 +579,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
581579
if (k_value_or_error.is_error())
582580
return;
583581
auto k_value = k_value_or_error.release_value();
584-
new_array->create_data_property_or_throw(n, k_value);
585-
if (vm.exception())
582+
auto result_or_error = new_array->create_data_property_or_throw(n, k_value);
583+
if (result_or_error.is_error())
586584
return;
587585
}
588586
++n;
@@ -593,8 +591,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
593591
vm.throw_exception<TypeError>(global_object, ErrorType::ArrayMaxSize);
594592
return;
595593
}
596-
new_array->create_data_property_or_throw(n, arg);
597-
if (vm.exception())
594+
auto result_or_error = new_array->create_data_property_or_throw(n, arg);
595+
if (result_or_error.is_error())
598596
return;
599597
++n;
600598
}
@@ -672,9 +670,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice)
672670

673671
if (present) {
674672
auto value = TRY_OR_DISCARD(this_object->get(k));
675-
new_array->create_data_property_or_throw(index, value);
676-
if (vm.exception())
677-
return {};
673+
TRY_OR_DISCARD(new_array->create_data_property_or_throw(index, value));
678674
}
679675

680676
++k;
@@ -1594,9 +1590,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice)
15941590
if (from_present) {
15951591
auto from_value = TRY_OR_DISCARD(this_object->get(from));
15961592

1597-
removed_elements->create_data_property_or_throw(i, from_value);
1598-
if (vm.exception())
1599-
return {};
1593+
TRY_OR_DISCARD(removed_elements->create_data_property_or_throw(i, from_value));
16001594
}
16011595
}
16021596

@@ -1767,9 +1761,7 @@ static size_t flatten_into_array(GlobalObject& global_object, Object& new_array,
17671761
return {};
17681762
}
17691763

1770-
new_array.create_data_property_or_throw(target_index, value);
1771-
if (vm.exception())
1772-
return {};
1764+
TRY_OR_DISCARD(new_array.create_data_property_or_throw(target_index, value));
17731765

17741766
++target_index;
17751767
}

Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ void ECMAScriptFunctionObject::InstanceField::define_field(VM& vm, Object& recei
442442
return;
443443
init_value = init_value_or_error.release_value();
444444
}
445-
receiver.create_data_property_or_throw(name, init_value);
445+
(void)receiver.create_data_property_or_throw(name, init_value);
446446
}
447447

448448
}

Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
101101
// b. Let v be the value of displayNames's internal slot whose name is the Internal Slot value of the current row.
102102
// c. Assert: v is not undefined.
103103
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
104-
options->create_data_property_or_throw(vm.names.locale, js_string(vm, display_names->locale()));
105-
options->create_data_property_or_throw(vm.names.style, js_string(vm, display_names->style_string()));
106-
options->create_data_property_or_throw(vm.names.type, js_string(vm, display_names->type_string()));
107-
options->create_data_property_or_throw(vm.names.fallback, js_string(vm, display_names->fallback_string()));
104+
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, display_names->locale())));
105+
MUST(options->create_data_property_or_throw(vm.names.style, js_string(vm, display_names->style_string())));
106+
MUST(options->create_data_property_or_throw(vm.names.type, js_string(vm, display_names->type_string())));
107+
MUST(options->create_data_property_or_throw(vm.names.fallback, js_string(vm, display_names->fallback_string())));
108108

109109
// 5. Return options.
110110
return options;

Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_
248248
auto* object = Object::create(global_object, global_object.object_prototype());
249249

250250
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
251-
object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type));
251+
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
252252

253253
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
254-
object->create_data_property_or_throw(vm.names.value, js_string(vm, part.value));
254+
MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, part.value)));
255255

256256
// d. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O).
257-
result->create_data_property_or_throw(n, object);
257+
MUST(result->create_data_property_or_throw(n, object));
258258

259259
// e. Increment n by 1.
260260
++n;

Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
8787
// b. Let v be the value of lf's internal slot whose name is the Internal Slot value of the current row.
8888
// c. Assert: v is not undefined.
8989
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
90-
options->create_data_property_or_throw(vm.names.locale, js_string(vm, list_format->locale()));
91-
options->create_data_property_or_throw(vm.names.type, js_string(vm, list_format->type_string()));
92-
options->create_data_property_or_throw(vm.names.style, js_string(vm, list_format->style_string()));
90+
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, list_format->locale())));
91+
MUST(options->create_data_property_or_throw(vm.names.type, js_string(vm, list_format->type_string())));
92+
MUST(options->create_data_property_or_throw(vm.names.style, js_string(vm, list_format->style_string())));
9393

9494
// 5. Return options.
9595
return options;

0 commit comments

Comments
 (0)