Skip to content

Commit 72ecf73

Browse files
committed
Don't crash on unexpected imports
1 parent 9510a8b commit 72ecf73

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lib/asbind-instance/bind-function.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ export function bindImportFunction(
159159
importObjectKeyPathToFunction
160160
);
161161
if (!importedFunctionDescriptor) {
162-
throw Error(`Unknown function ${importObjectKeyPathToFunction.join(".")}`);
162+
console.warn(
163+
`Unexpected function ${importObjectKeyPathToFunction.join(
164+
"."
165+
)} on import object, using pass-through.`
166+
);
167+
return importedFunction;
163168
}
164169

165170
// Grab type converter functions according to the type descriptor

test/tests/unexpected-import/asc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function thing(): i8 {
2+
return -1;
3+
}

test/tests/unexpected-import/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
describe("as-bind", function() {
2+
it("should handle unexpected imports gracefully", async function() {
3+
const instance = await AsBind.instantiate(this.rawModule, {
4+
env: {
5+
someFunc() {}
6+
}
7+
});
8+
assert(instance.exports.thing() === -1);
9+
});
10+
});

0 commit comments

Comments
 (0)