WritableStreamDefaultController.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. JS_DEFINE_ALLOCATOR(WritableStreamDefaultController);
  11. void WritableStreamDefaultController::visit_edges(Visitor& visitor)
  12. {
  13. Base::visit_edges(visitor);
  14. visitor.visit(m_signal);
  15. for (auto& value : m_queue)
  16. visitor.visit(value.value);
  17. visitor.visit(m_stream);
  18. visitor.visit(m_abort_algorithm);
  19. visitor.visit(m_close_algorithm);
  20. visitor.visit(m_strategy_size_algorithm);
  21. visitor.visit(m_write_algorithm);
  22. }
  23. // https://streams.spec.whatwg.org/#ws-default-controller-error
  24. WebIDL::ExceptionOr<void> WritableStreamDefaultController::error(JS::Value error)
  25. {
  26. // 1. Let state be this.[[stream]].[[state]].
  27. auto state = m_stream->state();
  28. // 2. If state is not "writable", return.
  29. if (state != WritableStream::State::Writable)
  30. return {};
  31. // 3. Perform ! WritableStreamDefaultControllerError(this, e).
  32. return writable_stream_default_controller_error(*this, error);
  33. }
  34. // https://streams.spec.whatwg.org/#ws-default-controller-private-abort
  35. WebIDL::ExceptionOr<JS::GCPtr<WebIDL::Promise>> WritableStreamDefaultController::abort_steps(JS::Value reason)
  36. {
  37. // 1. Let result be the result of performing this.[[abortAlgorithm]], passing reason.
  38. auto result = TRY(m_abort_algorithm->function()(reason));
  39. // 2. Perform ! WritableStreamDefaultControllerClearAlgorithms(this).
  40. writable_stream_default_controller_clear_algorithms(*this);
  41. // 3. Return result.
  42. return result;
  43. }
  44. // https://streams.spec.whatwg.org/#ws-default-controller-private-error
  45. void WritableStreamDefaultController::error_steps()
  46. {
  47. // 1. Perform ! ResetQueue(this).
  48. reset_queue(*this);
  49. }
  50. WritableStreamDefaultController::WritableStreamDefaultController(JS::Realm& realm)
  51. : Bindings::PlatformObject(realm)
  52. {
  53. }
  54. }