summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-10-23 03:25:05 +0300
committerAndreas Kling <kling@serenityos.org>2021-10-23 18:01:51 +0200
commitf7bafea661d18810044a388828036d678f89e9c9 (patch)
treebb01629126a206461054b130feea3255d7713e4e /Userland/Libraries/LibJS/Runtime
parent92b25cacd1a8bbde940eafbb04d2e84b3fe1d868 (diff)
downloadserenity-f7bafea661d18810044a388828036d678f89e9c9.zip
LibJS: Convert TypedArrayConstructor functions to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp60
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.h6
2 files changed, 29 insertions, 37 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp
index c6ff2e4e19..a9bb31d626 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp
@@ -30,10 +30,10 @@ void TypedArrayConstructor::initialize(GlobalObject& global_object)
define_direct_property(vm.names.prototype, global_object.typed_array_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
- define_old_native_function(vm.names.from, from, 1, attr);
- define_old_native_function(vm.names.of, of, 0, attr);
+ define_native_function(vm.names.from, from, 1, attr);
+ define_native_function(vm.names.of, of, 0, attr);
- define_old_native_accessor(*vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable);
+ define_native_accessor(*vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable);
define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
}
@@ -55,92 +55,84 @@ ThrowCompletionOr<Object*> TypedArrayConstructor::construct(FunctionObject&)
}
// 23.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ), https://tc39.es/ecma262/#sec-%typedarray%.from
-JS_DEFINE_OLD_NATIVE_FUNCTION(TypedArrayConstructor::from)
+JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::from)
{
auto constructor = vm.this_value(global_object);
- if (!constructor.is_constructor()) {
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
- return {};
- }
+ if (!constructor.is_constructor())
+ return vm.throw_completion<TypeError>(global_object, ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
FunctionObject* map_fn = nullptr;
if (!vm.argument(1).is_undefined()) {
auto callback = vm.argument(1);
- if (!callback.is_function()) {
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, callback.to_string_without_side_effects());
- return {};
- }
+ if (!callback.is_function())
+ return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, callback.to_string_without_side_effects());
map_fn = &callback.as_function();
}
auto source = vm.argument(0);
auto this_arg = vm.argument(2);
- auto using_iterator = TRY_OR_DISCARD(source.get_method(global_object, *vm.well_known_symbol_iterator()));
+ auto using_iterator = TRY(source.get_method(global_object, *vm.well_known_symbol_iterator()));
if (using_iterator) {
- auto values = TRY_OR_DISCARD(iterable_to_list(global_object, source, using_iterator));
+ auto values = TRY(iterable_to_list(global_object, source, using_iterator));
MarkedValueList arguments(vm.heap());
arguments.empend(values.size());
- auto target_object = TRY_OR_DISCARD(typed_array_create(global_object, constructor.as_function(), move(arguments)));
+ auto target_object = TRY(typed_array_create(global_object, constructor.as_function(), move(arguments)));
for (size_t k = 0; k < values.size(); ++k) {
auto k_value = values[k];
Value mapped_value;
if (map_fn)
- mapped_value = TRY_OR_DISCARD(vm.call(*map_fn, this_arg, k_value, Value(k)));
+ mapped_value = TRY(vm.call(*map_fn, this_arg, k_value, Value(k)));
else
mapped_value = k_value;
- TRY_OR_DISCARD(target_object->set(k, mapped_value, Object::ShouldThrowExceptions::Yes));
+ TRY(target_object->set(k, mapped_value, Object::ShouldThrowExceptions::Yes));
}
return target_object;
}
auto array_like = MUST(source.to_object(global_object));
- auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *array_like));
+ auto length = TRY(length_of_array_like(global_object, *array_like));
MarkedValueList arguments(vm.heap());
arguments.empend(length);
- auto target_object = TRY_OR_DISCARD(typed_array_create(global_object, constructor.as_function(), move(arguments)));
+ auto target_object = TRY(typed_array_create(global_object, constructor.as_function(), move(arguments)));
for (size_t k = 0; k < length; ++k) {
- auto k_value = TRY_OR_DISCARD(array_like->get(k));
+ auto k_value = TRY(array_like->get(k));
Value mapped_value;
if (map_fn)
- mapped_value = TRY_OR_DISCARD(vm.call(*map_fn, this_arg, k_value, Value(k)));
+ mapped_value = TRY(vm.call(*map_fn, this_arg, k_value, Value(k)));
else
mapped_value = k_value;
- TRY_OR_DISCARD(target_object->set(k, mapped_value, Object::ShouldThrowExceptions::Yes));
+ TRY(target_object->set(k, mapped_value, Object::ShouldThrowExceptions::Yes));
}
return target_object;
}
// 23.2.2.2 %TypedArray%.of ( ...items ), https://tc39.es/ecma262/#sec-%typedarray%.of
-JS_DEFINE_OLD_NATIVE_FUNCTION(TypedArrayConstructor::of)
+JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::of)
{
auto length = vm.argument_count();
auto constructor = vm.this_value(global_object);
- if (!constructor.is_constructor()) {
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
- return {};
- }
+ if (!constructor.is_constructor())
+ return vm.throw_completion<TypeError>(global_object, ErrorType::NotAConstructor, constructor.to_string_without_side_effects());
MarkedValueList arguments(vm.heap());
arguments.append(Value(length));
- auto new_object = TRY_OR_DISCARD(typed_array_create(global_object, constructor.as_function(), move(arguments)));
+ auto new_object = TRY(typed_array_create(global_object, constructor.as_function(), move(arguments)));
for (size_t k = 0; k < length; ++k) {
- auto success = TRY_OR_DISCARD(new_object->set(k, vm.argument(k), Object::ShouldThrowExceptions::Yes));
- if (!success) {
- vm.throw_exception<TypeError>(global_object, ErrorType::TypedArrayFailedSettingIndex, k);
- return {};
- }
+ auto success = TRY(new_object->set(k, vm.argument(k), Object::ShouldThrowExceptions::Yes));
+ if (!success)
+ return vm.throw_completion<TypeError>(global_object, ErrorType::TypedArrayFailedSettingIndex, k);
}
return new_object;
}
// 23.2.2.4 get %TypedArray% [ @@species ], https://tc39.es/ecma262/#sec-get-%typedarray%-@@species
-JS_DEFINE_OLD_NATIVE_FUNCTION(TypedArrayConstructor::symbol_species_getter)
+JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::symbol_species_getter)
{
return vm.this_value(global_object);
}
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.h b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.h
index 2cc6582b9b..b2138182ea 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.h
+++ b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.h
@@ -25,9 +25,9 @@ public:
private:
virtual bool has_constructor() const override { return true; }
- JS_DECLARE_OLD_NATIVE_FUNCTION(from);
- JS_DECLARE_OLD_NATIVE_FUNCTION(of);
- JS_DECLARE_OLD_NATIVE_FUNCTION(symbol_species_getter);
+ JS_DECLARE_NATIVE_FUNCTION(from);
+ JS_DECLARE_NATIVE_FUNCTION(of);
+ JS_DECLARE_NATIVE_FUNCTION(symbol_species_getter);
};
}