LibJS: Convert FinalizationRegistry.prototype to be a PrototypeObject
This commit is contained in:
parent
94f076a774
commit
43e4cec3e2
Notes:
sideshowbarker
2024-07-18 04:13:00 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/43e4cec3e22 Pull-request: https://github.com/SerenityOS/serenity/pull/9973 Reviewed-by: https://github.com/linusg ✅
2 changed files with 7 additions and 20 deletions
Userland/Libraries/LibJS/Runtime
|
@ -10,7 +10,7 @@
|
|||
namespace JS {
|
||||
|
||||
FinalizationRegistryPrototype::FinalizationRegistryPrototype(GlobalObject& global_object)
|
||||
: Object(*global_object.object_prototype())
|
||||
: PrototypeObject(*global_object.object_prototype())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -32,22 +32,10 @@ FinalizationRegistryPrototype::~FinalizationRegistryPrototype()
|
|||
{
|
||||
}
|
||||
|
||||
FinalizationRegistry* FinalizationRegistryPrototype::typed_this(VM& vm, GlobalObject& global_object)
|
||||
{
|
||||
auto* this_object = vm.this_value(global_object).to_object(global_object);
|
||||
if (!this_object)
|
||||
return nullptr;
|
||||
if (!is<FinalizationRegistry>(this_object)) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "FinalizationRegistry");
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<FinalizationRegistry*>(this_object);
|
||||
}
|
||||
|
||||
// @STAGE 2@ FinalizationRegistry.prototype.cleanupSome ( [ callback ] ), https://github.com/tc39/proposal-cleanup-some/blob/master/spec/finalization-registry.html
|
||||
JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::cleanup_some)
|
||||
{
|
||||
auto* finalization_registry = typed_this(vm, global_object);
|
||||
auto* finalization_registry = typed_this_object(global_object);
|
||||
if (!finalization_registry)
|
||||
return {};
|
||||
|
||||
|
@ -65,7 +53,7 @@ JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::cleanup_some)
|
|||
// 26.2.3.2 FinalizationRegistry.prototype.register ( target, heldValue [ , unregisterToken ] ), https://tc39.es/ecma262/#sec-finalization-registry.prototype.register
|
||||
JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::register_)
|
||||
{
|
||||
auto* finalization_registry = typed_this(vm, global_object);
|
||||
auto* finalization_registry = typed_this_object(global_object);
|
||||
if (!finalization_registry)
|
||||
return {};
|
||||
|
||||
|
@ -95,7 +83,7 @@ JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::register_)
|
|||
// 26.2.3.3 FinalizationRegistry.prototype.unregister ( unregisterToken ), https://tc39.es/ecma262/#sec-finalization-registry.prototype.unregister
|
||||
JS_DEFINE_NATIVE_FUNCTION(FinalizationRegistryPrototype::unregister)
|
||||
{
|
||||
auto* finalization_registry = typed_this(vm, global_object);
|
||||
auto* finalization_registry = typed_this_object(global_object);
|
||||
if (!finalization_registry)
|
||||
return {};
|
||||
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibJS/Runtime/FinalizationRegistry.h>
|
||||
#include <LibJS/Runtime/PrototypeObject.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
class FinalizationRegistryPrototype final : public Object {
|
||||
JS_OBJECT(FinalizationRegistryPrototype, Object);
|
||||
class FinalizationRegistryPrototype final : public PrototypeObject<FinalizationRegistryPrototype, FinalizationRegistry> {
|
||||
JS_PROTOTYPE_OBJECT(FinalizationRegistryPrototype, FinalizationRegistry, FinalizationRegistry);
|
||||
|
||||
public:
|
||||
FinalizationRegistryPrototype(GlobalObject&);
|
||||
|
@ -19,8 +20,6 @@ public:
|
|||
virtual ~FinalizationRegistryPrototype() override;
|
||||
|
||||
private:
|
||||
static FinalizationRegistry* typed_this(VM&, GlobalObject&);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(cleanup_some);
|
||||
JS_DECLARE_NATIVE_FUNCTION(register_);
|
||||
JS_DECLARE_NATIVE_FUNCTION(unregister);
|
||||
|
|
Loading…
Add table
Reference in a new issue