LibJS+LibWeb: Parse classic scripts off the main thread

Create a SourceCode on the main thread (performing UTF-8 to UTF-16
conversion), then submit parse_program() to the ThreadPool for
Rust parsing on a worker thread. This unblocks the WebContent event
loop during external script loading.

Add Script::create_from_parsed() and
ClassicScript::create_from_pre_parsed() factory methods that take a
pre-parsed RustParsedProgram and a SourceCode, performing only the
GC-allocating compile step on the main thread.

Falls back to synchronous parsing when the Rust pipeline is
unavailable (LIBJS_CPP=1 or LIBJS_COMPARE_PIPELINES=1).
This commit is contained in:
Andreas Kling
2026-02-27 23:44:29 +01:00
committed by Andreas Kling
parent 6983c6b1a5
commit d8921646f5
Notes: github-actions[bot] 2026-03-06 12:07:42 +00:00
7 changed files with 127 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ public:
Yes,
};
static GC::Ref<ClassicScript> create(ByteString filename, StringView source, JS::Realm&, URL::URL base_url, size_t source_line_number = 1, MutedErrors = MutedErrors::No);
static GC::Ref<ClassicScript> create_from_pre_parsed(ByteString filename, NonnullRefPtr<JS::SourceCode const> source_code, JS::Realm&, URL::URL base_url, RustParsedProgram* parsed, MutedErrors = MutedErrors::No);
JS::Script* script_record() { return m_script_record; }
JS::Script const* script_record() const { return m_script_record; }