mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03:00
LibJS: Convert WeakMap.prototype to be a PrototypeObject
This commit is contained in:
parent
be0880fb2c
commit
966f4faae4
Notes:
sideshowbarker
2024-07-18 04:13:27 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/966f4faae43 Pull-request: https://github.com/SerenityOS/serenity/pull/9973 Reviewed-by: https://github.com/linusg ✅
@ -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);
|
||||
|
@ -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&);
|
||||
|
Loading…
Reference in New Issue
Block a user