Skip to content

Commit a57de18

Browse files
committed
Add test for synchronous instantiation
1 parent 8eed715 commit a57de18

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

lib/asbind-instance/asbind-instance.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ function traverseObjectAndRunCallback(obj, callback, keys = [], baseObj = obj) {
2121
}
2222

2323
async function compileStreaming(source) {
24-
if (WebAssembly.compileStreaming) {
25-
return WebAssembly.compileStreaming(source);
26-
}
2724
source = await Promise.resolve(source);
2825
if (typeof Response === "object" && source instanceof Response) {
26+
if (WebAssembly.compileStreaming) {
27+
return WebAssembly.compileStreaming(source);
28+
}
2929
source = await source.arrayBuffer();
3030
}
3131
return WebAssembly.compile(source);

lib/asbind-instance/type-converters.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ function putArray(asbindInstance, value, typeName) {
8888

8989
export const converters = new Map([
9090
["void", { ascToJs: nop, jsToAsc: nop }],
91-
[/^(i|u|f)(8|16|32)$/, { ascToJs: nop, jsToAsc: nop }],
91+
// Technically this matches types that don’ exist (like f8),
92+
// but since those can only appear if the compiler accepts them,
93+
// it seems unlikely for that to be a problem.
94+
[/^(i|u|f)(8|16|32|64)$/, { ascToJs: nop, jsToAsc: nop }],
9295
["~lib/string/String", { ascToJs: getString, jsToAsc: putString }],
9396
[
9497
"~lib/typedarray/Int8Array",

test/test-runner.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
];
4242
const testPath = new URL(relativeTestPath, location.href);
4343
const wasmPath = new URL("./asc.wasm", testPath);
44-
this.rawModule = await fetch(wasmPath);
44+
this.rawModule = await fetch(wasmPath).then(r => r.arrayBuffer());
4545
}
4646
});
4747
</script>

test/tests/instantiateSync/asc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function exclaim(a: string): string {
2+
return a + "!";
3+
}

test/tests/instantiateSync/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
describe("as-bind", function() {
2+
it("works synchronously", function() {
3+
const instance = AsBind.instantiateSync(this.rawModule);
4+
assert(instance.exports.exclaim("a") === "a!");
5+
});
6+
});

0 commit comments

Comments
 (0)