LibJS+LibWeb: Add C++ compile_parsed_module wrapper

Add compile_parsed_module() to RustIntegration, which takes a
RustParsedProgram and a SourceCode (from parse_program with
ProgramType::Module) and compiles it on the main thread with GC
interaction.

Rewrite compile_module() to use the new split functions internally.

Add SourceTextModule::parse_from_pre_parsed() and
JavaScriptModuleScript::create_from_pre_parsed() to allow creating
module scripts from a pre-parsed RustParsedProgram.

This prepares the infrastructure for off-thread module parsing.
This commit is contained in:
Andreas Kling
2026-02-27 23:44:44 +01:00
committed by Andreas Kling
parent 7d45e897c4
commit 3f4d3d6108
Notes: github-actions[bot] 2026-03-06 12:07:29 +00:00
6 changed files with 132 additions and 59 deletions

View File

@@ -204,6 +204,29 @@ void SourceTextModule::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_tla_shared_data);
}
Result<GC::Ref<SourceTextModule>, Vector<ParserError>> SourceTextModule::parse_from_pre_parsed(RustParsedProgram* parsed, NonnullRefPtr<SourceCode const> source_code, Realm& realm, Script::HostDefined* host_defined)
{
auto filename = source_code->filename();
auto rust_result = RustIntegration::compile_parsed_module(parsed, move(source_code), realm);
// Always from the Rust pipeline, so the Optional must have a value.
VERIFY(rust_result.has_value());
if (rust_result->is_error())
return rust_result->release_error();
auto& module_result = rust_result->value();
Vector<FunctionToInitialize> functions_to_initialize;
functions_to_initialize.ensure_capacity(module_result.functions_to_initialize.size());
for (auto& f : module_result.functions_to_initialize)
functions_to_initialize.append({ *f.shared_data, move(f.name) });
return realm.heap().allocate<SourceTextModule>(
realm, filename, host_defined, module_result.has_top_level_await,
move(module_result.requested_modules), move(module_result.import_entries),
move(module_result.local_export_entries), move(module_result.indirect_export_entries),
move(module_result.star_export_entries), move(module_result.default_export_binding_name),
move(module_result.var_declared_names), move(module_result.lexical_bindings),
move(functions_to_initialize),
module_result.executable.ptr(), module_result.tla_shared_data.ptr());
}
// 16.2.1.7.1 ParseModule ( sourceText, realm, hostDefined ), https://tc39.es/ecma262/#sec-parsemodule
Result<GC::Ref<SourceTextModule>, Vector<ParserError>> SourceTextModule::parse(StringView source_text, Realm& realm, StringView filename, Script::HostDefined* host_defined)
{