-
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 1 commit
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,37 @@ async function getWasmBinary(binaryFile) { | |
|
||
#if SPLIT_MODULE | ||
{{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}} | ||
var splitModuleProxyHandler = { | ||
var wasmImportsProxyHandler = { | ||
get(target, prop, receiver) { | ||
return (...args) => { | ||
if (prop.startsWith('placeholder')) { | ||
const moduleName = prop; | ||
sbc100 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
var splitModuleProxyHandler = { | ||
|
||
get(target, prop, receiver) { | ||
return (...args) => { | ||
#if ASYNCIFY == 2 | ||
throw new Error('Placeholder function "' + prop + '" should not be called when using JSPI.'); | ||
throw new Error('Placeholder function "' + prop + '" should not be called when using JSPI.'); | ||
#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 | ||
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'); | ||
#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. | ||
prop = 1 + parseInt(prop); | ||
#endif | ||
return wasmTable.get({{{ toIndexType('prop') }}})(...args); | ||
return wasmTable.get({{{ toIndexType('prop') }}})(...args); | ||
#endif | ||
} | ||
} | ||
}; | ||
return new Proxy({}, splitModuleProxyHandler); | ||
} | ||
return target[prop]; | ||
} | ||
}; | ||
#endif | ||
|
@@ -633,6 +643,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 +664,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, wasmImportsProxyHandler); | ||
#endif | ||
return imports; | ||
} | ||
|
||
// Create the wasm instance. | ||
|
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.
Can we keep the splitModule prefix (or at least include it somewhere in the name) so its clear when this needed/used?
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 it to
splitImportsProxyHandler
: e918916