summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-06-09 19:01:45 +0300
committerLinus Groh <mail@linusgroh.de>2021-06-09 18:01:19 +0100
commitf4377937880054c680710f693c295490295c4662 (patch)
tree54936a54c0de86f72bbbb6d597d32a10896b12eb /Userland/Libraries
parent5d57384bc45aaea57e58fd06c6c6596afda52d21 (diff)
downloadserenity-f4377937880054c680710f693c295490295c4662.zip
LibJS: Stop inheriting from Set in SetPrototype
This makes sure that is<Set> checks done on the Set prototype instead of on Set instances return false, thereby emulating the behaviour of the RequireInternalSlot abstract operation.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Set.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Set.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetPrototype.cpp16
-rw-r--r--Userland/Libraries/LibJS/Runtime/SetPrototype.h6
4 files changed, 18 insertions, 18 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Set.cpp b/Userland/Libraries/LibJS/Runtime/Set.cpp
index 4cb42f215f..8c8a47fa1b 100644
--- a/Userland/Libraries/LibJS/Runtime/Set.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Set.cpp
@@ -22,18 +22,6 @@ Set::~Set()
{
}
-Set* Set::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::NotA, "Set");
- return nullptr;
- }
- return static_cast<Set*>(this_object);
-}
-
void Set::visit_edges(Cell::Visitor& visitor)
{
Object::visit_edges(visitor);
diff --git a/Userland/Libraries/LibJS/Runtime/Set.h b/Userland/Libraries/LibJS/Runtime/Set.h
index 59ac8ace4c..0e17fa7196 100644
--- a/Userland/Libraries/LibJS/Runtime/Set.h
+++ b/Userland/Libraries/LibJS/Runtime/Set.h
@@ -41,8 +41,6 @@ public:
explicit Set(Object& prototype);
virtual ~Set() override;
- static Set* typed_this(VM&, GlobalObject&);
-
HashTable<Value, ValueTraits> const& values() const { return m_values; };
HashTable<Value, ValueTraits>& values() { return m_values; };
diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
index d6f6a14af8..ac6c731260 100644
--- a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp
@@ -11,14 +11,14 @@
namespace JS {
SetPrototype::SetPrototype(GlobalObject& global_object)
- : Set(*global_object.object_prototype())
+ : Object(*global_object.object_prototype())
{
}
void SetPrototype::initialize(GlobalObject& global_object)
{
auto& vm = this->vm();
- Set::initialize(global_object);
+ Object::initialize(global_object);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.add, add, 1, attr);
@@ -40,6 +40,18 @@ 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::NotA, "Set");
+ return nullptr;
+ }
+ return static_cast<Set*>(this_object);
+}
+
JS_DEFINE_NATIVE_FUNCTION(SetPrototype::add)
{
auto* set = typed_this(vm, global_object);
diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.h b/Userland/Libraries/LibJS/Runtime/SetPrototype.h
index e0b7056140..9044172c5c 100644
--- a/Userland/Libraries/LibJS/Runtime/SetPrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.h
@@ -10,8 +10,8 @@
namespace JS {
-class SetPrototype final : public Set {
- JS_OBJECT(SetPrototype, Set);
+class SetPrototype final : public Object {
+ JS_OBJECT(SetPrototype, Object);
public:
SetPrototype(GlobalObject&);
@@ -19,6 +19,8 @@ public:
virtual ~SetPrototype() override;
private:
+ static Set* typed_this(VM&, GlobalObject&);
+
JS_DECLARE_NATIVE_FUNCTION(add);
JS_DECLARE_NATIVE_FUNCTION(clear);
JS_DECLARE_NATIVE_FUNCTION(delete_);