mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
LibJS: Implement the AllocateArrayBuffer() AO
This should be used instead of ArrayBuffer::create() in most places, as it uses OrdinaryCreateFromConstructor to allow for a custom prototype. The data block (ByteBuffer) is allocated separately and attached afterwards, if we didn't fail due to OOM.
This commit is contained in:
parent
f8489da8ee
commit
1fba5ca8c3
2 changed files with 32 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -9,6 +9,7 @@
|
|||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
|
||||
|
@ -35,6 +36,9 @@ public:
|
|||
ByteBuffer& buffer() { return buffer_impl(); }
|
||||
const ByteBuffer& buffer() const { return buffer_impl(); }
|
||||
|
||||
// Used by allocate_array_buffer() to attach the data block after construction
|
||||
void set_buffer(ByteBuffer buffer) { m_buffer = move(buffer); }
|
||||
|
||||
Value detach_key() const { return m_detach_key; }
|
||||
void set_detach_key(Value detach_key) { m_detach_key = detach_key; }
|
||||
|
||||
|
@ -70,6 +74,8 @@ private:
|
|||
Value m_detach_key;
|
||||
};
|
||||
|
||||
ThrowCompletionOr<ArrayBuffer*> allocate_array_buffer(GlobalObject&, FunctionObject& constructor, size_t byte_length);
|
||||
|
||||
// 25.1.2.9 RawBytesToNumeric ( type, rawBytes, isLittleEndian ), https://tc39.es/ecma262/#sec-rawbytestonumeric
|
||||
template<typename T>
|
||||
static Value raw_bytes_to_numeric(GlobalObject& global_object, ByteBuffer raw_value, bool is_little_endian)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue