WritableStreamDefaultController.cpp 1.8 KB

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