diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 0275e347f3..c23996961c 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -503,7 +503,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor) } \ \ ConstructorName::ConstructorName(Realm& realm, Object& prototype) \ - : TypedArrayConstructor(realm.vm().names.ClassName.as_string(), prototype) \ + : NativeFunction(realm.vm().names.ClassName.as_string(), prototype) \ { \ } \ \ diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h index 72b0c562b7..d36053a9f7 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.h +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h @@ -509,8 +509,8 @@ ThrowCompletionOr compare_typed_array_elements(VM&, Value x, Value y, Fu private: \ PrototypeName(Object& prototype); \ }; \ - class ConstructorName final : public TypedArrayConstructor { \ - JS_OBJECT(ConstructorName, TypedArrayConstructor); \ + class ConstructorName final : public NativeFunction { \ + JS_OBJECT(ConstructorName, NativeFunction); \ JS_DECLARE_ALLOCATOR(ConstructorName); \ \ public: \ diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.from.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.from.js index cc11516827..20bf294212 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.from.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.from.js @@ -27,3 +27,11 @@ test("basic functionality", () => { expect(newTypedArray[2]).toBe(3n); }); }); + +test("is inherited from TypedArray base class", () => { + TYPED_ARRAYS.forEach(T1 => { + TYPED_ARRAYS.forEach(T2 => { + expect(T1.from).toBe(T2.from); + }); + }); +}); diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.js index 5de4ca8445..454a9adc31 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.js @@ -390,3 +390,12 @@ test("source is not the same value as the receiver, and the index is invalid", ( expect(receiver[2]).toBeUndefined(); }); }); + +test("constructor functions are defined in the TypedArray prototype, rather than the object itself", () => { + TYPED_ARRAYS.forEach(T => { + for (property of ["of", "from"]) { + expect(T.hasOwnProperty(property)).toBe(false); + expect(Object.getPrototypeOf(T).hasOwnProperty(property)).toBe(true); + } + }); +}); diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.of.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.of.js index 7dc07353f6..7246b1833d 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.of.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.of.js @@ -27,3 +27,11 @@ test("basic functionality", () => { expect(newTypedArray[2]).toBe(3n); }); }); + +test("is inherited from TypedArray base class", () => { + TYPED_ARRAYS.forEach(T1 => { + TYPED_ARRAYS.forEach(T2 => { + expect(T1.of).toBe(T2.of); + }); + }); +});