diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-09-11 15:42:51 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-12 01:40:56 +0200 |
commit | 75d5c17aec7ae74c001d8ae8f36201717c408855 (patch) | |
tree | 6233f4fbf28f0ee27b1de01e77496487c827e3ce /Userland/Libraries/LibJS | |
parent | a41d0d23f94464f14b7b48f8cf4ebe0d4b5ba5cb (diff) | |
download | serenity-75d5c17aec7ae74c001d8ae8f36201717c408855.zip |
LibJS: Convert Set.prototype to be a PrototypeObject
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/SetPrototype.cpp | 30 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/SetPrototype.h | 5 |
2 files changed, 12 insertions, 23 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp index 89ef9596f1..7f68f48ee0 100644 --- a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp @@ -12,7 +12,7 @@ namespace JS { SetPrototype::SetPrototype(GlobalObject& global_object) - : Object(*global_object.object_prototype()) + : PrototypeObject(*global_object.object_prototype()) { } @@ -44,22 +44,10 @@ SetPrototype::~SetPrototype() { } -Set* SetPrototype::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<Set>(this_object)) { - vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "Set"); - return nullptr; - } - return static_cast<Set*>(this_object); -} - // 24.2.3.1 Set.prototype.add ( value ), https://tc39.es/ecma262/#sec-set.prototype.add JS_DEFINE_NATIVE_FUNCTION(SetPrototype::add) { - auto* set = typed_this(vm, global_object); + auto* set = typed_this_object(global_object); if (!set) return {}; auto value = vm.argument(0); @@ -72,7 +60,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::add) // 24.2.3.2 Set.prototype.clear ( ), https://tc39.es/ecma262/#sec-set.prototype.clear JS_DEFINE_NATIVE_FUNCTION(SetPrototype::clear) { - auto* set = typed_this(vm, global_object); + auto* set = typed_this_object(global_object); if (!set) return {}; set->values().clear(); @@ -82,7 +70,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::clear) // 24.2.3.4 Set.prototype.delete ( value ), https://tc39.es/ecma262/#sec-set.prototype.delete JS_DEFINE_NATIVE_FUNCTION(SetPrototype::delete_) { - auto* set = typed_this(vm, global_object); + auto* set = typed_this_object(global_object); if (!set) return {}; return Value(set->values().remove(vm.argument(0))); @@ -91,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::delete_) // 24.2.3.5 Set.prototype.entries ( ), https://tc39.es/ecma262/#sec-set.prototype.entries JS_DEFINE_NATIVE_FUNCTION(SetPrototype::entries) { - auto* set = typed_this(vm, global_object); + auto* set = typed_this_object(global_object); if (!set) return {}; @@ -101,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::entries) // 24.2.3.6 Set.prototype.forEach ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-set.prototype.foreach JS_DEFINE_NATIVE_FUNCTION(SetPrototype::for_each) { - auto* set = typed_this(vm, global_object); + auto* set = typed_this_object(global_object); if (!set) return {}; if (!vm.argument(0).is_function()) { @@ -120,7 +108,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::for_each) // 24.2.3.7 Set.prototype.has ( value ), https://tc39.es/ecma262/#sec-set.prototype.has JS_DEFINE_NATIVE_FUNCTION(SetPrototype::has) { - auto* set = typed_this(vm, global_object); + auto* set = typed_this_object(global_object); if (!set) return {}; auto& values = set->values(); @@ -130,7 +118,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::has) // 24.2.3.10 Set.prototype.values ( ), https://tc39.es/ecma262/#sec-set.prototype.values JS_DEFINE_NATIVE_FUNCTION(SetPrototype::values) { - auto* set = typed_this(vm, global_object); + auto* set = typed_this_object(global_object); if (!set) return {}; @@ -140,7 +128,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::values) // 24.2.3.9 get Set.prototype.size, https://tc39.es/ecma262/#sec-get-set.prototype.size JS_DEFINE_NATIVE_GETTER(SetPrototype::size_getter) { - auto* set = typed_this(vm, global_object); + auto* set = typed_this_object(global_object); if (!set) return {}; return Value(set->values().size()); diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.h b/Userland/Libraries/LibJS/Runtime/SetPrototype.h index 9044172c5c..24e0a241ff 100644 --- a/Userland/Libraries/LibJS/Runtime/SetPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.h @@ -6,12 +6,13 @@ #pragma once +#include <LibJS/Runtime/PrototypeObject.h> #include <LibJS/Runtime/Set.h> namespace JS { -class SetPrototype final : public Object { - JS_OBJECT(SetPrototype, Object); +class SetPrototype final : public PrototypeObject<SetPrototype, Set> { + JS_PROTOTYPE_OBJECT(SetPrototype, Set, Set); public: SetPrototype(GlobalObject&); |