Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -1903,10 +1903,12 @@ addToLibrary({
$setWasmTableEntry__internal: true,
$setWasmTableEntry__deps: ['$wasmTableMirror', '$wasmTable'],
$setWasmTableEntry: (idx, func) => {
/** @suppress {checkTypes} */
wasmTable.set({{{ toIndexType('idx') }}}, func);
// With ABORT_ON_WASM_EXCEPTIONS wasmTable.get is overridden to return wrapped
// functions so we need to call it here to retrieve the potential wrapper correctly
// instead of just storing 'func' directly into wasmTableMirror
/** @suppress {checkTypes} */
wasmTableMirror[idx] = wasmTable.get({{{ toIndexType('idx') }}});
},

Expand All @@ -1922,6 +1924,7 @@ addToLibrary({
var func = wasmTableMirror[funcPtr];
if (!func) {
if (funcPtr >= wasmTableMirror.length) wasmTableMirror.length = funcPtr + 1;
/** @suppress {checkTypes} */
wasmTableMirror[funcPtr] = func = wasmTable.get({{{ toIndexType('funcPtr') }}});
#if ASYNCIFY == 2
if (Asyncify.isAsyncExport(func)) {
Expand All @@ -1930,23 +1933,21 @@ addToLibrary({
#endif
}
#if ASSERTIONS && ASYNCIFY != 2 // With JSPI the function stored in the table will be a wrapper.
/** @suppress {checkTypes} */
assert(wasmTable.get({{{ toIndexType('funcPtr') }}}) == func, 'JavaScript-side Wasm function table mirror is out of date!');
#endif
return func;
},

#else

$setWasmTableEntry__docs: '/** @suppress{checkTypes} */',
$setWasmTableEntry__deps: ['$wasmTable'],
$setWasmTableEntry: (idx, func) => wasmTable.set({{{ toIndexType('idx') }}}, func),

$getWasmTableEntry__docs: '/** @suppress{checkTypes} */',
$getWasmTableEntry__deps: ['$wasmTable'],
$getWasmTableEntry: (funcPtr) => {
#if MEMORY64
// Function pointers are 64-bit, but wasmTable.get() requires a Number.
// https://github.com/emscripten-core/emscripten/issues/18200
funcPtr = Number(funcPtr);
#endif
// In -Os and -Oz builds, do not implement a JS side wasm table mirror for small
// code size, but directly access wasmTable, which is a bit slower as uncached.
return wasmTable.get({{{ toIndexType('funcPtr') }}});
Expand Down
1 change: 1 addition & 0 deletions src/library_addfunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ addToLibrary({
}
// Grow the table
try {
/** @suppress {checkTypes} */
wasmTable.grow({{{ toIndexType('1') }}});
} catch (err) {
if (!(err instanceof RangeError)) {
Expand Down
3 changes: 1 addition & 2 deletions src/parseTools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,7 @@ function from64Expr(x, assign = true) {
}

function toIndexType(x) {
if (MEMORY64 != 1) return x;
return `toIndexType(${x})`;
return to64(x);
Copy link
Member

Choose a reason for hiding this comment

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

Should we replace calls from toIndexType to to64? Or do we think the distinction is important/might matter later?

Copy link
Member

Choose a reason for hiding this comment

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

I lean towards keeping the distinction, but just a thought.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I thought of doing that. Can always be done as followup I guess?

Copy link
Member

Choose a reason for hiding this comment

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

Followup sounds fine, but also I am not sure if that is worthwhile. Unless we are certain we won't care about the difference later (which I am not sure of myself).

}

function to64(x) {
Expand Down
1 change: 1 addition & 0 deletions src/runtime_init_memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if (!ENVIRONMENT_IS_PTHREAD) {
#if ASSERTIONS
assert(INITIAL_MEMORY >= {{{STACK_SIZE}}}, 'INITIAL_MEMORY should be larger than STACK_SIZE, was ' + INITIAL_MEMORY + '! (STACK_SIZE=' + {{{STACK_SIZE}}} + ')');
#endif
/** @suppress {checkTypes} */
#if MINIMAL_RUNTIME && WASM_WORKERS
wasmMemory = Module['mem'] || new WebAssembly.Memory({
#else
Expand Down
16 changes: 0 additions & 16 deletions src/runtime_shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@ function updateMemoryViews() {
#endif
}

#if MEMORY64 == 1
var toIndexType = (function() {
// Probe for support of bigint bounds with memory64.
// TODO(sbc): Remove this once all browsers start requiring bigint here.
// See https://github.com/WebAssembly/memory64/issues/68
var bigintMemoryBounds = 1;
try {
/** @suppress {checkTypes} */
new WebAssembly.Memory({'initial': 1n, 'index': 'i64', 'address': 'i64'});
} catch (e) {
bigintMemoryBounds = 0;
}
return (i) => bigintMemoryBounds ? BigInt(i) : i;
})();
#endif

#if ENVIRONMENT_MAY_BE_NODE && MIN_NODE_VERSION < 160000
// The performance global was added to node in v16.0.0:
// https://nodejs.org/api/globals.html#performance
Expand Down
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_64.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1589
1522
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_64.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3311
3179
Loading