CountQueuingStrategy.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2023, Shannon Booth <shannon@serenityos.org>
  3. * Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/Bindings/CountQueuingStrategyPrototype.h>
  8. #include <LibWeb/Bindings/Intrinsics.h>
  9. #include <LibWeb/HTML/Window.h>
  10. #include <LibWeb/Streams/CountQueuingStrategy.h>
  11. #include <LibWeb/WebIDL/ExceptionOr.h>
  12. namespace Web::Streams {
  13. // https://streams.spec.whatwg.org/#blqs-constructor
  14. WebIDL::ExceptionOr<JS::NonnullGCPtr<CountQueuingStrategy>> CountQueuingStrategy::construct_impl(JS::Realm& realm, QueuingStrategyInit const& init)
  15. {
  16. // The new CountQueuingStrategy(init) constructor steps are:
  17. // 1. Set this.[[highWaterMark]] to init["highWaterMark"].
  18. return MUST_OR_THROW_OOM(realm.heap().allocate<CountQueuingStrategy>(realm, realm, init.high_water_mark));
  19. }
  20. CountQueuingStrategy::CountQueuingStrategy(JS::Realm& realm, double high_water_mark)
  21. : PlatformObject(realm)
  22. , m_high_water_mark(high_water_mark)
  23. {
  24. }
  25. CountQueuingStrategy::~CountQueuingStrategy() = default;
  26. // https://streams.spec.whatwg.org/#cqs-size
  27. WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::CallbackType>> CountQueuingStrategy::size()
  28. {
  29. // 1. Return this's relevant global object's count queuing strategy size function.
  30. return global_object().count_queuing_strategy_size_function();
  31. }
  32. JS::ThrowCompletionOr<void> CountQueuingStrategy::initialize(JS::Realm& realm)
  33. {
  34. MUST_OR_THROW_OOM(Base::initialize(realm));
  35. set_prototype(&Bindings::ensure_web_prototype<Bindings::CountQueuingStrategyPrototype>(realm, "CountQueuingStrategy"));
  36. return {};
  37. }
  38. }