MainThreadVM.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/NonnullRefPtrVector.h>
  9. #include <LibJS/Forward.h>
  10. #include <LibJS/Runtime/JobCallback.h>
  11. #include <LibJS/Runtime/VM.h>
  12. #include <LibWeb/DOM/MutationObserver.h>
  13. #include <LibWeb/HTML/EventLoop/EventLoop.h>
  14. namespace Web::Bindings {
  15. struct WebEngineCustomData final : public JS::VM::CustomData {
  16. virtual ~WebEngineCustomData() override = default;
  17. virtual void spin_event_loop_until(Function<bool()> goal_condition) override;
  18. HTML::EventLoop event_loop;
  19. // FIXME: These should only be on similar-origin window agents, but we don't currently differentiate agent types.
  20. // https://dom.spec.whatwg.org/#mutation-observer-compound-microtask-queued-flag
  21. bool mutation_observer_microtask_queued { false };
  22. // https://dom.spec.whatwg.org/#mutation-observer-list
  23. // FIXME: This should be a set.
  24. Vector<JS::Handle<DOM::MutationObserver>> mutation_observers;
  25. JS::Handle<JS::Realm> internal_realm;
  26. OwnPtr<JS::ExecutionContext> root_execution_context;
  27. };
  28. struct WebEngineCustomJobCallbackData final : public JS::JobCallback::CustomData {
  29. WebEngineCustomJobCallbackData(HTML::EnvironmentSettingsObject& incumbent_settings, OwnPtr<JS::ExecutionContext> active_script_context)
  30. : incumbent_settings(incumbent_settings)
  31. , active_script_context(move(active_script_context))
  32. {
  33. }
  34. virtual ~WebEngineCustomJobCallbackData() override = default;
  35. HTML::EnvironmentSettingsObject& incumbent_settings;
  36. OwnPtr<JS::ExecutionContext> active_script_context;
  37. };
  38. HTML::Script* active_script();
  39. JS::VM& main_thread_vm();
  40. void queue_mutation_observer_microtask(DOM::Document const&);
  41. NonnullOwnPtr<JS::ExecutionContext> create_a_new_javascript_realm(JS::VM&, Function<JS::Object*(JS::Realm&)> create_global_object, Function<JS::Object*(JS::Realm&)> create_global_this_value);
  42. }