mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 02:10:26 +00: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:
parent
7d45e897c4
commit
3f4d3d6108
Notes:
github-actions[bot]
2026-03-06 12:07:29 +00:00
Author: https://github.com/awesomekling
Commit: 3f4d3d6108
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
6 changed files with 132 additions and 59 deletions
|
|
@ -71,6 +71,29 @@ WebIDL::ExceptionOr<GC::Ptr<JavaScriptModuleScript>> JavaScriptModuleScript::cre
|
|||
return script;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<GC::Ptr<JavaScriptModuleScript>> JavaScriptModuleScript::create_from_pre_parsed(ByteString const& filename, StringView source, JS::Realm& realm, URL::URL base_url, RustParsedProgram* parsed)
|
||||
{
|
||||
if (HTML::is_scripting_disabled(realm))
|
||||
source = ""sv;
|
||||
|
||||
auto script = realm.create<JavaScriptModuleScript>(move(base_url), filename, realm);
|
||||
|
||||
script->set_parse_error(JS::js_null());
|
||||
script->set_error_to_rethrow(JS::js_null());
|
||||
|
||||
auto result = JS::SourceTextModule::parse_from_pre_parsed(parsed, source, realm, filename.view(), script);
|
||||
|
||||
if (result.is_error()) {
|
||||
auto& parse_error = result.error().first();
|
||||
dbgln("JavaScriptModuleScript: Failed to parse: {}", 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#run-a-module-script
|
||||
// https://whatpr.org/html/9893/webappapis.html#run-a-module-script
|
||||
JS::Promise* JavaScriptModuleScript::run(PreventErrorReporting)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue