LibWeb+LibJS: Compile fetched top-level JS off-thread

Split Rust program compilation so code generation and assembly finish
before the main thread materializes GC-backed executable objects. The
new CompiledProgram handle owns the parsed program, generator state, and
bytecode until C++ consumes it on the main thread.

Wire WebContent script fetching through that handle for classic scripts
and modules. Syntax-error paths still return ParsedProgram, so existing
error reporting stays in place. Successful fetches now do top-level
codegen on the thread pool before deferred_invoke hands control back to
the main thread.

Executable creation, SharedFunctionInstanceData materialization, module
metadata extraction, and declaration data extraction still run on the
main thread where VM and GC access is valid.
This commit is contained in:
Andreas Kling
2026-04-26 14:53:34 +02:00
committed by Andreas Kling
parent 0d120019df
commit 4a7dc45b3f
Notes: github-actions[bot] 2026-04-26 20:31:58 +00:00
12 changed files with 496 additions and 87 deletions

View File

@@ -90,6 +90,27 @@ WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> ModuleScript::create_from_pre_parsed(
return script;
}
WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> ModuleScript::create_from_pre_compiled(ByteString const& filename, NonnullRefPtr<JS::SourceCode const> source_code, EnvironmentSettingsObject& settings, URL::URL base_url, JS::FFI::CompiledProgram* compiled)
{
auto& realm = settings.realm();
auto script = realm.create<ModuleScript>(move(base_url), filename, settings);
script->set_parse_error(JS::js_null());
script->set_error_to_rethrow(JS::js_null());
auto result = JS::SourceTextModule::parse_from_pre_compiled(compiled, move(source_code), realm, script);
if (result.is_error()) {
auto& parse_error = result.error().first();
dbgln("JavaScriptModuleScript: Failed to materialize: {}", parse_error.to_string());
script->set_parse_error(JS::SyntaxError::create(realm, parse_error.to_string()));
return script;
}
script->m_record = result.value();
return script;
}
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-css-module-script
WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> ModuleScript::create_a_css_module_script(ByteString const& filename, StringView source, EnvironmentSettingsObject& settings)
{