diff --git a/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.cpp b/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.cpp index ac0efb5db3..054cca4816 100644 --- a/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.cpp @@ -17,7 +17,7 @@ namespace Web::Bindings::IDL { // https://webidl.spec.whatwg.org/#dfn-get-buffer-source-copy -Optional get_buffer_source_copy(JS::Object const& buffer_source) +ErrorOr get_buffer_source_copy(JS::Object const& buffer_source) { // 1. Let esBufferSource be the result of converting bufferSource to an ECMAScript value. @@ -69,18 +69,16 @@ Optional get_buffer_source_copy(JS::Object const& buffer_source) return ByteBuffer {}; // 8. Let bytes be a new byte sequence of length equal to length. - auto bytes = ByteBuffer::create_zeroed(length); - if (bytes.is_error()) - return {}; + auto bytes = TRY(ByteBuffer::create_zeroed(length)); // 9. For i in the range offset to offset + length − 1, inclusive, set bytes[i − offset] to ! GetValueFromBuffer(esArrayBuffer, i, Uint8, true, Unordered). for (u64 i = offset; i <= offset + length - 1; ++i) { auto value = es_array_buffer->get_value(i, true, JS::ArrayBuffer::Unordered); - bytes.value()[i - offset] = (u8)value.as_u32(); + bytes[i - offset] = (u8)value.as_u32(); } // 10. Return bytes. - return bytes.release_value(); + return bytes; } // https://webidl.spec.whatwg.org/#invoke-a-callback-function diff --git a/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.h b/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.h index 439283ae5c..8efaabaf7c 100644 --- a/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.h +++ b/Userland/Libraries/LibWeb/Bindings/IDLAbstractOperations.h @@ -16,7 +16,7 @@ namespace Web::Bindings::IDL { -Optional get_buffer_source_copy(JS::Object const& buffer_source); +ErrorOr get_buffer_source_copy(JS::Object const& buffer_source); // https://webidl.spec.whatwg.org/#call-user-object-operation-return inline JS::Completion clean_up_on_return(HTML::EnvironmentSettingsObject& stored_settings, HTML::EnvironmentSettingsObject& relevant_settings, JS::Completion& completion) diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp index 0a19c0d0ad..31af44c7a8 100644 --- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp @@ -22,13 +22,14 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handleglobal_object(), DOM::OperationError::create("Failed to copy bytes from ArrayBuffer")); auto* promise = JS::Promise::create(global_object); promise->reject(error); return promise; } + auto& data_buffer = data_buffer_or_error.value(); // 3. Let normalizedAlgorithm be the result of normalizing an algorithm, with alg set to algorithm and op set to "digest". // FIXME: This is way more generic than it needs to be right now, so we simplify it. @@ -60,7 +61,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle TextDecoder::decode(JS::Handle const& input { // FIXME: Implement the streaming stuff. - auto data_buffer = Bindings::IDL::get_buffer_source_copy(*input.cell()); - if (!data_buffer.has_value()) + auto data_buffer_or_error = Bindings::IDL::get_buffer_source_copy(*input.cell()); + if (data_buffer_or_error.is_error()) return DOM::OperationError::create("Failed to copy bytes from ArrayBuffer"); - - return m_decoder.to_utf8({ data_buffer->data(), data_buffer->size() }); + auto& data_buffer = data_buffer_or_error.value(); + return m_decoder.to_utf8({ data_buffer.data(), data_buffer.size() }); } } diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp index 880e0b3b88..9e1815511a 100644 --- a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp +++ b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp @@ -71,10 +71,8 @@ ErrorOr Blob::process_blob_parts(Vector const& blob_parts) }, // 2. If element is a BufferSource, get a copy of the bytes held by the buffer source, and append those bytes to bytes. [&](JS::Handle const& buffer_source) -> ErrorOr { - auto data_buffer = Bindings::IDL::get_buffer_source_copy(*buffer_source.cell()); - if (data_buffer.has_value()) - return bytes.try_append(data_buffer->bytes()); - return {}; + auto data_buffer = TRY(Bindings::IDL::get_buffer_source_copy(*buffer_source.cell())); + return bytes.try_append(data_buffer.bytes()); }, // 3. If element is a Blob, append the bytes it represents to bytes. [&](NonnullRefPtr const& blob) -> ErrorOr {