diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-29 01:02:29 +0300 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-29 21:29:24 +0300 |
commit | 56e14ba09f8647e1e5339c8c523080d0fa8a0766 (patch) | |
tree | 76315dd97fac25683fd9bd4eb4372973469617bf /Userland | |
parent | f1e215ea3ec89f6b429acc8bde1acb825e8ae401 (diff) | |
download | serenity-56e14ba09f8647e1e5339c8c523080d0fa8a0766.zip |
LibJS: Convert WeakMapPrototype functions to ThrowCompletionOr
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp | 30 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakMapPrototype.h | 8 |
2 files changed, 18 insertions, 20 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp index 69be97880a..957d8ce81f 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp @@ -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; } diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.h b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.h index 0e2afbafa7..5adcc838bd 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.h @@ -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); }; } |