Skip to content

Commit

Permalink
fix JS bitwise math
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Oct 23, 2023
1 parent eb61d35 commit f1cdbb4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion www/public/repl/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ function send_panic_msg_to_js(rocstr_ptr, panic_tag) {
let stringBytes = "";
if (finalByte < 0) {
// small string
const length = finalByte ^ 0b1000_0000;

// bitwise ops on negative JS numbers are weird. This clears the bit that we
// use to indicate a small string. In rust it's `finalByte as u8 ^ 0b1000_0000`
const length = finalByte + 128;
stringBytes = new Uint8Array(memory.buffer, rocstr_ptr, length);
} else {
// big string
Expand Down

0 comments on commit f1cdbb4

Please sign in to comment.