UniversalGlobalScope.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
  3. * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
  4. * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/Forward.h>
  10. #include <AK/String.h>
  11. #include <LibJS/Runtime/Value.h>
  12. #include <LibWeb/Forward.h>
  13. #include <LibWeb/HTML/Scripting/ImportMap.h>
  14. #include <LibWeb/WebIDL/ExceptionOr.h>
  15. namespace Web::HTML {
  16. // https://whatpr.org/html/9893/webappapis.html#universalglobalscope-mixin
  17. class UniversalGlobalScopeMixin {
  18. public:
  19. virtual ~UniversalGlobalScopeMixin();
  20. virtual DOM::EventTarget& this_impl() = 0;
  21. virtual DOM::EventTarget const& this_impl() const = 0;
  22. WebIDL::ExceptionOr<String> btoa(String const& data) const;
  23. WebIDL::ExceptionOr<String> atob(String const& data) const;
  24. void queue_microtask(WebIDL::CallbackType&);
  25. WebIDL::ExceptionOr<JS::Value> structured_clone(JS::Value, StructuredSerializeOptions const&) const;
  26. GC::Ref<WebIDL::CallbackType> count_queuing_strategy_size_function();
  27. GC::Ref<WebIDL::CallbackType> byte_length_queuing_strategy_size_function();
  28. void push_onto_outstanding_rejected_promises_weak_set(JS::Promise*);
  29. // Returns true if removed, false otherwise.
  30. bool remove_from_outstanding_rejected_promises_weak_set(JS::Promise*);
  31. void push_onto_about_to_be_notified_rejected_promises_list(GC::Ref<JS::Promise>);
  32. // Returns true if removed, false otherwise.
  33. bool remove_from_about_to_be_notified_rejected_promises_list(GC::Ref<JS::Promise>);
  34. void notify_about_rejected_promises(Badge<EventLoop>);
  35. protected:
  36. void visit_edges(GC::Cell::Visitor&);
  37. private:
  38. // https://streams.spec.whatwg.org/#count-queuing-strategy-size-function
  39. GC::Ptr<WebIDL::CallbackType> m_count_queuing_strategy_size_function;
  40. // https://streams.spec.whatwg.org/#byte-length-queuing-strategy-size-function
  41. GC::Ptr<WebIDL::CallbackType> m_byte_length_queuing_strategy_size_function;
  42. // https://html.spec.whatwg.org/multipage/webappapis.html#about-to-be-notified-rejected-promises-list
  43. Vector<GC::Root<JS::Promise>> m_about_to_be_notified_rejected_promises_list;
  44. // https://html.spec.whatwg.org/multipage/webappapis.html#outstanding-rejected-promises-weak-set
  45. // The outstanding rejected promises weak set must not create strong references to any of its members, and implementations are free to limit its size, e.g. by removing old entries from it when new ones are added.
  46. Vector<GC::Ptr<JS::Promise>> m_outstanding_rejected_promises_weak_set;
  47. };
  48. }