Skip to content
Merged
Changes from 1 commit
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
50 changes: 31 additions & 19 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,27 +487,37 @@ async function getWasmBinary(binaryFile) {

#if SPLIT_MODULE
{{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}}
var splitModuleProxyHandler = {
var wasmImportsProxyHandler = {
Copy link
Collaborator

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?

Copy link
Member Author

@aheejin aheejin Oct 15, 2025

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

get(target, prop, receiver) {
return (...args) => {
if (prop.startsWith('placeholder')) {
const moduleName = prop;
var splitModuleProxyHandler = {
Copy link
Collaborator

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?

Copy link
Collaborator

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?

Copy link
Member Author

@aheejin aheejin Oct 15, 2025

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 to innerHandler: eaea168

The inner handler name is used here, so now sure how to anonymize it.

      return new Proxy({}, innerHandler); 

Copy link
Collaborator

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 }

Copy link
Member Author

Choose a reason for hiding this comment

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

Done: 67e5380

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
Expand Down Expand Up @@ -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();
Expand All @@ -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.
Expand Down
Loading