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

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.
This commit is contained in:
Idan Horowitz 2021-06-09 19:01:45 +03:00 committed by Linus Groh
parent 5d57384bc4
commit f437793788
4 changed files with 18 additions and 18 deletions

View file

@ -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) void Set::visit_edges(Cell::Visitor& visitor)
{ {
Object::visit_edges(visitor); Object::visit_edges(visitor);

View file

@ -41,8 +41,6 @@ public:
explicit Set(Object& prototype); explicit Set(Object& prototype);
virtual ~Set() override; virtual ~Set() override;
static Set* typed_this(VM&, GlobalObject&);
HashTable<Value, ValueTraits> const& values() const { return m_values; }; HashTable<Value, ValueTraits> const& values() const { return m_values; };
HashTable<Value, ValueTraits>& values() { return m_values; }; HashTable<Value, ValueTraits>& values() { return m_values; };

View file

@ -11,14 +11,14 @@
namespace JS { namespace JS {
SetPrototype::SetPrototype(GlobalObject& global_object) SetPrototype::SetPrototype(GlobalObject& global_object)
: Set(*global_object.object_prototype()) : Object(*global_object.object_prototype())
{ {
} }
void SetPrototype::initialize(GlobalObject& global_object) void SetPrototype::initialize(GlobalObject& global_object)
{ {
auto& vm = this->vm(); auto& vm = this->vm();
Set::initialize(global_object); Object::initialize(global_object);
u8 attr = Attribute::Writable | Attribute::Configurable; u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.add, add, 1, attr); 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) JS_DEFINE_NATIVE_FUNCTION(SetPrototype::add)
{ {
auto* set = typed_this(vm, global_object); auto* set = typed_this(vm, global_object);

View file

@ -10,8 +10,8 @@
namespace JS { namespace JS {
class SetPrototype final : public Set { class SetPrototype final : public Object {
JS_OBJECT(SetPrototype, Set); JS_OBJECT(SetPrototype, Object);
public: public:
SetPrototype(GlobalObject&); SetPrototype(GlobalObject&);
@ -19,6 +19,8 @@ public:
virtual ~SetPrototype() override; virtual ~SetPrototype() override;
private: private:
static Set* typed_this(VM&, GlobalObject&);
JS_DECLARE_NATIVE_FUNCTION(add); JS_DECLARE_NATIVE_FUNCTION(add);
JS_DECLARE_NATIVE_FUNCTION(clear); JS_DECLARE_NATIVE_FUNCTION(clear);
JS_DECLARE_NATIVE_FUNCTION(delete_); JS_DECLARE_NATIVE_FUNCTION(delete_);