Skip to content

Commit a1f7e52

Browse files
committed
Use pass-through for unknown types
1 parent f6f4594 commit a1f7e52

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lib/asbind-instance/bind-function.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ function getConverterForType(typeName) {
7373
return converter;
7474
}
7575
}
76-
throw Error(`No converter for ${JSON.stringify(typeName)}`);
76+
console.warn(
77+
`No converter for ${JSON.stringify(typeName)}, using pass-through`
78+
);
79+
return { ascToJs: nop, jsToAsc: nop };
7780
}
7881

7982
function getAscToJsConverterForType(typeName) {

test/tests/unknown-type/asc.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class X {
2+
x: u32;
3+
constructor(x: u32) {
4+
this.x = x;
5+
}
6+
}
7+
export function makeAThing(v: u32): X {
8+
return new X(v);
9+
}

test/tests/unknown-type/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("should handle unknown types gracefully", async function() {
3+
const instance = await AsBind.instantiate(this.rawModule);
4+
assert(typeof instance.exports.makeAThing(43) === "number");
5+
});
6+
});

0 commit comments

Comments
 (0)