summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-09-11 16:12:31 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-12 01:40:56 +0200
commit8bfb665b72430b3c20a34cd5f4e6519d6744fcd5 (patch)
treef594d4832c108f4605c0671f2504d69ca1fba3f8 /Userland/Libraries/LibJS
parent4d1d0f05a9999be63821af1c3535e07fa12f1e54 (diff)
downloadserenity-8bfb665b72430b3c20a34cd5f4e6519d6744fcd5.zip
LibJS: Convert DataView.prototype to be a PrototypeObject
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp22
-rw-r--r--Userland/Libraries/LibJS/Runtime/DataViewPrototype.h5
2 files changed, 9 insertions, 18 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp b/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp
index 747200f0fc..5688c22005 100644
--- a/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp
@@ -11,7 +11,7 @@
namespace JS {
DataViewPrototype::DataViewPrototype(GlobalObject& global_object)
- : Object(*global_object.object_prototype())
+ : PrototypeObject(*global_object.object_prototype())
{
}
@@ -54,22 +54,12 @@ DataViewPrototype::~DataViewPrototype()
{
}
-static DataView* typed_this(VM& vm, GlobalObject& global_object)
-{
- auto this_value = vm.this_value(global_object);
- if (!this_value.is_object() || !is<DataView>(this_value.as_object())) {
- vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObjectOfType, vm.names.DataView);
- return nullptr;
- }
- return static_cast<DataView*>(&this_value.as_object());
-}
-
// 25.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ), https://tc39.es/ecma262/#sec-getviewvalue
template<typename T>
static Value get_view_value(GlobalObject& global_object, Value request_index, Value is_little_endian)
{
auto& vm = global_object.vm();
- auto* view = typed_this(vm, global_object);
+ auto* view = DataViewPrototype::typed_this_value(global_object);
if (!view)
return {};
@@ -108,7 +98,7 @@ template<typename T>
static Value set_view_value(GlobalObject& global_object, Value request_index, Value is_little_endian, Value value)
{
auto& vm = global_object.vm();
- auto* view = typed_this(vm, global_object);
+ auto* view = DataViewPrototype::typed_this_value(global_object);
if (!view)
return {};
@@ -265,7 +255,7 @@ JS_DEFINE_NATIVE_FUNCTION(DataViewPrototype::set_uint_32)
// 25.3.4.1 get DataView.prototype.buffer, https://tc39.es/ecma262/#sec-get-dataview.prototype.buffer
JS_DEFINE_NATIVE_GETTER(DataViewPrototype::buffer_getter)
{
- auto* data_view = typed_this(vm, global_object);
+ auto* data_view = typed_this_value(global_object);
if (!data_view)
return {};
return data_view->viewed_array_buffer();
@@ -274,7 +264,7 @@ JS_DEFINE_NATIVE_GETTER(DataViewPrototype::buffer_getter)
// 25.3.4.2 get DataView.prototype.byteLength, https://tc39.es/ecma262/#sec-get-dataview.prototype.bytelength
JS_DEFINE_NATIVE_GETTER(DataViewPrototype::byte_length_getter)
{
- auto* data_view = typed_this(vm, global_object);
+ auto* data_view = typed_this_value(global_object);
if (!data_view)
return {};
if (data_view->viewed_array_buffer()->is_detached()) {
@@ -287,7 +277,7 @@ JS_DEFINE_NATIVE_GETTER(DataViewPrototype::byte_length_getter)
// 25.3.4.3 get DataView.prototype.byteOffset, https://tc39.es/ecma262/#sec-get-dataview.prototype.byteoffset
JS_DEFINE_NATIVE_GETTER(DataViewPrototype::byte_offset_getter)
{
- auto* data_view = typed_this(vm, global_object);
+ auto* data_view = typed_this_value(global_object);
if (!data_view)
return {};
if (data_view->viewed_array_buffer()->is_detached()) {
diff --git a/Userland/Libraries/LibJS/Runtime/DataViewPrototype.h b/Userland/Libraries/LibJS/Runtime/DataViewPrototype.h
index 4a7444adf6..839719c43b 100644
--- a/Userland/Libraries/LibJS/Runtime/DataViewPrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/DataViewPrototype.h
@@ -7,11 +7,12 @@
#pragma once
#include <LibJS/Runtime/DataView.h>
+#include <LibJS/Runtime/PrototypeObject.h>
namespace JS {
-class DataViewPrototype final : public Object {
- JS_OBJECT(DataViewPrototype, Object);
+class DataViewPrototype final : public PrototypeObject<DataViewPrototype, DataView> {
+ JS_PROTOTYPE_OBJECT(DataViewPrototype, DataView, DataView);
public:
DataViewPrototype(GlobalObject&);