-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[SPLIT_MODULE] Make getWasmImports return Proxy #25559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
e51feda
470fcfb
6a30a50
3c5e7ad
3ddcbd1
b2a22d4
e918916
6cb0c42
4f2f3b3
5f2bc5f
68c3308
eaea168
147482f
3919476
67e5380
13f034d
d0a19db
ce9f8c8
6d395fb
6bb859f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -487,27 +487,39 @@ async function getWasmBinary(binaryFile) { | |
|
||
#if SPLIT_MODULE | ||
{{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}} | ||
var splitModuleProxyHandler = { | ||
get(target, prop, receiver) { | ||
return (...args) => { | ||
var splitImportsProxyHandler = { | ||
get(target, moduleName, receiver) { | ||
if (moduleName.startsWith('placeholder')) { | ||
var splitModuleProxyHandler = { | ||
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.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (As an aside I wonder if this line should be an assert). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
#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'. | ||
loadSplitModule(secondaryFile, 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 new Proxy({}, splitModuleProxyHandler); | ||
} | ||
return target[moduleName]; | ||
} | ||
}; | ||
#endif | ||
|
@@ -633,6 +645,7 @@ async function instantiateAsync(binary, binaryFile, imports) { | |
#endif // SOURCE_PHASE_IMPORTS | ||
|
||
#if !WASM_ESM_INTEGRATION | ||
|
||
function getWasmImports() { | ||
#if PTHREADS || WASM_WORKERS || (IMPORTED_MEMORY && MODULARIZE == 'instance') | ||
assignWasmImports(); | ||
|
@@ -653,21 +666,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, splitImportsProxyHandler); | ||
|
||
#endif | ||
return imports; | ||
} | ||
|
||
// Create the wasm instance. | ||
|
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just call this one
innerHandler
then maybe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This inner name is less important since its not in the global namespace. It could even just be inlined (anonymous) bat that could make harder to grok maybe?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed the outer handler to
splitModuleProxyHandler
and the inner one toinnerHandler
: eaea168The inner handler name is used here, so now sure how to anonymize it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean you could just write
return new Proxy({}, { ... inner handler code }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: 67e5380