diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-09-11 15:54:18 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-12 01:40:56 +0200 |
commit | 777ae53615e4ed77980c3ad792a0602d24719bd3 (patch) | |
tree | aec0c9d469675a873b24a02a53ac4415566b7b78 /Userland/Libraries | |
parent | 966f4faae432b50ccc7081651d23ba461b9fe96b (diff) | |
download | serenity-777ae53615e4ed77980c3ad792a0602d24719bd3.zip |
LibJS: Convert WeakRef.prototype to be a PrototypeObject
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/WeakRefPrototype.h | 5 |
2 files changed, 9 insertions, 12 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp index 120855fdcf..16036814f1 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp @@ -10,7 +10,7 @@ namespace JS { WeakRefPrototype::WeakRefPrototype(GlobalObject& global_object) - : Object(*global_object.object_prototype()) + : PrototypeObject(*global_object.object_prototype()) { } @@ -31,16 +31,12 @@ WeakRefPrototype::~WeakRefPrototype() // 26.1.3.2 WeakRef.prototype.deref ( ), https://tc39.es/ecma262/#sec-weak-ref.prototype.deref JS_DEFINE_NATIVE_FUNCTION(WeakRefPrototype::deref) { - auto* this_object = vm.this_value(global_object).to_object(global_object); - if (!this_object) + auto* weak_ref = typed_this_object(global_object); + if (vm.exception()) return {}; - if (!is<WeakRef>(this_object)) { - vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "WeakRef"); - return {}; - } - auto& weak_ref = static_cast<WeakRef&>(*this_object); - weak_ref.update_execution_generation(); - return weak_ref.value() ?: js_undefined(); + + weak_ref->update_execution_generation(); + return weak_ref->value() ?: js_undefined(); } } diff --git a/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.h b/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.h index 9d7cddb97f..15254e946c 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.h @@ -6,12 +6,13 @@ #pragma once +#include <LibJS/Runtime/PrototypeObject.h> #include <LibJS/Runtime/WeakRef.h> namespace JS { -class WeakRefPrototype final : public Object { - JS_OBJECT(WeakRefPrototype, Object); +class WeakRefPrototype final : public PrototypeObject<WeakRefPrototype, WeakRef> { + JS_PROTOTYPE_OBJECT(WeakRefPrototype, WeakRef, WeakRef); public: WeakRefPrototype(GlobalObject&); |