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

LibJS: Convert ArrayBuffer.prototype to be a PrototypeObject

This commit is contained in:
Timothy Flynn 2021-09-11 16:01:18 -04:00 committed by Andreas Kling
parent 696967d7b6
commit bd4c116d08
2 changed files with 7 additions and 18 deletions

View file

@ -7,7 +7,6 @@
#include <AK/Function.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/ArrayBufferConstructor.h>
#include <LibJS/Runtime/ArrayBufferPrototype.h>
#include <LibJS/Runtime/GlobalObject.h>
@ -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<ArrayBuffer>(this_value.as_object())) {
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, "ArrayBuffer");
return nullptr;
}
return static_cast<ArrayBuffer*>(&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 {};

View file

@ -6,12 +6,13 @@
#pragma once
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/PrototypeObject.h>
namespace JS {
class ArrayBufferPrototype final : public Object {
JS_OBJECT(ArrayBufferPrototype, Object);
class ArrayBufferPrototype final : public PrototypeObject<ArrayBufferPrototype, ArrayBuffer> {
JS_PROTOTYPE_OBJECT(ArrayBufferPrototype, ArrayBuffer, ArrayBuffer);
public:
explicit ArrayBufferPrototype(GlobalObject&);