mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:47:34 +00:00
LibJS: Partially implement resizable ArrayBuffer objects
This is (part of) a normative change in the ECMA-262 spec. See:
a9ae96e
This implements just support for resizing ArrayBuffer objects. This does
not implement the SharedArrayBuffer changes, as we do not have enough
support to do so.
This commit is contained in:
parent
a1e2f131c4
commit
29ac6e3689
13 changed files with 369 additions and 14 deletions
|
@ -18,6 +18,7 @@
|
|||
#include <LibJS/JIT/NativeExecutable.h>
|
||||
#include <LibJS/Runtime/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Array.h>
|
||||
#include <LibJS/Runtime/ArrayBuffer.h>
|
||||
#include <LibJS/Runtime/BoundFunction.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/ECMAScriptFunctionObject.h>
|
||||
|
@ -134,6 +135,25 @@ VM::VM(OwnPtr<CustomData> custom_data, ErrorMessages error_messages)
|
|||
// NOTE: Since LibJS has no way of knowing whether the current environment is a browser we always
|
||||
// call HostEnsureCanAddPrivateElement when needed.
|
||||
};
|
||||
|
||||
// 25.1.3.7 HostResizeArrayBuffer ( buffer, newByteLength ), https://tc39.es/ecma262/#sec-hostresizearraybuffer
|
||||
host_resize_array_buffer = [this](ArrayBuffer& buffer, size_t new_byte_length) -> ThrowCompletionOr<HandledByHost> {
|
||||
// The host-defined abstract operation HostResizeArrayBuffer takes arguments buffer (an ArrayBuffer) and
|
||||
// newByteLength (a non-negative integer) and returns either a normal completion containing either handled or
|
||||
// unhandled, or a throw completion. It gives the host an opportunity to perform implementation-defined resizing
|
||||
// of buffer. If the host chooses not to handle resizing of buffer, it may return unhandled for the default behaviour.
|
||||
|
||||
// The implementation of HostResizeArrayBuffer must conform to the following requirements:
|
||||
// - The abstract operation does not detach buffer.
|
||||
// - If the abstract operation completes normally with handled, buffer.[[ArrayBufferByteLength]] is newByteLength.
|
||||
|
||||
// The default implementation of HostResizeArrayBuffer is to return NormalCompletion(unhandled).
|
||||
|
||||
if (auto result = buffer.buffer().try_resize(new_byte_length); result.is_error())
|
||||
return throw_completion<RangeError>(ErrorType::NotEnoughMemoryToAllocate, new_byte_length);
|
||||
|
||||
return HandledByHost::Handled;
|
||||
};
|
||||
}
|
||||
|
||||
VM::~VM() = default;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue