TemporaryExecutionContext.h 887 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Forward.h>
  8. namespace Web::HTML {
  9. // When JS is run from outside the context of any user script, we currently do not have a running execution context.
  10. // This results in a crash when we access VM::running_execution_context(). This is a spec issue. Until it is resolved,
  11. // this is a workaround to temporarily push an execution context.
  12. class TemporaryExecutionContext {
  13. public:
  14. enum class CallbacksEnabled {
  15. No,
  16. Yes,
  17. };
  18. explicit TemporaryExecutionContext(EnvironmentSettingsObject&, CallbacksEnabled = CallbacksEnabled::No);
  19. ~TemporaryExecutionContext();
  20. private:
  21. JS::NonnullGCPtr<EnvironmentSettingsObject> m_environment_settings;
  22. CallbacksEnabled m_callbacks_enabled { CallbacksEnabled::No };
  23. };
  24. }