diff --git a/Userland/Libraries/LibJS/Runtime/Array.cpp b/Userland/Libraries/LibJS/Runtime/Array.cpp index 2509d13422..dabf19f9fb 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.cpp +++ b/Userland/Libraries/LibJS/Runtime/Array.cpp @@ -38,8 +38,13 @@ Array* Array::create(GlobalObject& global_object) Array::Array(Object& prototype) : Object(prototype) +{ +} + +void Array::initialize(GlobalObject& global_object) { auto& vm = this->vm(); + Object::initialize(global_object); define_native_property(vm.names.length, length_getter, length_setter, Attribute::Writable); } diff --git a/Userland/Libraries/LibJS/Runtime/Array.h b/Userland/Libraries/LibJS/Runtime/Array.h index 2ee4727c35..5beeefa809 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.h +++ b/Userland/Libraries/LibJS/Runtime/Array.h @@ -30,13 +30,14 @@ namespace JS { -class Array final : public Object { +class Array : public Object { JS_OBJECT(Array, Object); public: static Array* create(GlobalObject&); explicit Array(Object& prototype); + virtual void initialize(GlobalObject&) override; virtual ~Array() override; static Array* typed_this(VM&, GlobalObject&); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 311ea3707b..d4aba04f20 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -44,14 +44,14 @@ namespace JS { static HashTable s_array_join_seen_objects; ArrayPrototype::ArrayPrototype(GlobalObject& global_object) - : Object(*global_object.object_prototype()) + : Array(*global_object.object_prototype()) { } void ArrayPrototype::initialize(GlobalObject& global_object) { auto& vm = this->vm(); - Object::initialize(global_object); + Array::initialize(global_object); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.filter, filter, 1, attr); @@ -81,7 +81,6 @@ void ArrayPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.fill, fill, 1, attr); define_native_function(vm.names.values, values, 0, attr); define_native_function(vm.names.flat, flat, 0, attr); - define_property(vm.names.length, Value(0), Attribute::Configurable); // Use define_property here instead of define_native_function so that // Object.is(Array.prototype[Symbol.iterator], Array.prototype.values) diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.h b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.h index 92ffafe957..906e0af39a 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.h @@ -27,12 +27,12 @@ #pragma once -#include +#include namespace JS { -class ArrayPrototype final : public Object { - JS_OBJECT(ArrayPrototype, Object); +class ArrayPrototype final : public Array { + JS_OBJECT(ArrayPrototype, Array); public: ArrayPrototype(GlobalObject&); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js b/Userland/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js index bbe12a8c44..e0577a70fa 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Array/Array.isArray.js @@ -21,6 +21,5 @@ test("arguments that evaluate to true", () => { expect(Array.isArray(new Array())).toBeTrue(); expect(Array.isArray(new Array(10))).toBeTrue(); expect(Array.isArray(new Array("a", "b", "c"))).toBeTrue(); - // FIXME: Array.prototype is supposed to be an array! - // expect(Array.isArray(Array.prototype)).toBeTrue(); + expect(Array.isArray(Array.prototype)).toBeTrue(); });