1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:27:45 +00:00

LibWeb: Implement WritableStreamDefaultWriter.write()

This commit is contained in:
Matthew Olsson 2023-04-09 15:21:58 -07:00 committed by Linus Groh
parent 48b67e41f0
commit 58f3009faa
5 changed files with 163 additions and 3 deletions

View file

@ -103,6 +103,21 @@ WebIDL::ExceptionOr<void> WritableStreamDefaultWriter::release_lock()
return writable_stream_default_writer_release(*this);
}
// https://streams.spec.whatwg.org/#default-writer-write
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> WritableStreamDefaultWriter::write(JS::Value chunk)
{
auto& realm = this->realm();
// 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));
return WebIDL::create_rejected_promise(realm, exception)->promise();
}
// 2. Return ! WritableStreamDefaultWriterWrite(this, chunk).
return TRY(writable_stream_default_writer_write(*this, chunk))->promise();
}
WritableStreamDefaultWriter::WritableStreamDefaultWriter(JS::Realm& realm)
: Bindings::PlatformObject(realm)
{