Skip to content

Commit a71d00d

Browse files
authored
Use BigInt literals in JS sources (#17036)
Now that terser is patched and upgraded we no longer have to avoid the use of BigInt literals in the source!
1 parent 565c853 commit a71d00d

File tree

8 files changed

+13
-18
lines changed

8 files changed

+13
-18
lines changed

src/embind/embind.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ var LibraryEmbind = {
609609
// maxRange comes through as -1 for uint64_t (see issue 13902). Work around that temporarily
610610
if (isUnsignedType) {
611611
// Use string because acorn does recognize bigint literals
612-
maxRange = (BigInt(1) << BigInt(64)) - BigInt(1);
612+
maxRange = (1n << 64n) - 1n;
613613
}
614614

615615
registerType(primitiveType, {

src/library_pthread.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,11 +900,11 @@ var LibraryPThread = {
900900
#if WASM_BIGINT
901901
if (typeof arg == 'bigint') {
902902
// The prefix is non-zero to indicate a bigint.
903-
HEAP64[b + 2*i] = BigInt(1);
903+
HEAP64[b + 2*i] = 1n;
904904
HEAP64[b + 2*i + 1] = arg;
905905
} else {
906906
// The prefix is zero to indicate a JS Number.
907-
HEAP64[b + 2*i] = BigInt(0);
907+
HEAP64[b + 2*i] = 0n;
908908
HEAPF64[b + 2*i + 1] = arg;
909909
}
910910
#else

src/parseTools.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,12 +1133,7 @@ function defineI64Param(name) {
11331133

11341134
function receiveI64ParamAsI32s(name) {
11351135
if (WASM_BIGINT) {
1136-
// TODO: use Xn notation when JS parsers support it (as of April 6 2020,
1137-
// * closure compiler is missing support
1138-
// https://github.com/google/closure-compiler/issues/3167
1139-
// * acorn needs to be upgraded, and to set ecmascript version >= 11
1140-
// * terser needs to be upgraded
1141-
return `var ${name}_low = Number(${name} & BigInt(0xffffffff)) | 0, ${name}_high = Number(${name} >> BigInt(32)) | 0;`;
1136+
return `var ${name}_low = Number(${name} & 0xffffffffn) | 0, ${name}_high = Number(${name} >> 32n) | 0;`;
11421137
}
11431138
return '';
11441139
}
@@ -1155,7 +1150,7 @@ function receiveI64ParamAsI53(name, onError) {
11551150

11561151
function sendI64Argument(low, high) {
11571152
if (WASM_BIGINT) {
1158-
return 'BigInt(low) | (BigInt(high) << BigInt(32))';
1153+
return 'BigInt(low) | (BigInt(high) << 32n)';
11591154
}
11601155
return low + ', ' + high;
11611156
}

src/runtime_wasm64.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function instrumentWasmExportsForMemory64(exports) {
5757
// missing third argument will generate:
5858
// `TypeError: Cannot convert undefined to a BigInt`.
5959
// See https://github.com/WebAssembly/JS-BigInt-integration/issues/12
60-
return original(x, BigInt(y ? y : 0), BigInt(0));
60+
return original(x, BigInt(y ? y : 0), 0n);
6161
};
6262
} else if (['emscripten_stack_set_limits', '__set_stack_limits'].includes(name)) {
6363
// get 2 i64 arguments

tests/embind/embind.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ module({
640640

641641
test("passing Symbol or BigInt as floats always throws", function() {
642642
assert.throws(TypeError, function() { cm.const_ref_adder(Symbol('0'), 1); });
643-
assert.throws(TypeError, function() { cm.const_ref_adder(BigInt(0), 1); });
643+
assert.throws(TypeError, function() { cm.const_ref_adder(0n, 1); });
644644
});
645645

646646
if (cm['ASSERTIONS']) {

tests/return64bit/testbind_bigint.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ Module['runtest'] = function() {
1111
// Use eval to create BigInt, as no support for Xn notation yet in JS
1212
// optimizer.
1313
var bigint = _test_return64(eval('0xaabbccdd11223344n'));
14-
var low = Number(bigint & BigInt(0xffffffff));
15-
var high = Number(bigint >> BigInt(32));
14+
var low = Number(bigint & 0xffffffffn);
15+
var high = Number(bigint >> 32n);
1616
console.log("low = " + low);
1717
console.log("high = " + high);
1818

1919
var ptr = _get_func_ptr();
2020
bigint = dynCall('jj', ptr, [eval('0xabcdef1912345678n')]);
21-
low = Number(bigint & BigInt(0xffffffff));
22-
high = Number(bigint >> BigInt(32));
21+
low = Number(bigint & 0xffffffffn);
22+
high = Number(bigint >> 32n);
2323
console.log("low = " + low);
2424
console.log("high = " + high);
2525
};

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ def test_segfault(self):
18111811
18121812
EM_JS(Classey*, get_null, (), {
18131813
#if __wasm64__
1814-
return BigInt(0);
1814+
return 0n;
18151815
#else
18161816
return 0;
18171817
#endif

tools/js_manipulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def make_invoke(sig):
118118
# For function that needs to return a genuine i64 (i.e. if legal_sig[0] is 'j')
119119
# we need to return an actual BigInt, even in the exceptional case because
120120
# wasm won't implicitly convert undefined to 0 in this case.
121-
exceptional_ret = '\n return BigInt(0);' if legal_sig[0] == 'j' else ''
121+
exceptional_ret = '\n return 0n;' if legal_sig[0] == 'j' else ''
122122
body = '%s%s;' % (ret, make_dynCall(sig, args))
123123
# Exceptions thrown from C++ exception will be integer numbers.
124124
# longjmp will throw the number Infinity.

0 commit comments

Comments
 (0)