Skip to content

Commit 56ba041

Browse files
authored
Avoid extra JS var in defineI64Param/receiveI64ParamAsI53. NFC (#16962)
Declare bigint param without any mangling, and then simply overwrite with Number form if/when needed. Split out from #16922. As well as saving a little on codesize this helps for cases there `defineI64Param` is used but that reciever wants to deal with the bigint param directly.
1 parent 190f1be commit 56ba041

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/parseTools.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ function hasExportedFunction(func) {
11261126
// it is a BigInt. Otherwise, we legalize into pairs of i32s.
11271127
function defineI64Param(name) {
11281128
if (WASM_BIGINT) {
1129-
return `/** @type {!BigInt} */ ${name}_bigint`;
1129+
return `/** @type {!BigInt} */ ${name}`;
11301130
}
11311131
return `${name}_low, ${name}_high`;
11321132
}
@@ -1138,15 +1138,15 @@ function receiveI64ParamAsI32s(name) {
11381138
// https://github.com/google/closure-compiler/issues/3167
11391139
// * acorn needs to be upgraded, and to set ecmascript version >= 11
11401140
// * terser needs to be upgraded
1141-
return `var ${name}_low = Number(${name}_bigint & BigInt(0xffffffff)) | 0, ${name}_high = Number(${name}_bigint >> BigInt(32)) | 0;`;
1141+
return `var ${name}_low = Number(${name} & BigInt(0xffffffff)) | 0, ${name}_high = Number(${name} >> BigInt(32)) | 0;`;
11421142
}
11431143
return '';
11441144
}
11451145

11461146
function receiveI64ParamAsI53(name, onError) {
11471147
if (WASM_BIGINT) {
11481148
// Just convert the bigint into a double.
1149-
return `var ${name} = bigintToI53Checked(${name}_bigint); if (isNaN(${name})) return ${onError};`;
1149+
return `${name} = bigintToI53Checked(${name}); if (isNaN(${name})) return ${onError};`;
11501150
}
11511151
// Covert the high/low pair to a Number, checking for
11521152
// overflow of the I53 range and returning onError in that case.

src/parseTools_legacy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function makeStructuralReturn(values) {
1717
function receiveI64ParamAsDouble(name) {
1818
if (WASM_BIGINT) {
1919
// Just convert the bigint into a double.
20-
return `var ${name} = Number(${name}_bigint);`;
20+
return `${name} = Number(${name});`;
2121
}
2222
// Combine the i32 params. Use an unsigned operator on low and shift high by
2323
// 32 bits.

0 commit comments

Comments
 (0)