LibWeb+RequestServer: Send cached bytecode with responses

Attach cached JavaScript bytecode sidecars to HTTP response headers so
WebContent can materialize classic and module scripts directly from a
decoded cache blob on cache hits.

Carry the disk cache vary key with the sidecar and reuse it when storing
fresh bytecode, avoiding mismatches against the augmented network
request headers used to create the cache entry.

Keep CORS-filtered module responses intact for status, MIME, and script
creation checks. Read bytecode sidecar data only from the internal
response, and treat decode or materialization failure as a cache miss
that falls back to normal source compilation.
This commit is contained in:
Andreas Kling
2026-05-03 20:04:35 +02:00
committed by Andreas Kling
parent 557191decb
commit c32b5a3f73
Notes: github-actions[bot] 2026-05-06 06:21:12 +00:00
30 changed files with 280 additions and 63 deletions

View File

@@ -111,6 +111,27 @@ WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> ModuleScript::create_from_pre_compile
return script;
}
WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> ModuleScript::create_from_bytecode_cache(ByteString const& filename, NonnullRefPtr<JS::SourceCode const> source_code, EnvironmentSettingsObject& settings, URL::URL base_url, JS::FFI::DecodedBytecodeCacheBlob* bytecode_cache)
{
auto& realm = settings.realm();
auto script = realm.create<ModuleScript>(move(base_url), filename, settings);
script->set_parse_error(JS::js_null());
script->set_error_to_rethrow(JS::js_null());
auto result = JS::SourceTextModule::parse_from_bytecode_cache(bytecode_cache, move(source_code), realm, script);
if (result.is_error()) {
auto& parse_error = result.error().first();
dbgln("JavaScriptModuleScript: Failed to materialize bytecode cache: {}", 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#creating-a-css-module-script
WebIDL::ExceptionOr<GC::Ptr<ModuleScript>> ModuleScript::create_a_css_module_script(ByteString const& filename, StringView source, EnvironmentSettingsObject& settings)
{