1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:57:35 +00:00

LibJS: Convert WeakRef.prototype to be a PrototypeObject

This commit is contained in:
Timothy Flynn 2021-09-11 15:54:18 -04:00 committed by Andreas Kling
parent 966f4faae4
commit 777ae53615
2 changed files with 9 additions and 12 deletions

View file

@ -10,7 +10,7 @@
namespace JS { namespace JS {
WeakRefPrototype::WeakRefPrototype(GlobalObject& global_object) 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 // 26.1.3.2 WeakRef.prototype.deref ( ), https://tc39.es/ecma262/#sec-weak-ref.prototype.deref
JS_DEFINE_NATIVE_FUNCTION(WeakRefPrototype::deref) JS_DEFINE_NATIVE_FUNCTION(WeakRefPrototype::deref)
{ {
auto* this_object = vm.this_value(global_object).to_object(global_object); auto* weak_ref = typed_this_object(global_object);
if (!this_object) if (vm.exception())
return {}; return {};
if (!is<WeakRef>(this_object)) {
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "WeakRef"); weak_ref->update_execution_generation();
return {}; return weak_ref->value() ?: js_undefined();
}
auto& weak_ref = static_cast<WeakRef&>(*this_object);
weak_ref.update_execution_generation();
return weak_ref.value() ?: js_undefined();
} }
} }

View file

@ -6,12 +6,13 @@
#pragma once #pragma once
#include <LibJS/Runtime/PrototypeObject.h>
#include <LibJS/Runtime/WeakRef.h> #include <LibJS/Runtime/WeakRef.h>
namespace JS { namespace JS {
class WeakRefPrototype final : public Object { class WeakRefPrototype final : public PrototypeObject<WeakRefPrototype, WeakRef> {
JS_OBJECT(WeakRefPrototype, Object); JS_PROTOTYPE_OBJECT(WeakRefPrototype, WeakRef, WeakRef);
public: public:
WeakRefPrototype(GlobalObject&); WeakRefPrototype(GlobalObject&);