]> git.codecow.com Git - nano25519.git/commitdiff
Print error strings from WASM data.
authorChris Duncan <chris@zoso.dev>
Thu, 13 Aug 2026 07:41:28 +0000 (00:41 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 13 Aug 2026 07:41:28 +0000 (00:41 -0700)
src/lib/nano25519.ts

index 8fd0115d6130c76480605ddc09d577e214565359..63967a6ff821f9f24b64918ac1499ba1a1cb200c 100644 (file)
@@ -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