1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:37:46 +00:00

LibJS: Implement ArrayBuffer.prototype.transfer & transferToFixedLength

This commit is contained in:
PrestonLTaylor 2023-06-30 18:00:56 +01:00 committed by Jelle Raaijmakers
parent 34c5d34b95
commit 850c252b3e
5 changed files with 81 additions and 0 deletions

View file

@ -22,6 +22,11 @@ struct ClampedU8 {
// 25.1.1 Notation (read-modify-write modification function), https://tc39.es/ecma262/#sec-arraybuffer-notation
using ReadWriteModifyFunction = Function<ByteBuffer(ByteBuffer, ByteBuffer)>;
enum class PreserveResizability {
FixedLength,
PreserveResizability
};
class ArrayBuffer : public Object {
JS_OBJECT(ArrayBuffer, Object);
@ -98,6 +103,7 @@ void copy_data_block_bytes(ByteBuffer& to_block, u64 to_index, ByteBuffer& from_
ThrowCompletionOr<ArrayBuffer*> allocate_array_buffer(VM&, FunctionObject& constructor, size_t byte_length);
ThrowCompletionOr<void> detach_array_buffer(VM&, ArrayBuffer& array_buffer, Optional<Value> key = {});
ThrowCompletionOr<ArrayBuffer*> clone_array_buffer(VM&, ArrayBuffer& source_buffer, size_t source_byte_offset, size_t source_length);
ThrowCompletionOr<ArrayBuffer*> array_buffer_copy_and_detach(VM&, ArrayBuffer& array_buffer, Value new_length, PreserveResizability preserve_resizability);
// 25.1.2.9 RawBytesToNumeric ( type, rawBytes, isLittleEndian ), https://tc39.es/ecma262/#sec-rawbytestonumeric
template<typename T>