Skip to content

Commit 6b35664

Browse files
authored
Merge pull request #1079 from lightpanda-io/dynamic_import_caching
Dynamic import caching
2 parents 1a40853 + e7d1d55 commit 6b35664

File tree

8 files changed

+204
-201
lines changed

8 files changed

+204
-201
lines changed

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
.fingerprint = 0xda130f3af836cea0,
66
.dependencies = .{
77
.v8 = .{
8-
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/7177ee1ae267a44751a0e7e012e257177699a375.tar.gz",
9-
.hash = "v8-0.0.0-xddH63TCAwC1D1hEiOtbEnLBbtz9ZPHrdiGWLcBcYQB7",
8+
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/c25223900587005c9cf13f25e56a7e0be26a533c.tar.gz",
9+
.hash = "v8-0.0.0-xddH6x_DAwBh0gSbFFv1fyiExhExXKzZpbmj5sFH4MRY",
1010
},
1111
// .v8 = .{ .path = "../zig-v8-fork" }
1212
},

src/browser/html/elements.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,8 @@ test "Browser: HTML.HtmlStyleElement" {
13511351
test "Browser: HTML.HtmlScriptElement" {
13521352
try testing.htmlRunner("html/script/script.html");
13531353
try testing.htmlRunner("html/script/inline_defer.html");
1354+
try testing.htmlRunner("html/script/import.html");
1355+
try testing.htmlRunner("html/script/dynamic_import.html");
13541356
}
13551357

13561358
test "Browser: HTML.HtmlSlotElement" {

src/runtime/js.zig

Lines changed: 161 additions & 198 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
3+
<script src="../../testing.js"></script>
4+
5+
<script id=dynamic_import type=module>
6+
const promise1 = new Promise((resolve) => {
7+
Promise.all([
8+
import('./import.js'),
9+
import('./import.js'),
10+
import('./import2.js'),
11+
]).then(resolve);
12+
});
13+
14+
testing.async(promise1, (res) => {
15+
testing.expectEqual('hello', res[0].greeting);
16+
testing.expectEqual('hello', res[1].greeting);
17+
testing.expectEqual('world', res[2].greeting);
18+
})
19+
</script>

src/tests/html/script/import.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
3+
<script src="../../testing.js"></script>
4+
5+
<script id=import type=module>
6+
import * as im from './import.js';
7+
testing.expectEqual('hello', im.greeting);
8+
</script>
9+
10+
<script id=cached type=module>
11+
// hopefully cached, who knows, no real way to assert this
12+
// but at least it works.
13+
import * as im from './import.js';
14+
testing.expectEqual('hello', im.greeting);
15+
</script>

src/tests/html/script/import.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let greeting = 'hello';
2+
export {greeting as 'greeting'};

src/tests/html/script/import2.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let greeting = 'world';
2+
export {greeting as 'greeting'};

src/tests/testing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
}
9494

9595
async function async(promise, cb) {
96-
const script_id = document.currentScript.id;
96+
const script_id = document.currentScript ? document.currentScript.id : '<script id is unavailable in browsers>';
9797
const stack = new Error().stack;
9898
this._captured = {script_id: script_id, stack: stack};
9999
const value = await promise;

0 commit comments

Comments
 (0)