WritableStreamDefaultController.cpp 2.1 KB

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