WritableStreamDefaultController.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Streams/WritableStream.h>
  7. #include <LibWeb/Streams/WritableStreamDefaultController.h>
  8. namespace Web::Streams {
  9. // https://streams.spec.whatwg.org/#ws-default-controller-error
  10. WebIDL::ExceptionOr<void> WritableStreamDefaultController::error(JS::Value error)
  11. {
  12. // 1. Let state be this.[[stream]].[[state]].
  13. auto state = m_stream->state();
  14. // 2. If state is not "writable", return.
  15. if (state != WritableStream::State::Writable)
  16. return {};
  17. // 3. Perform ! WritableStreamDefaultControllerError(this, e).
  18. return writable_stream_default_controller_error(*this, error);
  19. }
  20. // https://streams.spec.whatwg.org/#ws-default-controller-private-abort
  21. WebIDL::ExceptionOr<JS::GCPtr<WebIDL::Promise>> WritableStreamDefaultController::abort_steps(JS::Value reason)
  22. {
  23. // 1. Let result be the result of performing this.[[abortAlgorithm]], passing reason.
  24. auto result = TRY((*m_abort_algorithm)(reason));
  25. // 2. Perform ! WritableStreamDefaultControllerClearAlgorithms(this).
  26. writable_stream_default_controller_clear_algorithms(*this);
  27. // 3. Return result.
  28. return result;
  29. }
  30. // https://streams.spec.whatwg.org/#ws-default-controller-private-error
  31. void WritableStreamDefaultController::error_steps()
  32. {
  33. // 1. Perform ! ResetQueue(this).
  34. reset_queue(*this);
  35. }
  36. WritableStreamDefaultController::WritableStreamDefaultController(JS::Realm& realm)
  37. : Bindings::PlatformObject(realm)
  38. {
  39. }
  40. }