summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-10-29 00:19:11 +0300
committerIdan Horowitz <idan.horowitz@gmail.com>2021-10-29 21:29:24 +0300
commitd46d8c9016f2cc60155f318da2412aa815f3dfd4 (patch)
tree156bf2bf29c79cffff584e00084336febee888a3 /Userland
parentc2e0753d8a8a956438d5a22a3898589aacc0b8df (diff)
downloadserenity-d46d8c9016f2cc60155f318da2412aa815f3dfd4.zip
LibJS: Convert SetPrototype functions to ThrowCompletionOr
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetPrototype.cpp61
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetPrototype.h18
2 files changed, 37 insertions, 42 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
index 3dd6e3e13f..fdda3b25e9 100644
--- a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
@@ -22,14 +22,14 @@ void SetPrototype::initialize(GlobalObject& global_object)
Object::initialize(global_object);
u8 attr = Attribute::Writable | Attribute::Configurable;
- define_old_native_function(vm.names.add, add, 1, attr);
- define_old_native_function(vm.names.clear, clear, 0, attr);
- define_old_native_function(vm.names.delete_, delete_, 1, attr);
- define_old_native_function(vm.names.entries, entries, 0, attr);
- define_old_native_function(vm.names.forEach, for_each, 1, attr);
- define_old_native_function(vm.names.has, has, 1, attr);
- define_old_native_function(vm.names.values, values, 0, attr);
- define_old_native_accessor(vm.names.size, size_getter, {}, Attribute::Configurable);
+ define_native_function(vm.names.add, add, 1, attr);
+ define_native_function(vm.names.clear, clear, 0, attr);
+ define_native_function(vm.names.delete_, delete_, 1, attr);
+ define_native_function(vm.names.entries, entries, 0, attr);
+ define_native_function(vm.names.forEach, for_each, 1, attr);
+ define_native_function(vm.names.has, has, 1, attr);
+ define_native_function(vm.names.values, values, 0, attr);
+ define_native_accessor(vm.names.size, size_getter, {}, Attribute::Configurable);
define_direct_property(vm.names.keys, get_without_side_effects(vm.names.values), attr);
@@ -45,9 +45,9 @@ SetPrototype::~SetPrototype()
}
// 24.2.3.1 Set.prototype.add ( value ), https://tc39.es/ecma262/#sec-set.prototype.add
-JS_DEFINE_OLD_NATIVE_FUNCTION(SetPrototype::add)
+JS_DEFINE_NATIVE_FUNCTION(SetPrototype::add)
{
- auto* set = TRY_OR_DISCARD(typed_this_object(global_object));
+ auto* set = TRY(typed_this_object(global_object));
auto value = vm.argument(0);
if (value.is_negative_zero())
value = Value(0);
@@ -56,65 +56,60 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(SetPrototype::add)
}
// 24.2.3.2 Set.prototype.clear ( ), https://tc39.es/ecma262/#sec-set.prototype.clear
-JS_DEFINE_OLD_NATIVE_FUNCTION(SetPrototype::clear)
+JS_DEFINE_NATIVE_FUNCTION(SetPrototype::clear)
{
- auto* set = TRY_OR_DISCARD(typed_this_object(global_object));
+ auto* set = TRY(typed_this_object(global_object));
set->values().clear();
return js_undefined();
}
// 24.2.3.4 Set.prototype.delete ( value ), https://tc39.es/ecma262/#sec-set.prototype.delete
-JS_DEFINE_OLD_NATIVE_FUNCTION(SetPrototype::delete_)
+JS_DEFINE_NATIVE_FUNCTION(SetPrototype::delete_)
{
- auto* set = TRY_OR_DISCARD(typed_this_object(global_object));
+ auto* set = TRY(typed_this_object(global_object));
return Value(set->values().remove(vm.argument(0)));
}
// 24.2.3.5 Set.prototype.entries ( ), https://tc39.es/ecma262/#sec-set.prototype.entries
-JS_DEFINE_OLD_NATIVE_FUNCTION(SetPrototype::entries)
+JS_DEFINE_NATIVE_FUNCTION(SetPrototype::entries)
{
- auto* set = TRY_OR_DISCARD(typed_this_object(global_object));
+ auto* set = TRY(typed_this_object(global_object));
return SetIterator::create(global_object, *set, Object::PropertyKind::KeyAndValue);
}
// 24.2.3.6 Set.prototype.forEach ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-set.prototype.foreach
-JS_DEFINE_OLD_NATIVE_FUNCTION(SetPrototype::for_each)
+JS_DEFINE_NATIVE_FUNCTION(SetPrototype::for_each)
{
- auto* set = TRY_OR_DISCARD(typed_this_object(global_object));
- if (!vm.argument(0).is_function()) {
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, vm.argument(0).to_string_without_side_effects());
- return {};
- }
+ auto* set = TRY(typed_this_object(global_object));
+ if (!vm.argument(0).is_function())
+ return vm.throw_completion<TypeError>(global_object, ErrorType::NotAFunction, vm.argument(0).to_string_without_side_effects());
auto this_value = vm.this_value(global_object);
- for (auto& value : set->values()) {
- (void)vm.call(vm.argument(0).as_function(), vm.argument(1), value, value, this_value);
- if (vm.exception())
- return {};
- }
+ for (auto& value : set->values())
+ TRY(vm.call(vm.argument(0).as_function(), vm.argument(1), value, value, this_value));
return js_undefined();
}
// 24.2.3.7 Set.prototype.has ( value ), https://tc39.es/ecma262/#sec-set.prototype.has
-JS_DEFINE_OLD_NATIVE_FUNCTION(SetPrototype::has)
+JS_DEFINE_NATIVE_FUNCTION(SetPrototype::has)
{
- auto* set = TRY_OR_DISCARD(typed_this_object(global_object));
+ auto* set = TRY(typed_this_object(global_object));
auto& values = set->values();
return Value(values.find(vm.argument(0)) != values.end());
}
// 24.2.3.10 Set.prototype.values ( ), https://tc39.es/ecma262/#sec-set.prototype.values
-JS_DEFINE_OLD_NATIVE_FUNCTION(SetPrototype::values)
+JS_DEFINE_NATIVE_FUNCTION(SetPrototype::values)
{
- auto* set = TRY_OR_DISCARD(typed_this_object(global_object));
+ auto* set = TRY(typed_this_object(global_object));
return SetIterator::create(global_object, *set, Object::PropertyKind::Value);
}
// 24.2.3.9 get Set.prototype.size, https://tc39.es/ecma262/#sec-get-set.prototype.size
-JS_DEFINE_OLD_NATIVE_FUNCTION(SetPrototype::size_getter)
+JS_DEFINE_NATIVE_FUNCTION(SetPrototype::size_getter)
{
- auto* set = TRY_OR_DISCARD(typed_this_object(global_object));
+ auto* set = TRY(typed_this_object(global_object));
return Value(set->values().size());
}
diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.h b/Userland/Libraries/LibJS/Runtime/SetPrototype.h
index c6c5929d51..cefa2b7767 100644
--- a/Userland/Libraries/LibJS/Runtime/SetPrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.h
@@ -20,15 +20,15 @@ public:
virtual ~SetPrototype() override;
private:
- JS_DECLARE_OLD_NATIVE_FUNCTION(add);
- JS_DECLARE_OLD_NATIVE_FUNCTION(clear);
- JS_DECLARE_OLD_NATIVE_FUNCTION(delete_);
- JS_DECLARE_OLD_NATIVE_FUNCTION(entries);
- JS_DECLARE_OLD_NATIVE_FUNCTION(for_each);
- JS_DECLARE_OLD_NATIVE_FUNCTION(has);
- JS_DECLARE_OLD_NATIVE_FUNCTION(values);
-
- JS_DECLARE_OLD_NATIVE_FUNCTION(size_getter);
+ JS_DECLARE_NATIVE_FUNCTION(add);
+ JS_DECLARE_NATIVE_FUNCTION(clear);
+ JS_DECLARE_NATIVE_FUNCTION(delete_);
+ JS_DECLARE_NATIVE_FUNCTION(entries);
+ JS_DECLARE_NATIVE_FUNCTION(for_each);
+ JS_DECLARE_NATIVE_FUNCTION(has);
+ JS_DECLARE_NATIVE_FUNCTION(values);
+
+ JS_DECLARE_NATIVE_FUNCTION(size_getter);
};
}