diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp index 89aafda333..f426754539 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -15,7 +14,7 @@ namespace JS { ArrayBufferPrototype::ArrayBufferPrototype(GlobalObject& global_object) - : Object(*global_object.object_prototype()) + : PrototypeObject(*global_object.object_prototype()) { } @@ -35,21 +34,10 @@ ArrayBufferPrototype::~ArrayBufferPrototype() { } -static ArrayBuffer* array_buffer_object_from(VM& vm, GlobalObject& global_object) -{ - // ArrayBuffer.prototype.* deliberately don't coerce |this| value to object. - auto this_value = vm.this_value(global_object); - if (!this_value.is_object() || !is(this_value.as_object())) { - vm.throw_exception(global_object, ErrorType::NotAnObjectOfType, "ArrayBuffer"); - return nullptr; - } - return static_cast(&this_value.as_object()); -} - // 25.1.5.3 ArrayBuffer.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice) { - auto array_buffer_object = array_buffer_object_from(vm, global_object); + auto array_buffer_object = typed_this_value(global_object); if (!array_buffer_object) return {}; @@ -126,7 +114,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayBufferPrototype::slice) // 25.1.5.1 get ArrayBuffer.prototype.byteLength, https://tc39.es/ecma262/#sec-get-arraybuffer.prototype.bytelength JS_DEFINE_NATIVE_GETTER(ArrayBufferPrototype::byte_length_getter) { - auto array_buffer_object = array_buffer_object_from(vm, global_object); + auto array_buffer_object = typed_this_value(global_object); if (!array_buffer_object) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.h b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.h index e0d70ebe24..17536ac332 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.h +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.h @@ -6,12 +6,13 @@ #pragma once -#include +#include +#include namespace JS { -class ArrayBufferPrototype final : public Object { - JS_OBJECT(ArrayBufferPrototype, Object); +class ArrayBufferPrototype final : public PrototypeObject { + JS_PROTOTYPE_OBJECT(ArrayBufferPrototype, ArrayBuffer, ArrayBuffer); public: explicit ArrayBufferPrototype(GlobalObject&);