mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:07:45 +00:00
LibJS: Convert WeakMapPrototype functions to ThrowCompletionOr
This commit is contained in:
parent
f1e215ea3e
commit
56e14ba09f
2 changed files with 18 additions and 20 deletions
|
@ -21,10 +21,10 @@ void WeakMapPrototype::initialize(GlobalObject& global_object)
|
||||||
Object::initialize(global_object);
|
Object::initialize(global_object);
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||||
|
|
||||||
define_old_native_function(vm.names.delete_, delete_, 1, attr);
|
define_native_function(vm.names.delete_, delete_, 1, attr);
|
||||||
define_old_native_function(vm.names.get, get, 1, attr);
|
define_native_function(vm.names.get, get, 1, attr);
|
||||||
define_old_native_function(vm.names.has, has, 1, attr);
|
define_native_function(vm.names.has, has, 1, attr);
|
||||||
define_old_native_function(vm.names.set, set, 2, 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
|
// 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);
|
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
|
// 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);
|
auto value = vm.argument(0);
|
||||||
if (!value.is_object())
|
if (!value.is_object())
|
||||||
return Value(false);
|
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
|
// 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);
|
auto value = vm.argument(0);
|
||||||
if (!value.is_object())
|
if (!value.is_object())
|
||||||
return js_undefined();
|
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
|
// 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);
|
auto value = vm.argument(0);
|
||||||
if (!value.is_object())
|
if (!value.is_object())
|
||||||
return Value(false);
|
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
|
// 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);
|
auto value = vm.argument(0);
|
||||||
if (!value.is_object()) {
|
if (!value.is_object())
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, value.to_string_without_side_effects());
|
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, value.to_string_without_side_effects());
|
||||||
return {};
|
|
||||||
}
|
|
||||||
weak_map->values().set(&value.as_object(), vm.argument(1));
|
weak_map->values().set(&value.as_object(), vm.argument(1));
|
||||||
return weak_map;
|
return weak_map;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,10 @@ public:
|
||||||
virtual ~WeakMapPrototype() override;
|
virtual ~WeakMapPrototype() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS_DECLARE_OLD_NATIVE_FUNCTION(delete_);
|
JS_DECLARE_NATIVE_FUNCTION(delete_);
|
||||||
JS_DECLARE_OLD_NATIVE_FUNCTION(get);
|
JS_DECLARE_NATIVE_FUNCTION(get);
|
||||||
JS_DECLARE_OLD_NATIVE_FUNCTION(has);
|
JS_DECLARE_NATIVE_FUNCTION(has);
|
||||||
JS_DECLARE_OLD_NATIVE_FUNCTION(set);
|
JS_DECLARE_NATIVE_FUNCTION(set);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue