mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 17:37:33 +02:00
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:
committed by
Andreas Kling
parent
0d120019df
commit
4a7dc45b3f
Notes:
github-actions[bot]
2026-04-26 20:31:58 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/4a7dc45b3f0 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/9118
@@ -105,6 +105,39 @@ GC::Ref<ClassicScript> ClassicScript::create_from_pre_parsed(ByteString filename
|
||||
return script;
|
||||
}
|
||||
|
||||
GC::Ref<ClassicScript> ClassicScript::create_from_pre_compiled(ByteString filename, NonnullRefPtr<JS::SourceCode const> source_code, EnvironmentSettingsObject& settings, URL::URL base_url, JS::FFI::CompiledProgram* compiled, MutedErrors muted_errors)
|
||||
{
|
||||
auto& realm = settings.realm();
|
||||
auto& vm = realm.vm();
|
||||
|
||||
if (muted_errors == MutedErrors::Yes)
|
||||
base_url = URL::about_blank();
|
||||
|
||||
auto script = vm.heap().allocate<ClassicScript>(move(base_url), move(filename), settings);
|
||||
|
||||
script->m_muted_errors = muted_errors;
|
||||
script->set_parse_error(JS::js_null());
|
||||
script->set_error_to_rethrow(JS::js_null());
|
||||
|
||||
auto parse_timer = Core::ElapsedTimer::start_new();
|
||||
auto result = JS::Script::create_from_compiled(compiled, move(source_code), realm, script);
|
||||
dbgln_if(HTML_SCRIPT_DEBUG, "ClassicScript: Materialized pre-compiled {} in {}ms", script->filename(), parse_timer.elapsed_milliseconds());
|
||||
|
||||
if (result.is_error()) {
|
||||
auto& parse_error = result.error().first();
|
||||
dbgln_if(HTML_SCRIPT_DEBUG, "ClassicScript: Failed to materialize: {}", parse_error.to_string());
|
||||
|
||||
script->set_parse_error(JS::SyntaxError::create(realm, parse_error.to_string()));
|
||||
script->set_error_to_rethrow(script->parse_error());
|
||||
|
||||
return script;
|
||||
}
|
||||
|
||||
script->m_script_record = *result.release_value();
|
||||
|
||||
return script;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script
|
||||
JS::Completion ClassicScript::run(RethrowErrors rethrow_errors, GC::Ptr<JS::Environment> lexical_environment_override)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user