From f1cdbb4279b26c4b17ba61f49cd7eb7d7c59c263 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 23 Oct 2023 19:08:57 +0200 Subject: [PATCH] fix JS bitwise math --- www/public/repl/repl.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/www/public/repl/repl.js b/www/public/repl/repl.js index 0b35edee73a..c688e21833e 100644 --- a/www/public/repl/repl.js +++ b/www/public/repl/repl.js @@ -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