diff --git a/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib.js b/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib.js index 706ad37970..1264153823 100644 --- a/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib.js +++ b/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib.js @@ -23,18 +23,9 @@ function getStringFromWasm0(ptr, len) { return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); } -const heap = new Array(128).fill(undefined); - -heap.push(undefined, null, true, false); - -let heap_next = heap.length; - -function addHeapObject(obj) { - if (heap_next === heap.length) heap.push(heap.length + 1); - const idx = heap_next; - heap_next = heap[idx]; - - heap[idx] = obj; +function addToExternrefTable0(obj) { + const idx = wasm.__externref_table_alloc(); + wasm.__wbindgen_export_3.set(idx, obj); return idx; } @@ -42,7 +33,8 @@ function handleError(f, args) { try { return f.apply(this, args); } catch (e) { - wasm.__wbindgen_exn_store(addHeapObject(e)); + const idx = addToExternrefTable0(e); + wasm.__wbindgen_exn_store(idx); } } @@ -111,33 +103,25 @@ function getDataViewMemory0() { return cachedDataViewMemory0; } -function getObject(idx) { return heap[idx]; } - -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - function isLikeNone(x) { return x === undefined || x === null; } function passArrayJsValueToWasm0(array, malloc) { const ptr = malloc(array.length * 4, 4) >>> 0; - const mem = getDataViewMemory0(); for (let i = 0; i < array.length; i++) { - mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true); + const add = addToExternrefTable0(array[i]); + getDataViewMemory0().setUint32(ptr + 4 * i, add, true); } WASM_VECTOR_LEN = array.length; return ptr; } + +function takeFromExternrefTable0(idx) { + const value = wasm.__wbindgen_export_3.get(idx); + wasm.__externref_table_dealloc(idx); + return value; +} /** * Convert schema.json to OpenAPI. The `cwd` argument is the current directory to be used * if not the system-defined one, as is the case when running with `npm rum --prefix compiler` @@ -145,20 +129,13 @@ function passArrayJsValueToWasm0(array, malloc) { * @param {string | null} [cwd] */ module.exports.convert_schema_to_openapi = function(args, cwd) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passArrayJsValueToWasm0(args, wasm.__wbindgen_malloc); - const len0 = WASM_VECTOR_LEN; - var ptr1 = isLikeNone(cwd) ? 0 : passStringToWasm0(cwd, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - wasm.convert_schema_to_openapi(retptr, ptr0, len0, ptr1, len1); - var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); - var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); - if (r1) { - throw takeObject(r0); - } - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); + const ptr0 = passArrayJsValueToWasm0(args, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + var ptr1 = isLikeNone(cwd) ? 0 : passStringToWasm0(cwd, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + const ret = wasm.convert_schema_to_openapi(ptr0, len0, ptr1, len1); + if (ret[1]) { + throw takeFromExternrefTable0(ret[0]); } }; @@ -221,7 +198,7 @@ module.exports.__wbg_measure_fb7825c11612c823 = function() { return handleError( module.exports.__wbg_new_8a6f238a6ece86ea = function() { const ret = new Error(); - return addHeapObject(ret); + return ret; }; module.exports.__wbg_readFileSync_691af69453e7d4ec = function(arg0, arg1, arg2, arg3, arg4) { @@ -233,7 +210,7 @@ module.exports.__wbg_readFileSync_691af69453e7d4ec = function(arg0, arg1, arg2, }; module.exports.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) { - const ret = getObject(arg1).stack; + const ret = arg1.stack; const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); const len1 = WASM_VECTOR_LEN; getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); @@ -244,12 +221,19 @@ module.exports.__wbg_writeFileSync_d2c5ed0808e00dc9 = function(arg0, arg1, arg2, writeFileSync(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3)); }; -module.exports.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); +module.exports.__wbindgen_init_externref_table = function() { + const table = wasm.__wbindgen_export_3; + const offset = table.grow(4); + table.set(0, undefined); + table.set(offset + 0, undefined); + table.set(offset + 1, null); + table.set(offset + 2, true); + table.set(offset + 3, false); + ; }; module.exports.__wbindgen_string_get = function(arg0, arg1) { - const obj = getObject(arg1); + const obj = arg1; const ret = typeof(obj) === 'string' ? obj : undefined; var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); var len1 = WASM_VECTOR_LEN; @@ -259,7 +243,7 @@ module.exports.__wbindgen_string_get = function(arg0, arg1) { module.exports.__wbindgen_string_new = function(arg0, arg1) { const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); + return ret; }; module.exports.__wbindgen_throw = function(arg0, arg1) { @@ -274,3 +258,5 @@ const wasmInstance = new WebAssembly.Instance(wasmModule, imports); wasm = wasmInstance.exports; module.exports.__wasm = wasm; +wasm.__wbindgen_start(); + diff --git a/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm b/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm index b0b39f9a35..b731a5028a 100644 Binary files a/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm and b/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm differ diff --git a/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm.d.ts b/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm.d.ts index f9645942c4..2d4f44aee3 100644 --- a/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm.d.ts +++ b/compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm.d.ts @@ -1,9 +1,12 @@ /* tslint:disable */ /* eslint-disable */ export const memory: WebAssembly.Memory; -export const convert_schema_to_openapi: (a: number, b: number, c: number, d: number, e: number) => void; +export const convert_schema_to_openapi: (a: number, b: number, c: number, d: number) => [number, number]; export const __wbindgen_free: (a: number, b: number, c: number) => void; export const __wbindgen_exn_store: (a: number) => void; +export const __externref_table_alloc: () => number; +export const __wbindgen_export_3: WebAssembly.Table; export const __wbindgen_malloc: (a: number, b: number) => number; export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number; -export const __wbindgen_add_to_stack_pointer: (a: number) => number; +export const __externref_table_dealloc: (a: number) => void; +export const __wbindgen_start: () => void;