From 54d1f4e234fb3f28b269fb14d7a7461736992007 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 6 Sep 2023 08:18:01 -0400 Subject: [PATCH] LibJS: Stop propagating small OOM errors from the Error object --- Userland/Libraries/LibJS/Bytecode/Op.cpp | 22 ++++++++-------- Userland/Libraries/LibJS/Runtime/Error.cpp | 22 ++++++++-------- Userland/Libraries/LibJS/Runtime/Error.h | 26 +++++++++---------- .../LibJS/Runtime/ErrorPrototype.cpp | 6 ++--- Userland/Libraries/LibJS/Runtime/Promise.cpp | 4 +-- .../LibJS/Runtime/PromiseResolvingFunction.h | 2 +- Userland/Libraries/LibJS/Runtime/VM.cpp | 2 +- Userland/Libraries/LibJS/Runtime/VM.h | 5 +--- .../Libraries/LibTest/JavaScriptTestRunner.h | 2 +- Userland/Libraries/LibWeb/Fetch/Body.cpp | 2 +- .../Libraries/LibWeb/Fetch/FetchMethod.cpp | 2 +- .../LibWeb/Streams/AbstractOperations.cpp | 22 ++++++++-------- .../LibWeb/Streams/ReadableStream.cpp | 2 +- .../Streams/ReadableStreamDefaultReader.cpp | 10 ++----- .../Streams/ReadableStreamGenericReader.cpp | 2 +- .../LibWeb/Streams/WritableStream.cpp | 6 ++--- .../Streams/WritableStreamDefaultWriter.cpp | 8 +++--- 17 files changed, 68 insertions(+), 77 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index b3b312eccc..e660da5f1b 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -347,17 +347,17 @@ ThrowCompletionOr NewRegExp::execute_impl(Bytecode::Interpreter& interpret return {}; } -#define JS_DEFINE_NEW_BUILTIN_ERROR_OP(ErrorName) \ - ThrowCompletionOr New##ErrorName::execute_impl(Bytecode::Interpreter& interpreter) const \ - { \ - auto& vm = interpreter.vm(); \ - auto& realm = *vm.current_realm(); \ - interpreter.accumulator() = MUST_OR_THROW_OOM(ErrorName::create(realm, interpreter.current_executable().get_string(m_error_string))); \ - return {}; \ - } \ - DeprecatedString New##ErrorName::to_deprecated_string_impl(Bytecode::Executable const& executable) const \ - { \ - return DeprecatedString::formatted("New" #ErrorName " {} (\"{}\")", m_error_string, executable.string_table->get(m_error_string)); \ +#define JS_DEFINE_NEW_BUILTIN_ERROR_OP(ErrorName) \ + ThrowCompletionOr New##ErrorName::execute_impl(Bytecode::Interpreter& interpreter) const \ + { \ + auto& vm = interpreter.vm(); \ + auto& realm = *vm.current_realm(); \ + interpreter.accumulator() = ErrorName::create(realm, interpreter.current_executable().get_string(m_error_string)); \ + return {}; \ + } \ + DeprecatedString New##ErrorName::to_deprecated_string_impl(Bytecode::Executable const& executable) const \ + { \ + return DeprecatedString::formatted("New" #ErrorName " {} (\"{}\")", m_error_string, executable.string_table->get(m_error_string)); \ } JS_ENUMERATE_NEW_BUILTIN_ERROR_OPS(JS_DEFINE_NEW_BUILTIN_ERROR_OP) diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp index 3755ffde90..e8d0368653 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.cpp +++ b/Userland/Libraries/LibJS/Runtime/Error.cpp @@ -5,12 +5,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include #include #include -#include #include namespace JS { @@ -44,9 +44,9 @@ NonnullGCPtr Error::create(Realm& realm, String message) return error; } -ThrowCompletionOr> Error::create(Realm& realm, StringView message) +NonnullGCPtr Error::create(Realm& realm, StringView message) { - return create(realm, TRY_OR_THROW_OOM(realm.vm(), String::from_utf8(message))); + return create(realm, MUST(String::from_utf8(message))); } Error::Error(Object& prototype) @@ -95,9 +95,9 @@ void Error::populate_stack() } } -ThrowCompletionOr Error::stack_string(VM& vm) const +String Error::stack_string() const { - ThrowableStringBuilder stack_string_builder(vm); + StringBuilder stack_string_builder; // Note: We roughly follow V8's formatting // Note: The error's name and message get prepended by ErrorPrototype::stack @@ -111,15 +111,15 @@ ThrowCompletionOr Error::stack_string(VM& vm) const if (!source_range.filename().is_empty() || source_range.start.offset != 0 || source_range.end.offset != 0) { if (function_name == ""sv) - MUST_OR_THROW_OOM(stack_string_builder.appendff(" at {}:{}:{}\n", source_range.filename(), source_range.start.line, source_range.start.column)); + stack_string_builder.appendff(" at {}:{}:{}\n", source_range.filename(), source_range.start.line, source_range.start.column); else - MUST_OR_THROW_OOM(stack_string_builder.appendff(" at {} ({}:{}:{})\n", function_name, source_range.filename(), source_range.start.line, source_range.start.column)); + stack_string_builder.appendff(" at {} ({}:{}:{})\n", function_name, source_range.filename(), source_range.start.line, source_range.start.column); } else { - MUST_OR_THROW_OOM(stack_string_builder.appendff(" at {}\n", function_name.is_empty() ? ""sv : function_name.view())); + stack_string_builder.appendff(" at {}\n", function_name.is_empty() ? ""sv : function_name.view()); } } - return stack_string_builder.to_string(); + return MUST(stack_string_builder.to_string()); } #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ @@ -137,9 +137,9 @@ ThrowCompletionOr Error::stack_string(VM& vm) const return error; \ } \ \ - ThrowCompletionOr> ClassName::create(Realm& realm, StringView message) \ + NonnullGCPtr ClassName::create(Realm& realm, StringView message) \ { \ - return create(realm, TRY_OR_THROW_OOM(realm.vm(), String::from_utf8(message))); \ + return create(realm, MUST(String::from_utf8(message))); \ } \ \ ClassName::ClassName(Object& prototype) \ diff --git a/Userland/Libraries/LibJS/Runtime/Error.h b/Userland/Libraries/LibJS/Runtime/Error.h index a1f68eb8aa..a93ad03f98 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.h +++ b/Userland/Libraries/LibJS/Runtime/Error.h @@ -28,11 +28,11 @@ class Error : public Object { public: static NonnullGCPtr create(Realm&); static NonnullGCPtr create(Realm&, String message); - static ThrowCompletionOr> create(Realm&, StringView message); + static NonnullGCPtr create(Realm&, StringView message); virtual ~Error() override = default; - [[nodiscard]] ThrowCompletionOr stack_string(VM&) const; + [[nodiscard]] String stack_string() const; ThrowCompletionOr install_error_cause(Value options); @@ -49,17 +49,17 @@ private: // NOTE: Making these inherit from Error is not required by the spec but // our way of implementing the [[ErrorData]] internal slot, which is // used in Object.prototype.toString(). -#define DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName) \ - class ClassName final : public Error { \ - JS_OBJECT(ClassName, Error); \ - \ - public: \ - static NonnullGCPtr create(Realm&); \ - static NonnullGCPtr create(Realm&, String message); \ - static ThrowCompletionOr> create(Realm&, StringView message); \ - \ - explicit ClassName(Object& prototype); \ - virtual ~ClassName() override = default; \ +#define DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName) \ + class ClassName final : public Error { \ + JS_OBJECT(ClassName, Error); \ + \ + public: \ + static NonnullGCPtr create(Realm&); \ + static NonnullGCPtr create(Realm&, String message); \ + static NonnullGCPtr create(Realm&, StringView message); \ + \ + explicit ClassName(Object& prototype); \ + virtual ~ClassName() override = default; \ }; #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ diff --git a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp index 6d8c197e13..fd5828c3b3 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp @@ -65,7 +65,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string) return PrimitiveString::create(vm, move(name)); // 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE), and msg. - return PrimitiveString::create(vm, TRY_OR_THROW_OOM(vm, String::formatted("{}: {}", name, message))); + return PrimitiveString::create(vm, MUST(String::formatted("{}: {}", name, message))); } // B.1.1 get Error.prototype.stack ( ), https://tc39.es/proposal-error-stacks/#sec-get-error.prototype-stack @@ -96,9 +96,9 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_getter) auto header = message.is_empty() ? move(name) - : TRY_OR_THROW_OOM(vm, String::formatted("{}: {}", name, message)); + : MUST(String::formatted("{}: {}", name, message)); - return PrimitiveString::create(vm, TRY_OR_THROW_OOM(vm, String::formatted("{}\n{}", header, MUST_OR_THROW_OOM(error.stack_string(vm))))); + return PrimitiveString::create(vm, MUST(String::formatted("{}\n{}", header, error.stack_string()))); } // B.1.2 set Error.prototype.stack ( value ), https://tc39.es/proposal-error-stacks/#sec-set-error.prototype-stack diff --git a/Userland/Libraries/LibJS/Runtime/Promise.cpp b/Userland/Libraries/LibJS/Runtime/Promise.cpp index 51eb1f078f..c2809a0122 100644 --- a/Userland/Libraries/LibJS/Runtime/Promise.cpp +++ b/Userland/Libraries/LibJS/Runtime/Promise.cpp @@ -71,7 +71,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions() // 6. Set resolve.[[AlreadyResolved]] to alreadyResolved. // 27.2.1.3.2 Promise Resolve Functions, https://tc39.es/ecma262/#sec-promise-resolve-functions - auto resolve_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto& promise, auto& already_resolved) -> ThrowCompletionOr { + auto resolve_function = PromiseResolvingFunction::create(realm, *this, *already_resolved, [](auto& vm, auto& promise, auto& already_resolved) { dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Resolve function was called", &promise); auto& realm = *vm.current_realm(); @@ -97,7 +97,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions() dbgln_if(PROMISE_DEBUG, "[Promise @ {} / PromiseResolvingFunction]: Promise can't be resolved with itself, rejecting with error", &promise); // a. Let selfResolutionError be a newly created TypeError object. - auto self_resolution_error = MUST_OR_THROW_OOM(TypeError::create(realm, "Cannot resolve promise with itself"sv)); + auto self_resolution_error = TypeError::create(realm, "Cannot resolve promise with itself"sv); // b. Perform RejectPromise(promise, selfResolutionError). promise.reject(self_resolution_error); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h index e73e550b4d..245d5baaa0 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h +++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.h @@ -26,7 +26,7 @@ class PromiseResolvingFunction final : public NativeFunction { JS_OBJECT(PromiseResolvingFunction, NativeFunction); public: - using FunctionType = Function(VM&, Promise&, AlreadyResolved&)>; + using FunctionType = Function; static NonnullGCPtr create(Realm&, Promise&, AlreadyResolved&, FunctionType); diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index a3b512b6d2..f23985ec58 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -106,7 +106,7 @@ VM::VM(OwnPtr custom_data, ErrorMessages error_messages) // If you are here because you want to enable dynamic module importing make sure it won't be a security problem // by checking the default implementation of HostImportModuleDynamically and creating your own hook or calling // vm.enable_default_host_import_module_dynamically_hook(). - promise->reject(MUST_OR_THROW_OOM(Error::create(realm, ErrorType::DynamicImportNotAllowed.message()))); + promise->reject(Error::create(realm, ErrorType::DynamicImportNotAllowed.message())); promise->perform_then( NativeFunction::create(realm, "", [](auto&) -> ThrowCompletionOr { diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 2f4321bf4e..f515d7e7d1 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -178,10 +178,7 @@ public: auto& realm = *current_realm(); auto completion = T::create(realm, forward(args)...); - if constexpr (IsSame>>) - return JS::throw_completion(MUST_OR_THROW_OOM(completion)); - else - return JS::throw_completion(completion); + return JS::throw_completion(completion); } template diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h index 8d204ca8ec..3e59b1cd84 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h +++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h @@ -458,7 +458,7 @@ inline JSFileResult TestRunner::run_file_test(DeprecatedString const& test_path) if (is(error_object)) { auto& error_as_error = static_cast(error_object); detail_builder.append('\n'); - detail_builder.append(error_as_error.stack_string(*g_vm).release_allocated_value_but_fixme_should_propagate_errors()); + detail_builder.append(error_as_error.stack_string()); } test_case.details = detail_builder.to_deprecated_string(); diff --git a/Userland/Libraries/LibWeb/Fetch/Body.cpp b/Userland/Libraries/LibWeb/Fetch/Body.cpp index 5dece554d8..ac15e6f18d 100644 --- a/Userland/Libraries/LibWeb/Fetch/Body.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Body.cpp @@ -155,7 +155,7 @@ WebIDL::ExceptionOr> consume_body(JS::Realm& realm { // 1. If object is unusable, then return a promise rejected with a TypeError. if (object.is_unusable()) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Body is unusable"sv)); + auto exception = JS::TypeError::create(realm, "Body is unusable"sv); auto promise_capability = WebIDL::create_rejected_promise(realm, exception); return JS::NonnullGCPtr { verify_cast(*promise_capability->promise().ptr()) }; } diff --git a/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp b/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp index fdabd3149b..9cfe0a3df9 100644 --- a/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp +++ b/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp @@ -105,7 +105,7 @@ JS::NonnullGCPtr fetch(JS::VM& vm, RequestInfo const& input, Reques // 3. If response is a network error, then reject p with a TypeError and abort these steps. if (response->is_network_error()) { auto message = response->network_error_message().value_or("Response is a network error"sv); - WebIDL::reject_promise(relevant_realm, promise_capability, JS::TypeError::create(relevant_realm, message).release_allocated_value_but_fixme_should_propagate_errors()); + WebIDL::reject_promise(relevant_realm, promise_capability, JS::TypeError::create(relevant_realm, message)); return; } diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp index 1e9b8fe437..df425411cc 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -397,7 +397,7 @@ WebIDL::ExceptionOr readable_stream_reader_generic_release(ReadableStreamG auto& realm = stream->realm(); // 4. If stream.[[state]] is "readable", reject reader.[[closedPromise]] with a TypeError exception. - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Released readable stream"sv)); + auto exception = JS::TypeError::create(realm, "Released readable stream"sv); if (stream->is_readable()) { WebIDL::reject_promise(realm, *reader.closed_promise_capability(), exception); } @@ -497,7 +497,7 @@ WebIDL::ExceptionOr readable_stream_default_reader_release(ReadableStreamD TRY(readable_stream_reader_generic_release(reader)); // 2. Let e be a new TypeError exception. - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Reader has been released"sv)); + auto exception = JS::TypeError::create(realm, "Reader has been released"sv); // 3. Perform ! ReadableStreamDefaultReaderErrorReadRequests(reader, e). readable_stream_default_reader_error_read_requests(reader, exception); @@ -514,7 +514,7 @@ void readable_stream_byob_reader_release(ReadableStreamBYOBReader& reader) MUST(readable_stream_reader_generic_release(reader)); // 2. Let e be a new TypeError exception. - auto exception = MUST(JS::TypeError::create(realm, "Reader has been released"sv)); + auto exception = JS::TypeError::create(realm, "Reader has been released"sv); // 3. Perform ! ReadableStreamBYOBReaderErrorReadIntoRequests(reader, e). readable_stream_byob_reader_error_read_into_requests(reader, exception); @@ -1023,7 +1023,7 @@ WebIDL::ExceptionOr readable_byte_stream_controller_close(ReadableByteStre // 2. If firstPendingPullInto’s bytes filled > 0, if (first_pending_pull_into.bytes_filled > 0) { // 1. Let e be a new TypeError exception. - auto error = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot close controller in the middle of processing a write request"sv)); + auto error = JS::TypeError::create(realm, "Cannot close controller in the middle of processing a write request"sv); // 2. Perform ! ReadableByteStreamControllerError(controller, e). readable_byte_stream_controller_error(controller, error); @@ -1525,7 +1525,7 @@ WebIDL::ExceptionOr readable_byte_stream_controller_enqueue(ReadableByteSt // 6. If ! IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (buffer->is_detached()) { - auto error = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Buffer is detached"sv)); + auto error = JS::TypeError::create(realm, "Buffer is detached"sv); return JS::throw_completion(error); } @@ -1539,7 +1539,7 @@ WebIDL::ExceptionOr readable_byte_stream_controller_enqueue(ReadableByteSt // 2. If ! IsDetachedBuffer(firstPendingPullInto’s buffer) is true, throw a TypeError exception. if (first_pending_pull_into.buffer->is_detached()) { - auto error = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Buffer is detached"sv)); + auto error = JS::TypeError::create(realm, "Buffer is detached"sv); return JS::throw_completion(error); } @@ -1836,7 +1836,7 @@ WebIDL::ExceptionOr> writable_stream_close(Wri // 2. If state is "closed" or "errored", return a promise rejected with a TypeError exception. if (state == WritableStream::State::Closed || state == WritableStream::State::Errored) { auto message = state == WritableStream::State::Closed ? "Cannot close a closed stream"sv : "Cannot close an errored stream"sv; - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, message)); + auto exception = JS::TypeError::create(realm, message); return WebIDL::create_rejected_promise(realm, exception); } @@ -2362,7 +2362,7 @@ WebIDL::ExceptionOr writable_stream_default_writer_release(WritableStreamD VERIFY(stream->writer().ptr() == &writer); // 4. Let releasedError be a new TypeError. - auto released_error = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Writer's stream lock has been released"sv)); + auto released_error = JS::TypeError::create(realm, "Writer's stream lock has been released"sv); // 5. Perform ! WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError). writable_stream_default_writer_ensure_ready_promise_rejected(writer, released_error); @@ -2398,7 +2398,7 @@ WebIDL::ExceptionOr> writable_stream_default_w // 5. If stream is not equal to writer.[[stream]], return a promise rejected with a TypeError exception. if (stream.ptr() != writer.stream().ptr()) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Writer's locked stream changed during write"sv)); + auto exception = JS::TypeError::create(realm, "Writer's locked stream changed during write"sv); return WebIDL::create_rejected_promise(realm, exception); } @@ -2411,7 +2411,7 @@ WebIDL::ExceptionOr> writable_stream_default_w // 8. If ! WritableStreamCloseQueuedOrInFlight(stream) is true or state is "closed", return a promise rejected with a TypeError exception indicating that the stream is closing or closed. if (writable_stream_close_queued_or_in_flight(*stream) || state == WritableStream::State::Closed) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot write to a writer whose stream is closing or already closed"sv)); + auto exception = JS::TypeError::create(realm, "Cannot write to a writer whose stream is closing or already closed"sv); return WebIDL::create_rejected_promise(realm, exception); } @@ -3085,7 +3085,7 @@ WebIDL::ExceptionOr transform_stream_default_controller_terminate(Transfor readable_stream_default_controller_close(readable_controller); // 4. Let error be a TypeError exception indicating that the stream has been terminated. - auto error = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Stream has been terminated."sv)); + auto error = JS::TypeError::create(realm, "Stream has been terminated."sv); // 5. Perform ! TransformStreamErrorWritableAndUnblockWrite(stream, error). TRY(transform_stream_error_writable_and_unblock_write(*stream, error)); diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp index b695c27faa..41af767116 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp +++ b/Userland/Libraries/LibWeb/Streams/ReadableStream.cpp @@ -84,7 +84,7 @@ WebIDL::ExceptionOr> ReadableStream::cancel(JS::Value reas // 1. If ! IsReadableStreamLocked(this) is true, return a promise rejected with a TypeError exception. if (is_readable_stream_locked(*this)) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot cancel a locked stream"sv)); + auto exception = JS::TypeError::create(realm, "Cannot cancel a locked stream"sv); return WebIDL::create_rejected_promise(realm, JS::Value { exception })->promise(); } diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultReader.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultReader.cpp index 4274a4064f..255e4d667c 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultReader.cpp +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamDefaultReader.cpp @@ -76,13 +76,7 @@ void ReadLoopReadRequest::on_chunk(JS::Value chunk) { // 1. If chunk is not a Uint8Array object, call failureSteps with a TypeError and abort these steps. if (!chunk.is_object() || !is(chunk.as_object())) { - auto exception = JS::TypeError::create(m_realm, "Chunk data is not Uint8Array"sv); - if (exception.is_error()) { - m_failure_steps(*exception.release_error().value()); - return; - } - - m_failure_steps(exception.value()); + m_failure_steps(JS::TypeError::create(m_realm, "Chunk data is not Uint8Array"sv)); return; } @@ -162,7 +156,7 @@ WebIDL::ExceptionOr> ReadableStreamDefaultReader:: // 1. If this.[[stream]] is undefined, return a promise rejected with a TypeError exception. if (!m_stream) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot read from an empty stream"sv)); + auto exception = JS::TypeError::create(realm, "Cannot read from an empty stream"sv); auto promise_capability = WebIDL::create_rejected_promise(realm, exception); return JS::NonnullGCPtr { verify_cast(*promise_capability->promise()) }; } diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamGenericReader.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStreamGenericReader.cpp index 20c5ce397f..3e370c531f 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamGenericReader.cpp +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamGenericReader.cpp @@ -26,7 +26,7 @@ WebIDL::ExceptionOr> ReadableStreamGenericReaderMi { // 1. If this.[[stream]] is undefined, return a promise rejected with a TypeError exception. if (!m_stream) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(m_realm, "No stream present to cancel"sv)); + auto exception = JS::TypeError::create(m_realm, "No stream present to cancel"sv); auto promise_capability = WebIDL::create_rejected_promise(m_realm, exception); return JS::NonnullGCPtr { verify_cast(*promise_capability->promise().ptr()) }; } diff --git a/Userland/Libraries/LibWeb/Streams/WritableStream.cpp b/Userland/Libraries/LibWeb/Streams/WritableStream.cpp index 9b1c6ecd53..78d5c9cb42 100644 --- a/Userland/Libraries/LibWeb/Streams/WritableStream.cpp +++ b/Userland/Libraries/LibWeb/Streams/WritableStream.cpp @@ -62,13 +62,13 @@ WebIDL::ExceptionOr> WritableStream::close() // 1. If ! IsWritableStreamLocked(this) is true, return a promise rejected with a TypeError exception. if (is_writable_stream_locked(*this)) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot close a locked stream"sv)); + auto exception = JS::TypeError::create(realm, "Cannot close a locked stream"sv); return WebIDL::create_rejected_promise(realm, exception)->promise(); } // 2. If ! WritableStreamCloseQueuedOrInFlight(this) is true, return a promise rejected with a TypeError exception. if (writable_stream_close_queued_or_in_flight(*this)) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot close a stream that is already closed or errored"sv)); + auto exception = JS::TypeError::create(realm, "Cannot close a stream that is already closed or errored"sv); return WebIDL::create_rejected_promise(realm, exception)->promise(); } @@ -83,7 +83,7 @@ WebIDL::ExceptionOr> WritableStream::abort(JS::Value reaso // 1. If ! IsWritableStreamLocked(this) is true, return a promise rejected with a TypeError exception. if (is_writable_stream_locked(*this)) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot abort a locked stream"sv)); + auto exception = JS::TypeError::create(realm, "Cannot abort a locked stream"sv); return WebIDL::create_rejected_promise(realm, exception)->promise(); } diff --git a/Userland/Libraries/LibWeb/Streams/WritableStreamDefaultWriter.cpp b/Userland/Libraries/LibWeb/Streams/WritableStreamDefaultWriter.cpp index 2ca9c38236..85aa7c9926 100644 --- a/Userland/Libraries/LibWeb/Streams/WritableStreamDefaultWriter.cpp +++ b/Userland/Libraries/LibWeb/Streams/WritableStreamDefaultWriter.cpp @@ -56,7 +56,7 @@ WebIDL::ExceptionOr> WritableStreamDefaultWriter::abort(JS // 1. If this.[[stream]] is undefined, return a promise rejected with a TypeError exception. if (!m_stream) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot abort a writer that has no locked stream"sv)); + auto exception = JS::TypeError::create(realm, "Cannot abort a writer that has no locked stream"sv); return WebIDL::create_rejected_promise(realm, exception)->promise(); } @@ -73,13 +73,13 @@ WebIDL::ExceptionOr> WritableStreamDefaultWriter::close() // 2. If stream is undefined, return a promise rejected with a TypeError exception. if (!m_stream) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot close a writer that has no locked stream"sv)); + auto exception = JS::TypeError::create(realm, "Cannot close a writer that has no locked stream"sv); return WebIDL::create_rejected_promise(realm, exception)->promise(); } // 3. If ! WritableStreamCloseQueuedOrInFlight(stream) is true, return a promise rejected with a TypeError exception. if (writable_stream_close_queued_or_in_flight(*m_stream)) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot close a stream that is already closed or errored"sv)); + auto exception = JS::TypeError::create(realm, "Cannot close a stream that is already closed or errored"sv); return WebIDL::create_rejected_promise(realm, exception)->promise(); } @@ -110,7 +110,7 @@ WebIDL::ExceptionOr> WritableStreamDefaultWriter::write(JS // 1. If this.[[stream]] is undefined, return a promise rejected with a TypeError exception. if (!m_stream) { - auto exception = MUST_OR_THROW_OOM(JS::TypeError::create(realm, "Cannot write to a writer that has no locked stream"sv)); + auto exception = JS::TypeError::create(realm, "Cannot write to a writer that has no locked stream"sv); return WebIDL::create_rejected_promise(realm, exception)->promise(); }