LibJS: Allow creating shared ArrayBuffer objects more easily

This will allow structured deserialization in LibWeb to create shared
buffers without having to go through CreateSharedByteDataBlock. That
will let us pass in the underlying ByteBuffer, rather than having to
allocate a second buffer via CreateSharedByteDataBlock and memcpy the
data into it.
This commit is contained in:
Timothy Flynn 2025-07-17 09:49:11 -04:00 committed by Tim Flynn
commit b204977efb
Notes: github-actions[bot] 2025-07-18 14:11:11 +00:00
2 changed files with 24 additions and 17 deletions

View file

@ -59,9 +59,9 @@ class JS_API ArrayBuffer : public Object {
GC_DECLARE_ALLOCATOR(ArrayBuffer);
public:
static ThrowCompletionOr<GC::Ref<ArrayBuffer>> create(Realm&, size_t);
static GC::Ref<ArrayBuffer> create(Realm&, ByteBuffer);
static GC::Ref<ArrayBuffer> create(Realm&, ByteBuffer*);
static ThrowCompletionOr<GC::Ref<ArrayBuffer>> create(Realm&, size_t, DataBlock::Shared = DataBlock::Shared::No);
static GC::Ref<ArrayBuffer> create(Realm&, ByteBuffer, DataBlock::Shared = DataBlock::Shared::No);
static GC::Ref<ArrayBuffer> create(Realm&, ByteBuffer*, DataBlock::Shared = DataBlock::Shared::No);
virtual ~ArrayBuffer() override = default;
@ -132,8 +132,8 @@ public:
Value get_modify_set_value(size_t byte_index, Value value, ReadWriteModifyFunction operation, bool is_little_endian = true);
private:
ArrayBuffer(ByteBuffer buffer, Object& prototype);
ArrayBuffer(ByteBuffer* buffer, Object& prototype);
ArrayBuffer(ByteBuffer buffer, DataBlock::Shared, Object& prototype);
ArrayBuffer(ByteBuffer* buffer, DataBlock::Shared, Object& prototype);
virtual void visit_edges(Visitor&) override;