From ca9843a276fa97d095c8ebdc8fb6bc0509b6aa67 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 13 Aug 2026 00:41:28 -0700 Subject: [PATCH] Print error strings from WASM data. --- src/lib/nano25519.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/lib/nano25519.ts b/src/lib/nano25519.ts index 8fd0115..63967a6 100644 --- a/src/lib/nano25519.ts +++ b/src/lib/nano25519.ts @@ -22,13 +22,24 @@ export const nano25519_init = (bytes: number[]): { derive: typeof derive, sign: const { exports } = new WebAssembly.Instance(module, { env: { abort: (msg: any, file: any, row: any, col: any) => { + const getString = (pointer: number): string | null => { + const end = pointer + new Uint32Array(exports.memory.buffer)[pointer - 4 >>> 2] >>> 1 + const buf = new Uint16Array(exports.memory.buffer) + let start = pointer >>> 1 + let string = '' + while (end - start > 1024) { + string += String.fromCharCode(...buf.subarray(start, start += 1024)) + } + return string + String.fromCharCode(...buf.subarray(start, end)) + } // ~lib/builtins/abort(~lib/string/String | null?, ~lib/string/String | null?, u32?, u32?) => void - msg = msg >>> 0 - file = file >>> 0 - row = row >>> 0 - col = col >>> 0 - console.error('wasm abort:', `msg ${msg}`, `file ${file}`, `row ${row}`, `col ${col}`) - throw new Error(msg, { cause: { file, row, col } }) + msg >>>= 0 + file >>>= 0 + row >>>= 0 + col >>>= 0 + const message = 'nano25519/async wasm abort' + console.error(message, getString(msg), getString(file), { msg, file, row, col }) + throw new Error(message) }, "performance.now" () { // ~lib/bindings/dom/performance.now() => f64 -- 2.52.0