1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +00:00

LibJS: Inline the ArrayBufferByteLength implementation

Note: When we better support SharedArrayBuffer, that part of this AO
might not be inlined, as it looks a bit expensive.

On https://cyxx.github.io/another_js, this reduces the runtime of
IsValidIntegerIndex from 12.5% to 11.5%.
This commit is contained in:
Timothy Flynn 2024-02-27 09:19:58 -05:00 committed by Andreas Kling
parent 9c943f36ed
commit 84936c9ab6
2 changed files with 16 additions and 17 deletions

View file

@ -181,22 +181,6 @@ ThrowCompletionOr<ArrayBuffer*> allocate_array_buffer(VM& vm, FunctionObject& co
return obj.ptr();
}
// 25.1.3.2 ArrayBufferByteLength ( arrayBuffer, order ), https://tc39.es/ecma262/#sec-arraybufferbytelength
size_t array_buffer_byte_length(ArrayBuffer const& array_buffer, ArrayBuffer::Order)
{
// FIXME: 1. If IsSharedArrayBuffer(arrayBuffer) is true and arrayBuffer has an [[ArrayBufferByteLengthData]] internal slot, then
// FIXME: a. Let bufferByteLengthBlock be arrayBuffer.[[ArrayBufferByteLengthData]].
// FIXME: b. Let rawLength be GetRawBytesFromSharedBlock(bufferByteLengthBlock, 0, biguint64, true, order).
// FIXME: c. Let isLittleEndian be the value of the [[LittleEndian]] field of the surrounding agent's Agent Record.
// FIXME: d. Return (RawBytesToNumeric(biguint64, rawLength, isLittleEndian)).
// 2. Assert: IsDetachedBuffer(arrayBuffer) is false.
VERIFY(!array_buffer.is_detached());
// 3. Return arrayBuffer.[[ArrayBufferByteLength]].
return array_buffer.byte_length();
}
// 25.1.3.4 DetachArrayBuffer ( arrayBuffer [ , key ] ), https://tc39.es/ecma262/#sec-detacharraybuffer
ThrowCompletionOr<void> detach_array_buffer(VM& vm, ArrayBuffer& array_buffer, Optional<Value> key)
{