mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
Merge pull request #803 from lightpanda-io/inline_module_no_cache
Fix module caching
This commit is contained in:
@@ -986,12 +986,19 @@ const Script = struct {
|
||||
defer try_catch.deinit();
|
||||
|
||||
const src = self.src orelse page.url.raw;
|
||||
// if self.src is null, then this is an inline script, and it should
|
||||
// not be cached.
|
||||
const cacheable = self.src != null;
|
||||
|
||||
log.debug(.browser, "executing script", .{ .src = src, .kind = self.kind });
|
||||
log.debug(.browser, "executing script", .{
|
||||
.src = src,
|
||||
.kind = self.kind,
|
||||
.cacheable = cacheable,
|
||||
});
|
||||
|
||||
const result = switch (self.kind) {
|
||||
.javascript => page.main_context.eval(body, src),
|
||||
.module => page.main_context.module(body, src),
|
||||
.module => page.main_context.module(body, src, cacheable),
|
||||
};
|
||||
|
||||
result catch {
|
||||
@@ -1003,6 +1010,7 @@ const Script = struct {
|
||||
log.warn(.user_script, "eval script", .{
|
||||
.src = src,
|
||||
.err = msg,
|
||||
.cacheable = cacheable,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -691,7 +691,11 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
||||
|
||||
// compile and eval a JS module
|
||||
// It doesn't wait for callbacks execution
|
||||
pub fn module(self: *JsContext, src: []const u8, url: []const u8) !void {
|
||||
pub fn module(self: *JsContext, src: []const u8, url: []const u8, cacheable: bool) !void {
|
||||
if (!cacheable) {
|
||||
return self.moduleNoCache(src, url);
|
||||
}
|
||||
|
||||
const arena = self.context_arena;
|
||||
|
||||
const gop = try self.module_cache.getOrPut(arena, url);
|
||||
@@ -718,6 +722,16 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
||||
_ = try m.evaluate(v8_context);
|
||||
}
|
||||
|
||||
fn moduleNoCache(self: *JsContext, src: []const u8, url: []const u8) !void {
|
||||
const m = try compileModule(self.isolate, src, url);
|
||||
const v8_context = self.v8_context;
|
||||
if (try m.instantiate(v8_context, resolveModuleCallback) == false) {
|
||||
return error.ModuleInstantiationError;
|
||||
}
|
||||
|
||||
_ = try m.evaluate(v8_context);
|
||||
}
|
||||
|
||||
// Wrap a v8.Exception
|
||||
fn createException(self: *const JsContext, e: v8.Value) Exception {
|
||||
return .{
|
||||
|
||||
Reference in New Issue
Block a user