2021-06-13 22:47:08 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibJS/Runtime/ArrayBuffer.h>
|
2023-10-15 13:46:09 +00:00
|
|
|
#include <LibJS/Runtime/ByteLength.h>
|
2021-06-13 22:47:08 +00:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
class DataView : public Object {
|
|
|
|
JS_OBJECT(DataView, Object);
|
2024-11-14 15:01:23 +00:00
|
|
|
GC_DECLARE_ALLOCATOR(DataView);
|
2021-06-13 22:47:08 +00:00
|
|
|
|
|
|
|
public:
|
2024-11-14 15:01:23 +00:00
|
|
|
static GC::Ref<DataView> create(Realm&, ArrayBuffer*, ByteLength byte_length, size_t byte_offset);
|
2021-06-13 22:47:08 +00:00
|
|
|
|
2022-03-14 16:25:06 +00:00
|
|
|
virtual ~DataView() override = default;
|
2021-06-13 22:47:08 +00:00
|
|
|
|
|
|
|
ArrayBuffer* viewed_array_buffer() const { return m_viewed_array_buffer; }
|
2023-10-15 13:46:09 +00:00
|
|
|
ByteLength const& byte_length() const { return m_byte_length; }
|
2024-11-03 22:30:44 +00:00
|
|
|
u32 byte_offset() const { return m_byte_offset; }
|
2021-06-13 22:47:08 +00:00
|
|
|
|
|
|
|
private:
|
2023-10-15 13:46:09 +00:00
|
|
|
DataView(ArrayBuffer*, ByteLength byte_length, size_t byte_offset, Object& prototype);
|
2022-08-28 21:51:28 +00:00
|
|
|
|
2021-06-13 22:47:08 +00:00
|
|
|
virtual void visit_edges(Visitor& visitor) override;
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
GC::Ptr<ArrayBuffer> m_viewed_array_buffer;
|
2023-10-15 13:46:09 +00:00
|
|
|
ByteLength m_byte_length { 0 };
|
2021-06-13 22:47:08 +00:00
|
|
|
size_t m_byte_offset { 0 };
|
|
|
|
};
|
|
|
|
|
2023-10-15 13:46:09 +00:00
|
|
|
// 25.3.1.1 DataView With Buffer Witness Records, https://tc39.es/ecma262/#sec-dataview-with-buffer-witness-records
|
|
|
|
struct DataViewWithBufferWitness {
|
2024-11-14 15:01:23 +00:00
|
|
|
GC::Ref<DataView const> object; // [[Object]]
|
2023-10-15 13:46:09 +00:00
|
|
|
ByteLength cached_buffer_byte_length; // [[CachedBufferByteLength]]
|
|
|
|
};
|
|
|
|
|
|
|
|
DataViewWithBufferWitness make_data_view_with_buffer_witness_record(DataView const&, ArrayBuffer::Order);
|
|
|
|
u32 get_view_byte_length(DataViewWithBufferWitness const&);
|
|
|
|
bool is_view_out_of_bounds(DataViewWithBufferWitness const&);
|
|
|
|
|
2021-06-13 22:47:08 +00:00
|
|
|
}
|