mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-27 01:50:24 +00:00
LibJS: Convert WeakMapPrototype functions to ThrowCompletionOr
This commit is contained in:
parent
f1e215ea3e
commit
56e14ba09f
Notes:
sideshowbarker
2024-07-18 01:46:17 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/56e14ba09f8 Pull-request: https://github.com/SerenityOS/serenity/pull/10675 Reviewed-by: https://github.com/linusg ✅
2 changed files with 18 additions and 20 deletions
|
@ -21,10 +21,10 @@ void WeakMapPrototype::initialize(GlobalObject& global_object)
|
|||
Object::initialize(global_object);
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
|
||||
define_old_native_function(vm.names.delete_, delete_, 1, attr);
|
||||
define_old_native_function(vm.names.get, get, 1, attr);
|
||||
define_old_native_function(vm.names.has, has, 1, attr);
|
||||
define_old_native_function(vm.names.set, set, 2, attr);
|
||||
define_native_function(vm.names.delete_, delete_, 1, attr);
|
||||
define_native_function(vm.names.get, get, 1, attr);
|
||||
define_native_function(vm.names.has, has, 1, attr);
|
||||
define_native_function(vm.names.set, set, 2, attr);
|
||||
|
||||
// 24.3.3.6 WeakMap.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-weakmap.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.WeakMap.as_string()), Attribute::Configurable);
|
||||
|
@ -35,9 +35,9 @@ WeakMapPrototype::~WeakMapPrototype()
|
|||
}
|
||||
|
||||
// 24.3.3.2 WeakMap.prototype.delete ( key ), https://tc39.es/ecma262/#sec-weakmap.prototype.delete
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(WeakMapPrototype::delete_)
|
||||
JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::delete_)
|
||||
{
|
||||
auto* weak_map = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* weak_map = TRY(typed_this_object(global_object));
|
||||
auto value = vm.argument(0);
|
||||
if (!value.is_object())
|
||||
return Value(false);
|
||||
|
@ -45,9 +45,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WeakMapPrototype::delete_)
|
|||
}
|
||||
|
||||
// 24.3.3.3 WeakMap.prototype.get ( key ), https://tc39.es/ecma262/#sec-weakmap.prototype.get
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(WeakMapPrototype::get)
|
||||
JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::get)
|
||||
{
|
||||
auto* weak_map = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* weak_map = TRY(typed_this_object(global_object));
|
||||
auto value = vm.argument(0);
|
||||
if (!value.is_object())
|
||||
return js_undefined();
|
||||
|
@ -59,9 +59,9 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WeakMapPrototype::get)
|
|||
}
|
||||
|
||||
// 24.3.3.4 WeakMap.prototype.has ( key ), https://tc39.es/ecma262/#sec-weakmap.prototype.has
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(WeakMapPrototype::has)
|
||||
JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::has)
|
||||
{
|
||||
auto* weak_map = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* weak_map = TRY(typed_this_object(global_object));
|
||||
auto value = vm.argument(0);
|
||||
if (!value.is_object())
|
||||
return Value(false);
|
||||
|
@ -70,14 +70,12 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(WeakMapPrototype::has)
|
|||
}
|
||||
|
||||
// 24.3.3.5 WeakMap.prototype.set ( key, value ), https://tc39.es/ecma262/#sec-weakmap.prototype.set
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(WeakMapPrototype::set)
|
||||
JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::set)
|
||||
{
|
||||
auto* weak_map = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* weak_map = 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_map->values().set(&value.as_object(), vm.argument(1));
|
||||
return weak_map;
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ public:
|
|||
virtual ~WeakMapPrototype() override;
|
||||
|
||||
private:
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(delete_);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(has);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set);
|
||||
JS_DECLARE_NATIVE_FUNCTION(delete_);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get);
|
||||
JS_DECLARE_NATIVE_FUNCTION(has);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue