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

@@ -12,6 +12,8 @@
#include <LibJS/Forward.h>
#include <LibJS/Runtime/ExecutionContext.h>
struct RustParsedProgram;
namespace JS {
// 16.2.1.6 Source Text Module Records, https://tc39.es/ecma262/#sec-source-text-module-records
@@ -23,6 +25,7 @@ public:
virtual ~SourceTextModule() override;
static Result<GC::Ref<SourceTextModule>, Vector<ParserError>> parse(StringView source_text, Realm&, StringView filename = {}, Script::HostDefined* host_defined = nullptr);
static Result<GC::Ref<SourceTextModule>, Vector<ParserError>> parse_from_pre_parsed(RustParsedProgram* parsed, NonnullRefPtr<SourceCode const> source_code, Realm&, Script::HostDefined* host_defined = nullptr);
Program const* parse_node() const { return m_ecmascript_code; }