mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 15:41:48 +00:00
Correct dynamic module loading/caching
Refactors some of the module loading logic. Both normal modules import and dynamic module import now share more of the same code - they both go through the slightly modified `module` function. Dynamic modules now check the cache first, before loading, and when cached, resolve the correct promise. This can now happen regardless of the module loading state. Also tried to replace some page arenas with call arenas and added some basic tests for both normal and dynamic module loading.
This commit is contained in:
19
src/tests/html/script/dynamic_import.html
Normal file
19
src/tests/html/script/dynamic_import.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<script src="../../testing.js"></script>
|
||||
|
||||
<script id=dynamic_import type=module>
|
||||
const promise1 = new Promise((resolve) => {
|
||||
Promise.all([
|
||||
import('./import.js'),
|
||||
import('./import.js'),
|
||||
import('./import2.js'),
|
||||
]).then(resolve);
|
||||
});
|
||||
|
||||
testing.async(promise1, (res) => {
|
||||
testing.expectEqual('hello', res[0].greeting);
|
||||
testing.expectEqual('hello', res[1].greeting);
|
||||
testing.expectEqual('world', res[2].greeting);
|
||||
})
|
||||
</script>
|
||||
15
src/tests/html/script/import.html
Normal file
15
src/tests/html/script/import.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<script src="../../testing.js"></script>
|
||||
|
||||
<script id=import type=module>
|
||||
import * as im from './import.js';
|
||||
testing.expectEqual('hello', im.greeting);
|
||||
</script>
|
||||
|
||||
<script id=cached type=module>
|
||||
// hopefully cached, who knows, no real way to assert this
|
||||
// but at least it works.
|
||||
import * as im from './import.js';
|
||||
testing.expectEqual('hello', im.greeting);
|
||||
</script>
|
||||
2
src/tests/html/script/import.js
Normal file
2
src/tests/html/script/import.js
Normal file
@@ -0,0 +1,2 @@
|
||||
let greeting = 'hello';
|
||||
export {greeting as 'greeting'};
|
||||
2
src/tests/html/script/import2.js
Normal file
2
src/tests/html/script/import2.js
Normal file
@@ -0,0 +1,2 @@
|
||||
let greeting = 'world';
|
||||
export {greeting as 'greeting'};
|
||||
Reference in New Issue
Block a user