diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-09-11 15:52:36 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-12 01:40:56 +0200 |
commit | 966f4faae432b50ccc7081651d23ba461b9fe96b (patch) | |
tree | 51cada768eba52a3e17c22027cf1a20f045388a0 /Userland/Libraries | |
parent | be0880fb2cc49d00f6ff1750fb3327a47286e9bb (diff) | |
download | serenity-966f4faae432b50ccc7081651d23ba461b9fe96b.zip |
LibJS: Convert WeakMap.prototype to be a PrototypeObject
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp | 22 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakMapPrototype.h | 5 |
2 files changed, 8 insertions, 19 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp index 027c1603d4..fe972b95de 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp @@ -11,7 +11,7 @@ namespace JS { WeakMapPrototype::WeakMapPrototype(GlobalObject& global_object) - : Object(*global_object.object_prototype()) + : PrototypeObject(*global_object.object_prototype()) { } @@ -34,22 +34,10 @@ WeakMapPrototype::~WeakMapPrototype() { } -WeakMap* WeakMapPrototype::typed_this(VM& vm, GlobalObject& global_object) -{ - auto* this_object = vm.this_value(global_object).to_object(global_object); - if (!this_object) - return {}; - if (!is<WeakMap>(this_object)) { - vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "WeakMap"); - return nullptr; - } - return static_cast<WeakMap*>(this_object); -} - // 24.3.3.2 WeakMap.prototype.delete ( key ), https://tc39.es/ecma262/#sec-weakmap.prototype.delete JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::delete_) { - auto* weak_map = typed_this(vm, global_object); + auto* weak_map = typed_this_object(global_object); if (!weak_map) return {}; auto value = vm.argument(0); @@ -61,7 +49,7 @@ JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::delete_) // 24.3.3.3 WeakMap.prototype.get ( key ), https://tc39.es/ecma262/#sec-weakmap.prototype.get JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::get) { - auto* weak_map = typed_this(vm, global_object); + auto* weak_map = typed_this_object(global_object); if (!weak_map) return {}; auto value = vm.argument(0); @@ -77,7 +65,7 @@ JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::get) // 24.3.3.4 WeakMap.prototype.has ( key ), https://tc39.es/ecma262/#sec-weakmap.prototype.has JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::has) { - auto* weak_map = typed_this(vm, global_object); + auto* weak_map = typed_this_object(global_object); if (!weak_map) return {}; auto value = vm.argument(0); @@ -90,7 +78,7 @@ JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::has) // 24.3.3.5 WeakMap.prototype.set ( key, value ), https://tc39.es/ecma262/#sec-weakmap.prototype.set JS_DEFINE_NATIVE_FUNCTION(WeakMapPrototype::set) { - auto* weak_map = typed_this(vm, global_object); + auto* weak_map = typed_this_object(global_object); if (!weak_map) return {}; auto value = vm.argument(0); diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.h b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.h index f662f62eb2..86fa77dadf 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.h @@ -6,12 +6,13 @@ #pragma once +#include <LibJS/Runtime/PrototypeObject.h> #include <LibJS/Runtime/WeakMap.h> namespace JS { -class WeakMapPrototype final : public Object { - JS_OBJECT(WeakMapPrototype, Object); +class WeakMapPrototype final : public PrototypeObject<WeakMapPrototype, WeakMap> { + JS_PROTOTYPE_OBJECT(WeakMapPrototype, WeakMap, WeakMap); public: WeakMapPrototype(GlobalObject&); |