Skip to content

Commit a7f5361

Browse files
committed
Simplify from64 macro
Also, add a variant that simply generates an expression, similar to how the `to64` macro works. This is needed for #22497
1 parent 7d78ad8 commit a7f5361

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/library_ccall.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ addToLibrary({
4646

4747
function convertReturnValue(ret) {
4848
if (returnType === 'string') {
49-
{{{ from64('ret') }}}
50-
return UTF8ToString(ret);
49+
return UTF8ToString({{{ from64Expr('ret') }}});
5150
}
5251
#if MEMORY64
5352
if (returnType === 'pointer') return Number(ret);

src/library_dylink.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,7 @@ var LibraryDylink = {
814814
for (var name in moduleExports) {
815815
if (name.startsWith('__em_js__')) {
816816
var start = moduleExports[name]
817-
{{{ from64('start') }}}
818-
var jsString = UTF8ToString(start);
817+
var jsString = UTF8ToString({{{ from64Expr('start') }}});
819818
// EM_JS strings are stored in the data section in the form
820819
// SIG<::>BODY.
821820
var parts = jsString.split('<::>');

src/parseTools.mjs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -949,20 +949,20 @@ function receiveI64ParamAsI53Unchecked(name) {
949949
return `var ${name} = convertI32PairToI53(${name}_low, ${name}_high);`;
950950
}
951951

952-
// Any function called from wasm64 may have bigint args, this function takes
953-
// a list of variable names to convert to number.
952+
// Convert a pointer value under wasm64 from BigInt (used at local level API
953+
// level) to Number (used in JS library code). No-op under wasm32.
954954
function from64(x) {
955-
if (!MEMORY64) {
956-
return '';
957-
}
958-
if (Array.isArray(x)) {
959-
let ret = '';
960-
for (e of x) ret += from64(e);
961-
return ret;
962-
}
955+
if (!MEMORY64) return '';
963956
return `${x} = Number(${x});`;
964957
}
965958

959+
// Like from64 above but generate an expression instead of an assignment
960+
// statement.
961+
function from64Expr(x, assign = true) {
962+
if (!MEMORY64) return x;
963+
return `Number(${x})`;
964+
}
965+
966966
function to64(x) {
967967
if (!MEMORY64) return x;
968968
return `BigInt(${x})`;
@@ -1118,6 +1118,7 @@ addToCompileTimeContext({
11181118
expectToReceiveOnModule,
11191119
formattedMinNodeVersion,
11201120
from64,
1121+
from64Expr,
11211122
getEntryFunction,
11221123
getHeapForType,
11231124
getHeapOffset,

0 commit comments

Comments
 (0)