Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,26 +488,38 @@ async function getWasmBinary(binaryFile) {
#if SPLIT_MODULE
{{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}}
var splitModuleProxyHandler = {
get(target, prop, receiver) {
return (...args) => {
get(target, moduleName, receiver) {
if (moduleName.startsWith('placeholder')) {
return new Proxy({}, {
get(target, base, receiver) {
return (...args) => {
#if ASYNCIFY == 2
throw new Error('Placeholder function "' + prop + '" should not be called when using JSPI.');
throw new Error('Placeholder function "' + base + '" should not be called when using JSPI.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(As an aside I wonder if this line should be an assert).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure... Can't this be triggered by user errors? If so an Error might be fine?

#else
err(`placeholder function called: ${prop}`);
var imports = {'primary': wasmExports};
// Replace '.wasm' suffix with '.deferred.wasm'.
var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm'
loadSplitModule(deferred, imports, prop);
err('instantiated deferred module, continuing');
// TODO: Implement multi-split module loading
#if RUNTIME_DEBUG
dbg(`placeholder function called: ${base}`);
#endif
var imports = {'primary': wasmExports};
// Replace '.wasm' suffix with '.deferred.wasm'.
var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm'
loadSplitModule(deferred, imports, base);
#if RUNTIME_DEBUG
dbg('instantiated deferred module, continuing');
#endif
#if RELOCATABLE
// When the table is dynamically laid out, the placeholder functions names
// are offsets from the table base. In the main module, the table base is
// always 1.
prop = 1 + parseInt(prop);
// When the table is dynamically laid out, the placeholder functions names
// are offsets from the table base. In the main module, the table base is
// always 1.
base = 1 + parseInt(base);
#endif
return wasmTable.get({{{ toIndexType('prop') }}})(...args);
return wasmTable.get({{{ toIndexType('base') }}})(...args);
#endif
}
}
});
}
return target[moduleName];
}
};
#endif
Expand Down Expand Up @@ -653,21 +665,22 @@ function getWasmImports() {
#endif
#endif
// prepare imports
return {
var imports = {
#if MINIFY_WASM_IMPORTED_MODULES
'a': wasmImports,
#else // MINIFY_WASM_IMPORTED_MODULES
'env': wasmImports,
'{{{ WASI_MODULE_NAME }}}': wasmImports,
#endif // MINIFY_WASM_IMPORTED_MODULES
#if SPLIT_MODULE
'placeholder': new Proxy({}, splitModuleProxyHandler),
#endif
#if RELOCATABLE
'GOT.mem': new Proxy(wasmImports, GOTHandler),
'GOT.func': new Proxy(wasmImports, GOTHandler),
#endif
}
};
#if SPLIT_MODULE
imports = new Proxy(imports, splitModuleProxyHandler);
#endif
return imports;
}

// Create the wasm instance.
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_cxx_wasmfs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"a.out.js": 7059,
"a.out.js.gz": 3330,
"a.out.nodebug.wasm": 169721,
"a.out.nodebug.wasm.gz": 62983,
"a.out.nodebug.wasm.gz": 62981,
"total": 176780,
"total_gz": 66313,
"total_gz": 66311,
"sent": [
"__cxa_throw",
"_abort_js",
Expand Down
3 changes: 2 additions & 1 deletion test/codesize/test_codesize_file_preload.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,10 @@ async function instantiateAsync(binary, binaryFile, imports) {

function getWasmImports() {
// prepare imports
return {
var imports = {
"a": wasmImports
};
return imports;
}

// Create the wasm instance.
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_files_wasmfs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"a.out.js": 5465,
"a.out.js.gz": 2576,
"a.out.nodebug.wasm": 50218,
"a.out.nodebug.wasm.gz": 18082,
"a.out.nodebug.wasm.gz": 18086,
"total": 55683,
"total_gz": 20658,
"total_gz": 20662,
"sent": [
"a (emscripten_date_now)",
"b (emscripten_err)",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_hello_O0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 24070,
"a.out.js.gz": 8666,
"a.out.nodebug.wasm": 15127,
"a.out.nodebug.wasm.gz": 7450,
"total": 39197,
"total_gz": 16116,
"a.out.nodebug.wasm": 15119,
"a.out.nodebug.wasm.gz": 7444,
"total": 39189,
"total_gz": 16110,
"sent": [
"fd_write"
],
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 245829,
"a.out.nodebug.wasm": 597724,
"total": 843553,
"a.out.nodebug.wasm": 597730,
"total": 843559,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
5 changes: 3 additions & 2 deletions test/codesize/test_codesize_minimal_O0.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,11 @@ async function instantiateAsync(binary, binaryFile, imports) {

function getWasmImports() {
// prepare imports
return {
var imports = {
'env': wasmImports,
'wasi_snapshot_preview1': wasmImports,
}
};
return imports;
}

// Create the wasm instance.
Expand Down
28 changes: 14 additions & 14 deletions test/codesize/test_unoptimized_code_size.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"hello_world.js": 56566,
"hello_world.js.gz": 17601,
"hello_world.wasm": 15127,
"hello_world.wasm.gz": 7450,
"no_asserts.js": 26608,
"no_asserts.js.gz": 8874,
"no_asserts.wasm": 12227,
"no_asserts.wasm.gz": 6010,
"strict.js": 54581,
"strict.js.gz": 16947,
"strict.wasm": 15127,
"strict.wasm.gz": 7447,
"total": 180236,
"total_gz": 64329
"hello_world.js": 56592,
"hello_world.js.gz": 17608,
"hello_world.wasm": 15119,
"hello_world.wasm.gz": 7444,
"no_asserts.js": 26634,
"no_asserts.js.gz": 8883,
"no_asserts.wasm": 12219,
"no_asserts.wasm.gz": 6005,
"strict.js": 54607,
"strict.js.gz": 16955,
"strict.wasm": 15119,
"strict.wasm.gz": 7442,
"total": 180290,
"total_gz": 64337
}
Loading