Skip to content

Commit 5a1564d

Browse files
committed
decouple webcomponents.js from window
1 parent ad4aaa6 commit 5a1564d

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

src/browser/js/Env.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,7 @@ fn generateIsolateSnaphot(params: *v8.CreateParams) v8.StartupData {
563563
context.enter();
564564
defer context.exit();
565565

566-
return snapshot_creator.createSnapshotDataBlob("function LightpandaSnapshotPoC() { return 73; }");
566+
return snapshot_creator.createSnapshotDataBlob(
567+
@import("../polyfill/webcomponents.zig").source,
568+
);
567569
}

src/browser/polyfill/polyfill.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ pub const Loader = struct {
5656
}
5757

5858
if (!self.done.webcomponents and isWebcomponents(name)) {
59-
const source = @import("webcomponents.zig").source;
60-
self.load("webcomponents", source, js_context);
59+
const lazy = @import("webcomponents.zig").lazy;
60+
self.load("webcomponents", lazy, js_context);
6161
// We return false here: We want v8 to continue the calling chain
6262
// to finally find the polyfill we just inserted. If we want to
6363
// return false and stops the call chain, we have to use

src/browser/polyfill/webcomponents.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/browser/polyfill/webcomponents.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ pub const pre =
3636
\\ })();
3737
;
3838

39+
pub const lazy =
40+
\\ __polyfillWebcomponents(window);
41+
\\ delete(__polyfillWebcomponents);
42+
;
43+
3944
const testing = @import("../../testing.zig");
4045
test "Browser: Polyfill.WebComponents" {
4146
try testing.htmlRunner("polyfill/webcomponents.html");

src/tests/polyfill/webcomponents.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
}
1414
}
1515

16-
testing.expectEqual(73, LightpandaSnapshotPoC());
17-
1816
window.customElements.define("lightpanda-test", LightPanda);
1917
const main = document.getElementById('main');
2018
main.appendChild(document.createElement('lightpanda-test'));

0 commit comments

Comments
 (0)