ByteLengthQueuingStrategy.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/ByteLengthQueuingStrategyPrototype.h>
  8. #include <LibWeb/Bindings/Intrinsics.h>
  9. #include <LibWeb/HTML/Window.h>
  10. #include <LibWeb/Streams/ByteLengthQueuingStrategy.h>
  11. #include <LibWeb/WebIDL/ExceptionOr.h>
  12. namespace Web::Streams {
  13. JS_DEFINE_ALLOCATOR(ByteLengthQueuingStrategy);
  14. // https://streams.spec.whatwg.org/#blqs-constructor
  15. WebIDL::ExceptionOr<JS::NonnullGCPtr<ByteLengthQueuingStrategy>> ByteLengthQueuingStrategy::construct_impl(JS::Realm& realm, QueuingStrategyInit const& init)
  16. {
  17. // The new ByteLengthQueuingStrategy(init) constructor steps are:
  18. // 1. Set this.[[highWaterMark]] to init["highWaterMark"].
  19. return realm.heap().allocate<ByteLengthQueuingStrategy>(realm, realm, init.high_water_mark);
  20. }
  21. ByteLengthQueuingStrategy::ByteLengthQueuingStrategy(JS::Realm& realm, double high_water_mark)
  22. : PlatformObject(realm)
  23. , m_high_water_mark(high_water_mark)
  24. {
  25. }
  26. ByteLengthQueuingStrategy::~ByteLengthQueuingStrategy() = default;
  27. // https://streams.spec.whatwg.org/#blqs-size
  28. WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::CallbackType>> ByteLengthQueuingStrategy::size()
  29. {
  30. // 1. Return this's relevant global object's byte length queuing strategy size function.
  31. return global_object().byte_length_queuing_strategy_size_function();
  32. }
  33. void ByteLengthQueuingStrategy::initialize(JS::Realm& realm)
  34. {
  35. Base::initialize(realm);
  36. WEB_SET_PROTOTYPE_FOR_INTERFACE(ByteLengthQueuingStrategy);
  37. }
  38. }