Skip to content

Commit 5b1c48d

Browse files
committed
Maybe fix
1 parent 644758d commit 5b1c48d

File tree

4 files changed

+49
-85
lines changed

4 files changed

+49
-85
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"test:js-ext": "deno task test:main --js-ext mjs --out lib_out_js_file && cat tests/lib_out_js_file/deno_test.mjs > /dev/null",
2727
"test:check": "deno task test:main --check",
2828
"test:inline": "deno task test:main --inline --out lib_inline",
29-
"test:start": "cd tests && deno run -A ../main.ts -p deno_test --features start && deno test -A test.ts"
29+
"test:start": "cd tests && deno run -A ../main.ts -p deno_test --features start && USES_START=1 deno test -A test.ts"
3030
},
3131
"imports": {
3232
"@david/path": "jsr:@david/path@^0.2.0",

lib/wasmbuild_bg.js

Lines changed: 47 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ export function __wbg_set_wasm(val) {
88
wasm = val;
99
}
1010

11-
const heap = new Array(128).fill(undefined);
12-
13-
heap.push(undefined, null, true, false);
14-
15-
function getObject(idx) {
16-
return heap[idx];
17-
}
18-
1911
let WASM_VECTOR_LEN = 0;
2012

2113
let cachedUint8ArrayMemory0 = null;
@@ -100,17 +92,6 @@ function getDataViewMemory0() {
10092
return cachedDataViewMemory0;
10193
}
10294

103-
let heap_next = heap.length;
104-
105-
function addHeapObject(obj) {
106-
if (heap_next === heap.length) heap.push(heap.length + 1);
107-
const idx = heap_next;
108-
heap_next = heap[idx];
109-
110-
heap[idx] = obj;
111-
return idx;
112-
}
113-
11495
const lTextDecoder = typeof TextDecoder === "undefined"
11596
? (0, module.require)("util").TextDecoder
11697
: TextDecoder;
@@ -129,62 +110,48 @@ function getStringFromWasm0(ptr, len) {
129110
);
130111
}
131112

132-
function dropObject(idx) {
133-
if (idx < 132) return;
134-
heap[idx] = heap_next;
135-
heap_next = idx;
136-
}
137-
138-
function takeObject(idx) {
139-
const ret = getObject(idx);
140-
dropObject(idx);
141-
return ret;
142-
}
143-
144113
function passArray8ToWasm0(arg, malloc) {
145114
const ptr = malloc(arg.length * 1, 1) >>> 0;
146115
getUint8ArrayMemory0().set(arg, ptr / 1);
147116
WASM_VECTOR_LEN = arg.length;
148117
return ptr;
149118
}
119+
120+
function takeFromExternrefTable0(idx) {
121+
const value = wasm.__wbindgen_export_2.get(idx);
122+
wasm.__externref_table_dealloc(idx);
123+
return value;
124+
}
150125
/**
151126
* @param {string} name
152127
* @param {string} ext
153128
* @param {Uint8Array} wasm_bytes
154129
* @returns {any}
155130
*/
156131
export function generate_bindgen(name, ext, wasm_bytes) {
157-
try {
158-
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
159-
const ptr0 = passStringToWasm0(
160-
name,
161-
wasm.__wbindgen_malloc,
162-
wasm.__wbindgen_realloc,
163-
);
164-
const len0 = WASM_VECTOR_LEN;
165-
const ptr1 = passStringToWasm0(
166-
ext,
167-
wasm.__wbindgen_malloc,
168-
wasm.__wbindgen_realloc,
169-
);
170-
const len1 = WASM_VECTOR_LEN;
171-
const ptr2 = passArray8ToWasm0(wasm_bytes, wasm.__wbindgen_malloc);
172-
const len2 = WASM_VECTOR_LEN;
173-
wasm.generate_bindgen(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
174-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
175-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
176-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
177-
if (r2) {
178-
throw takeObject(r1);
179-
}
180-
return takeObject(r0);
181-
} finally {
182-
wasm.__wbindgen_add_to_stack_pointer(16);
132+
const ptr0 = passStringToWasm0(
133+
name,
134+
wasm.__wbindgen_malloc,
135+
wasm.__wbindgen_realloc,
136+
);
137+
const len0 = WASM_VECTOR_LEN;
138+
const ptr1 = passStringToWasm0(
139+
ext,
140+
wasm.__wbindgen_malloc,
141+
wasm.__wbindgen_realloc,
142+
);
143+
const len1 = WASM_VECTOR_LEN;
144+
const ptr2 = passArray8ToWasm0(wasm_bytes, wasm.__wbindgen_malloc);
145+
const len2 = WASM_VECTOR_LEN;
146+
const ret = wasm.generate_bindgen(ptr0, len0, ptr1, len1, ptr2, len2);
147+
if (ret[2]) {
148+
throw takeFromExternrefTable0(ret[1]);
183149
}
150+
return takeFromExternrefTable0(ret[0]);
184151
}
185152

186153
export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) {
187-
const ret = String(getObject(arg1));
154+
const ret = String(arg1);
188155
const ptr1 = passStringToWasm0(
189156
ret,
190157
wasm.__wbindgen_malloc,
@@ -197,64 +164,65 @@ export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) {
197164

198165
export function __wbg_new_405e22f390576ce2() {
199166
const ret = new Object();
200-
return addHeapObject(ret);
167+
return ret;
201168
}
202169

203170
export function __wbg_new_5e0be73521bc8c17() {
204171
const ret = new Map();
205-
return addHeapObject(ret);
172+
return ret;
206173
}
207174

208175
export function __wbg_new_78feb108b6472713() {
209176
const ret = new Array();
210-
return addHeapObject(ret);
177+
return ret;
211178
}
212179

213180
export function __wbg_new_c68d7209be747379(arg0, arg1) {
214181
const ret = new Error(getStringFromWasm0(arg0, arg1));
215-
return addHeapObject(ret);
182+
return ret;
216183
}
217184

218185
export function __wbg_set_37837023f3d740e8(arg0, arg1, arg2) {
219-
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
186+
arg0[arg1 >>> 0] = arg2;
220187
}
221188

222189
export function __wbg_set_3f1d0b984ed272ed(arg0, arg1, arg2) {
223-
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
190+
arg0[arg1] = arg2;
224191
}
225192

226193
export function __wbg_set_8fc6bf8a5b1071d1(arg0, arg1, arg2) {
227-
const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
228-
return addHeapObject(ret);
194+
const ret = arg0.set(arg1, arg2);
195+
return ret;
229196
}
230197

231198
export function __wbindgen_error_new(arg0, arg1) {
232199
const ret = new Error(getStringFromWasm0(arg0, arg1));
233-
return addHeapObject(ret);
200+
return ret;
201+
}
202+
203+
export function __wbindgen_init_externref_table() {
204+
const table = wasm.__wbindgen_export_2;
205+
const offset = table.grow(4);
206+
table.set(0, undefined);
207+
table.set(offset + 0, undefined);
208+
table.set(offset + 1, null);
209+
table.set(offset + 2, true);
210+
table.set(offset + 3, false);
234211
}
235212

236213
export function __wbindgen_is_string(arg0) {
237-
const ret = typeof (getObject(arg0)) === "string";
214+
const ret = typeof arg0 === "string";
238215
return ret;
239216
}
240217

241218
export function __wbindgen_number_new(arg0) {
242219
const ret = arg0;
243-
return addHeapObject(ret);
244-
}
245-
246-
export function __wbindgen_object_clone_ref(arg0) {
247-
const ret = getObject(arg0);
248-
return addHeapObject(ret);
249-
}
250-
251-
export function __wbindgen_object_drop_ref(arg0) {
252-
takeObject(arg0);
220+
return ret;
253221
}
254222

255223
export function __wbindgen_string_new(arg0, arg1) {
256224
const ret = getStringFromWasm0(arg0, arg1);
257-
return addHeapObject(ret);
225+
return ret;
258226
}
259227

260228
export function __wbindgen_throw(arg0, arg1) {

lib/wasmbuild_bg.wasm

18.6 KB
Binary file not shown.

tests/test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import * as wasm from "./lib/deno_test.js";
33
import * as wasm2 from "./lib_inline/deno_test.js";
44

55
Deno.test("test works export", () => {
6-
function hasStart() {
7-
return Deno.readTextFileSync(import.meta.dirname + "/lib/deno_test.js")
8-
.includes("__wbindgen_start");
9-
}
106
assertEquals(
117
wasm.greet("Deno"),
12-
hasStart() ? "Hello, Deno! Result: 4" : "Hello, Deno! Result: 3",
8+
Deno.env.get("USES_START") ? "Hello, Deno! Result: 4" : "Hello, Deno! Result: 3",
139
);
1410
});
1511

0 commit comments

Comments
 (0)