dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / html / scripting / temporary_execution_context.lucb
#==============================================================================================
#
# temporary_execution_context - HTML::TemporaryExecutionContext: a realm execution context
# pushed for native code that runs outside any script
#
# DESCRIPTION:
# Port of Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.cpp (lines 1-33) and
# TemporaryExecutionContext.h (lines 1-34). C++ RAII: the constructors prepare to run
# script (and a callback), the destructor cleans up; callers construct the context in a
# `---` local and `defer html_temporary_execution_context_destruct(&context)`.
#
# When JS is run from outside the context of any user script, we currently do not have a
# running execution context. This results in a crash when we access
# VM::running_execution_context(). This is a spec issue. Until it is resolved, this is a
# workaround to temporarily push an execution context.
#
# Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.cpp:12 Web::HTML::TemporaryExecutionContext::TemporaryExecutionContext(JS::Realm&, CallbacksEnabled).
pub func html_temporary_execution_context_construct_realm(this: HtmlTemporaryExecutionContext*, realm: Realm*, callbacks_enabled: HtmlTemporaryExecutionContextCallbacksEnabled = HtmlTemporaryExecutionContextCallbacksEnabled.no):
html_temporary_execution_context_construct_html_environment_settings_obje(this, html_principal_realm_settings_object(realm), callbacks_enabled)
## Ported from Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.cpp:17 Web::HTML::TemporaryExecutionContext::TemporaryExecutionContext(EnvironmentSettingsObject&, CallbacksEnabled).
pub func html_temporary_execution_context_construct_html_environment_settings_obje(this: HtmlTemporaryExecutionContext*, settings: HtmlEnvironmentSettingsObject*, callbacks_enabled: HtmlTemporaryExecutionContextCallbacksEnabled = HtmlTemporaryExecutionContextCallbacksEnabled.no):
this.m_settings = settings
this.m_callbacks_enabled = callbacks_enabled
html_prepare_to_run_script(this.m_settings)
if this.m_callbacks_enabled == HtmlTemporaryExecutionContextCallbacksEnabled.yes:
html_prepare_to_run_callback(this.m_settings)
## Ported from Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.cpp:26 Web::HTML::TemporaryExecutionContext::~TemporaryExecutionContext:
## cleans up after running script (and callbacks); callers run it with `defer`.
pub func html_temporary_execution_context_destruct(this: HtmlTemporaryExecutionContext*):
html_clean_up_after_running_script(this.m_settings)
if this.m_callbacks_enabled == HtmlTemporaryExecutionContextCallbacksEnabled.yes:
html_clean_up_after_running_callback(this.m_settings)