mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
Support a module dynamically importing itself
This commit is contained in:
@@ -301,9 +301,17 @@ pub fn module(self: *Context, comptime want_result: bool, local: *const js.Local
|
|||||||
|
|
||||||
// and the module must have been set after we compiled it
|
// and the module must have been set after we compiled it
|
||||||
lp.assert(entry.module != null, "Context.module with module", .{});
|
lp.assert(entry.module != null, "Context.module with module", .{});
|
||||||
lp.assert(entry.module_promise == null, "Context.module with module_promise", .{});
|
if (entry.module_promise != null) {
|
||||||
|
// While loading this script, it's possible that it was dynamically
|
||||||
|
// included (either the module dynamically loaded itself (unlikely) or
|
||||||
|
// it included a script which dynamically imported it). If it was, then
|
||||||
|
// the module_promise would already be setup, and we don't need to do
|
||||||
|
// anything
|
||||||
|
} else {
|
||||||
|
// The *much* more likely case where the module we're trying to load
|
||||||
|
// didn't [directly or indirectly] dynamically load itself.
|
||||||
entry.module_promise = try evaluated.toPromise().persist();
|
entry.module_promise = try evaluated.toPromise().persist();
|
||||||
|
}
|
||||||
return if (comptime want_result) entry.* else {};
|
return if (comptime want_result) entry.* else {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,3 +58,6 @@
|
|||||||
testing.expectEqual(true, e.toString().includes("FailedToLoad"), {script_id: 'import-404'});
|
testing.expectEqual(true, e.toString().includes("FailedToLoad"), {script_id: 'import-404'});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- this used to crash -->
|
||||||
|
<script type=module src=modules/self_async.js></script>
|
||||||
|
|||||||
1
src/browser/tests/page/modules/self_async.js
Normal file
1
src/browser/tests/page/modules/self_async.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
const c = await import('./self_async.js');
|
||||||
Reference in New Issue
Block a user