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

LibJS: Implement and test ArrayBuffer.prototype.resize

This commit is contained in:
ForLoveOfCats 2022-03-02 11:24:46 -05:00 committed by Linus Groh
parent b29e19c52a
commit f350c153e8
7 changed files with 118 additions and 0 deletions

View file

@ -14,6 +14,7 @@
#include <LibJS/Interpreter.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>
@ -113,6 +114,23 @@ VM::VM(OwnPtr<CustomData> custom_data)
return Vector<String> { "type" };
};
// 1.1.7 HostResizeArrayBuffer ( buffer, newByteLength ), https://tc39.es/proposal-resizablearraybuffer/#sec-hostresizearraybuffer
host_resize_array_buffer = [](GlobalObject& global_object, size_t new_byte_length) {
// The host-defined abstract operation HostResizeArrayBuffer takes arguments buffer (an ArrayBuffer) and newByteLength (a non-negative integer).
// The host-defined abstract operation HostResizeArrayBuffer takes arguments buffer (an ArrayBuffer object) and newByteLength.
// 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 behavior.
// The implementation of HostResizeArrayBuffer must conform to the following requirements:
// * The abstract operation must return either NormalCompletion(handled), NormalCompletion(unhandled), or an abrupt throw completion.
// * 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 unhandled.
(void)global_object;
(void)new_byte_length;
return HostResizeArrayBufferResult::Unhandled;
};
#define __JS_ENUMERATE(SymbolName, snake_name) \
m_well_known_symbol_##snake_name = js_symbol(*this, "Symbol." #SymbolName, false);
JS_ENUMERATE_WELL_KNOWN_SYMBOLS