From c013b2493ded9e4be644b89b9ca74ac62019a7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Mon, 23 May 2022 20:08:47 +0200 Subject: [PATCH] Revert "Grow table from within WebAssembly" It doesn't work in Node 16 (used by GitHub actions) This reverts commit 2747458242c27c6bcf2474a3f760c26cd8f2e9f2. --- src/waforth.wat | 9 +++------ src/web/waforth.ts | 3 +++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/waforth.wat b/src/waforth.wat index 83baae2..e657999 100644 --- a/src/waforth.wat +++ b/src/waforth.wat @@ -2201,12 +2201,9 @@ (global.set $cp (i32.add (global.get $cp) (local.get $nameLength))))) ;; Load the code - (if (i32.ge_u (global.get $nextTableIndex) (table.size 0)) - (then (drop (table.grow 0 (ref.func $!) (table.size 0))))) ;; Double size - (call $shell_load - (i32.const 0x1000 (; = MODULE_HEADER_BASE ;)) - (i32.sub (global.get $cp) (i32.const 0x1000 (; = MODULE_HEADER_BASE ;))) - (global.get $nextTableIndex)) + (call $shell_load (i32.const 0x1000 (; = MODULE_HEADER_BASE ;)) + (i32.sub (global.get $cp) (i32.const 0x1000 (; = MODULE_HEADER_BASE ;))) + (global.get $nextTableIndex)) (global.set $nextTableIndex (i32.add (global.get $nextTableIndex) (i32.const 1)))) diff --git a/src/web/waforth.ts b/src/web/waforth.ts index ebdac49..ded122a 100644 --- a/src/web/waforth.ts +++ b/src/web/waforth.ts @@ -147,6 +147,9 @@ class WAForth { } data = new Uint8Array(dataCopy); } + if (index >= table.length) { + table.grow(table.length); // Double size + } // console.log("Load", index, arrayToBase64(data)); try { var module = new WebAssembly.Module(data);