mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibWeb: Implement the CloneAsUint8Array AO
This commit is contained in:
parent
debfe996d7
commit
5e5b42730c
Notes:
sideshowbarker
2024-07-16 23:38:54 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/5e5b42730c Pull-request: https://github.com/SerenityOS/serenity/pull/22977 Reviewed-by: https://github.com/shannonbooth ✅
@ -4243,6 +4243,27 @@ bool can_transfer_array_buffer(JS::ArrayBuffer const& array_buffer)
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#abstract-opdef-cloneasuint8array
|
||||
WebIDL::ExceptionOr<JS::Value> clone_as_uint8_array(JS::Realm& realm, WebIDL::ArrayBufferView& view)
|
||||
{
|
||||
auto& vm = realm.vm();
|
||||
|
||||
// 1. Assert: Type(O) is Object.
|
||||
// 2. Assert: O has an [[ViewedArrayBuffer]] internal slot.
|
||||
|
||||
// 3. Assert: ! IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is false.
|
||||
VERIFY(!view.viewed_array_buffer()->is_detached());
|
||||
|
||||
// 4. Let buffer be ? CloneArrayBuffer(O.[[ViewedArrayBuffer]], O.[[ByteOffset]], O.[[ByteLength]], %ArrayBuffer%).
|
||||
auto* buffer = TRY(JS::clone_array_buffer(vm, *view.viewed_array_buffer(), view.byte_offset(), view.byte_length()));
|
||||
|
||||
// 5. Let array be ! Construct(%Uint8Array%, « buffer »).
|
||||
auto array = MUST(JS::construct(vm, *realm.intrinsics().uint8_array_constructor(), buffer));
|
||||
|
||||
// 5. Return array.
|
||||
return array;
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#abstract-opdef-structuredclone
|
||||
WebIDL::ExceptionOr<JS::Value> structured_clone(JS::Realm& realm, JS::Value value)
|
||||
{
|
||||
|
@ -178,6 +178,7 @@ WebIDL::ExceptionOr<void> transform_stream_set_backpressure(TransformStream&, bo
|
||||
|
||||
bool is_non_negative_number(JS::Value);
|
||||
bool can_transfer_array_buffer(JS::ArrayBuffer const& array_buffer);
|
||||
WebIDL::ExceptionOr<JS::Value> clone_as_uint8_array(JS::Realm&, WebIDL::ArrayBufferView&);
|
||||
WebIDL::ExceptionOr<JS::Value> structured_clone(JS::Realm&, JS::Value value);
|
||||
|
||||
JS::Value create_close_sentinel();
|
||||
|
Loading…
Reference in New Issue
Block a user