mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
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:
committed by
Andreas Kling
parent
7d45e897c4
commit
3f4d3d6108
Notes:
github-actions[bot]
2026-03-06 12:07:29 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/3f4d3d61080 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8211 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/Zaggy1024 Reviewed-by: https://github.com/alimpfard
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user