diff options
author | davidot <davidot@serenityos.org> | 2022-02-07 13:34:32 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-02-08 09:12:42 +0000 |
commit | de90d54be08f0f09b86895916d419833e8a01e5b (patch) | |
tree | 0c68e85e4d45c8a991ceaf6f3518bbc89aab6c25 /Userland/Libraries/LibWeb/Encoding | |
parent | 4136cbdb09130ca643597a5cb284485135f10e95 (diff) | |
download | serenity-de90d54be08f0f09b86895916d419833e8a01e5b.zip |
LibJS: Convert ArrayBuffer construction to ThrowCompletionOr
This also allows us to create TypedArrays with an existing buffer thus
clearing up an additional FIXME in TextEncoder.
Diffstat (limited to 'Userland/Libraries/LibWeb/Encoding')
-rw-r--r-- | Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp index 16a2205df1..bd3af0bb55 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp +++ b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp @@ -27,11 +27,9 @@ JS::Uint8Array* TextEncoder::encode(String const& input) const // 4. If result is finished, then convert output into a byte sequence and return a Uint8Array object wrapping an ArrayBuffer containing output. auto byte_buffer = input.to_byte_buffer(); - - // FIXME: Support `TypedArray::create()` with existing `ArrayBuffer`, so that we don't have to allocate two `ByteBuffer`s. - auto* typed_array = JS::Uint8Array::create(global_object, byte_buffer.size()); - typed_array->viewed_array_buffer()->buffer() = move(byte_buffer); - return typed_array; + auto array_length = byte_buffer.size(); + auto* array_buffer = JS::ArrayBuffer::create(global_object, move(byte_buffer)); + return JS::Uint8Array::create(global_object, array_length, *array_buffer); } // https://encoding.spec.whatwg.org/#dom-textencoder-encoding |