LibJS: Stop propagating small OOM errors from the Error object

This commit is contained in:
Timothy Flynn 2023-09-06 08:18:01 -04:00 committed by Tim Flynn
parent df915f8a98
commit 54d1f4e234
17 changed files with 68 additions and 77 deletions

View file

@ -347,17 +347,17 @@ ThrowCompletionOr<void> NewRegExp::execute_impl(Bytecode::Interpreter& interpret
return {};
}
#define JS_DEFINE_NEW_BUILTIN_ERROR_OP(ErrorName) \
ThrowCompletionOr<void> 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<void> 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)

View file

@ -5,12 +5,12 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StringBuilder.h>
#include <LibJS/AST.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/ExecutionContext.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/ThrowableStringBuilder.h>
#include <LibJS/SourceRange.h>
namespace JS {
@ -44,9 +44,9 @@ NonnullGCPtr<Error> Error::create(Realm& realm, String message)
return error;
}
ThrowCompletionOr<NonnullGCPtr<Error>> Error::create(Realm& realm, StringView message)
NonnullGCPtr<Error> 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<String> 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<String> 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 == "<unknown>"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() ? "<unknown>"sv : function_name.view()));
stack_string_builder.appendff(" at {}\n", function_name.is_empty() ? "<unknown>"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<String> Error::stack_string(VM& vm) const
return error; \
} \
\
ThrowCompletionOr<NonnullGCPtr<ClassName>> ClassName::create(Realm& realm, StringView message) \
NonnullGCPtr<ClassName> 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) \

View file

@ -28,11 +28,11 @@ class Error : public Object {
public:
static NonnullGCPtr<Error> create(Realm&);
static NonnullGCPtr<Error> create(Realm&, String message);
static ThrowCompletionOr<NonnullGCPtr<Error>> create(Realm&, StringView message);
static NonnullGCPtr<Error> create(Realm&, StringView message);
virtual ~Error() override = default;
[[nodiscard]] ThrowCompletionOr<String> stack_string(VM&) const;
[[nodiscard]] String stack_string() const;
ThrowCompletionOr<void> 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<ClassName> create(Realm&); \
static NonnullGCPtr<ClassName> create(Realm&, String message); \
static ThrowCompletionOr<NonnullGCPtr<ClassName>> 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<ClassName> create(Realm&); \
static NonnullGCPtr<ClassName> create(Realm&, String message); \
static NonnullGCPtr<ClassName> create(Realm&, StringView message); \
\
explicit ClassName(Object& prototype); \
virtual ~ClassName() override = default; \
};
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \

View file

@ -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

View file

@ -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<Value> {
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);

View file

@ -26,7 +26,7 @@ class PromiseResolvingFunction final : public NativeFunction {
JS_OBJECT(PromiseResolvingFunction, NativeFunction);
public:
using FunctionType = Function<ThrowCompletionOr<Value>(VM&, Promise&, AlreadyResolved&)>;
using FunctionType = Function<Value(VM&, Promise&, AlreadyResolved&)>;
static NonnullGCPtr<PromiseResolvingFunction> create(Realm&, Promise&, AlreadyResolved&, FunctionType);

View file

@ -106,7 +106,7 @@ VM::VM(OwnPtr<CustomData> 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<Value> {

View file

@ -178,10 +178,7 @@ public:
auto& realm = *current_realm();
auto completion = T::create(realm, forward<Args>(args)...);
if constexpr (IsSame<decltype(completion), ThrowCompletionOr<NonnullGCPtr<T>>>)
return JS::throw_completion(MUST_OR_THROW_OOM(completion));
else
return JS::throw_completion(completion);
return JS::throw_completion(completion);
}
template<typename T, typename... Args>

View file

@ -458,7 +458,7 @@ inline JSFileResult TestRunner::run_file_test(DeprecatedString const& test_path)
if (is<JS::Error>(error_object)) {
auto& error_as_error = static_cast<JS::Error&>(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();

View file

@ -155,7 +155,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> 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<JS::Promise>(*promise_capability->promise().ptr()) };
}

View file

@ -105,7 +105,7 @@ JS::NonnullGCPtr<JS::Promise> 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;
}

View file

@ -397,7 +397,7 @@ WebIDL::ExceptionOr<void> 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<void> 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<void> readable_byte_stream_controller_close(ReadableByteStre
// 2. If firstPendingPullIntos 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<void> 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<void> readable_byte_stream_controller_enqueue(ReadableByteSt
// 2. If ! IsDetachedBuffer(firstPendingPullIntos 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<JS::NonnullGCPtr<WebIDL::Promise>> 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<void> 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<JS::NonnullGCPtr<WebIDL::Promise>> 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<JS::NonnullGCPtr<WebIDL::Promise>> 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<void> 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));

View file

@ -84,7 +84,7 @@ WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> 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();
}

View file

@ -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<JS::Uint8Array>(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<JS::NonnullGCPtr<JS::Promise>> 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<JS::Promise>(*promise_capability->promise()) };
}

View file

@ -26,7 +26,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> 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<JS::Promise>(*promise_capability->promise().ptr()) };
}

View file

@ -62,13 +62,13 @@ WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> 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<JS::GCPtr<JS::Object>> 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();
}

View file

@ -56,7 +56,7 @@ WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> 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<JS::GCPtr<JS::Object>> 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<JS::GCPtr<JS::Object>> 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();
}