mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
LibJS: Convert WeakSetPrototype functions to ThrowCompletionOr
This commit is contained in:
parent
56e14ba09f
commit
909e13c5e6
Notes:
sideshowbarker
2024-07-18 01:46:14 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/909e13c5e61 Pull-request: https://github.com/SerenityOS/serenity/pull/10675 Reviewed-by: https://github.com/linusg ✅
|
@ -21,9 +21,9 @@ void WeakSetPrototype::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.delete_, delete_, 1, attr);
|
||||
define_old_native_function(vm.names.has, has, 1, attr);
|
||||
define_native_function(vm.names.add, add, 1, attr);
|
||||
define_native_function(vm.names.delete_, delete_, 1, attr);
|
||||
define_native_function(vm.names.has, has, 1, attr);
|
||||
|
||||
// 24.4.3.5 WeakSet.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-weakset.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.WeakSet.as_string()), Attribute::Configurable);
|
||||
|
@ -34,22 +34,20 @@ WeakSetPrototype::~WeakSetPrototype()
|
|||
}
|
||||
|
||||
// 24.4.3.1 WeakSet.prototype.add ( value ), https://tc39.es/ecma262/#sec-weakset.prototype.add
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(WeakSetPrototype::add)
|
||||
JS_DEFINE_NATIVE_FUNCTION(WeakSetPrototype::add)
|
||||
{
|
||||
auto* weak_set = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* weak_set = TRY(typed_this_object(global_object));
|
||||
auto value = vm.argument(0);
|
||||
if (!value.is_object()) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, value.to_string_without_side_effects());
|
||||
return {};
|
||||
}
|
||||
if (!value.is_object())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, value.to_string_without_side_effects());
|
||||
weak_set->values().set(&value.as_object(), AK::HashSetExistingEntryBehavior::Keep);
|
||||
return weak_set;
|
||||
}
|
||||
|
||||
// 24.4.3.3 WeakSet.prototype.delete ( value ), https://tc39.es/ecma262/#sec-weakset.prototype.delete
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(WeakSetPrototype::delete_)
|
||||
JS_DEFINE_NATIVE_FUNCTION(WeakSetPrototype::delete_)
|
||||
{
|
||||
auto* weak_set = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* weak_set = TRY(typed_this_object(global_object));
|
||||
auto value = vm.argument(0);
|
||||
if (!value.is_object())
|
||||
return Value(false);
|
||||
|
@ -57,9 +55,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WeakSetPrototype::delete_)
|
|||
}
|
||||
|
||||
// 24.4.3.4 WeakSet.prototype.has ( value ), https://tc39.es/ecma262/#sec-weakset.prototype.has
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(WeakSetPrototype::has)
|
||||
JS_DEFINE_NATIVE_FUNCTION(WeakSetPrototype::has)
|
||||
{
|
||||
auto* weak_set = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* weak_set = TRY(typed_this_object(global_object));
|
||||
auto value = vm.argument(0);
|
||||
if (!value.is_object())
|
||||
return Value(false);
|
||||
|
|
|
@ -20,9 +20,9 @@ public:
|
|||
virtual ~WeakSetPrototype() override;
|
||||
|
||||
private:
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(add);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(delete_);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(has);
|
||||
JS_DECLARE_NATIVE_FUNCTION(add);
|
||||
JS_DECLARE_NATIVE_FUNCTION(delete_);
|
||||
JS_DECLARE_NATIVE_FUNCTION(has);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue