You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve handling of incoming i64 syscall arguments. (#16787)
Add new `receiveI64ParamAsI53` to replace the old
`receiveI64ParamAsDouble`. The new function checks the value fits
within I53 and requires an `onError` value to be returned in the case of
out-of-bounds.
`receiveI64ParamAsI53` makes use of the existing `convertI32PairToI53`
utility.
There is now some amount of duplication between `test_parseTools`
and `js_library_i64_params` which I would prefer to address as
a followup.
Copy file name to clipboardExpand all lines: src/parseTools.js
+15-8Lines changed: 15 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -689,6 +689,16 @@ function getHeapForType(type) {
689
689
assert(false,'bad heap type: '+type);
690
690
}
691
691
692
+
functionmakeReturn64(value){
693
+
if(WASM_BIGINT){
694
+
return`BigInt(${value})`;
695
+
}
696
+
constpair=splitI64(value);
697
+
// `return (a, b, c)` in JavaScript will execute `a`, and `b` and return the final
698
+
// element `c`
699
+
return`(setTempRet0(${pair[1]}), ${pair[0]})`;
700
+
}
701
+
692
702
functionmakeThrow(what){
693
703
if(ASSERTIONS&&DISABLE_EXCEPTION_CATCHING){
694
704
what+=' + " - Exception catching is disabled, this exception cannot be caught. Compile with -sNO_DISABLE_EXCEPTION_CATCHING or -sEXCEPTION_CATCHING_ALLOWED=[..] to catch."';
@@ -1100,17 +1110,14 @@ function receiveI64ParamAsI32s(name) {
1100
1110
return'';
1101
1111
}
1102
1112
1103
-
// TODO: use this in library_wasi.js and other places. but we need to add an
1104
-
// error-handling hook here.
1105
-
functionreceiveI64ParamAsDouble(name){
1113
+
functionreceiveI64ParamAsI53(name,onError){
1106
1114
if(WASM_BIGINT){
1107
1115
// Just convert the bigint into a double.
1108
-
return`var ${name} = Number(${name}_bigint);`;
1116
+
return`var ${name} = bigintToI53Checked(${name}_bigint); if (isNaN(${name})) return ${onError};`;
1109
1117
}
1110
-
1111
-
// Combine the i32 params. Use an unsigned operator on low and shift high by
0 commit comments