Skip to content

Commit 458b65a

Browse files
committed
Fixed values not being returned by import funciton, #14
1 parent 80ba800 commit 458b65a

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

lib/bind-function.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ export function bindImportFunction(
8585
});
8686

8787
// Call the import function
88-
originalImport.apply(null, argumentsWithReplacedRefs);
88+
const response = originalImport.apply(null, argumentsWithReplacedRefs);
8989

90-
// TODO: Returning from Import functions is not supported by asbind :(
90+
// TODO: Returning High-level types from Import functions is not supported by asbind :(
91+
return response;
9192
};
9293

9394
// Initialize the state of our function

test/assembly/test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export function mapFloat64Array(array: Float64Array): Float64Array {
5252
return array.map((value: f64) => value * 2);
5353
}
5454

55-
// NOTE: Asbind does not support return types on import object functions
5655
declare function testImportString(value: string): void;
5756
export function callTestImportString(value: string): void {
5857
testImportString(value);
@@ -66,6 +65,12 @@ export function callTestImportTwoStrings(
6665
testImportTwoStrings(valueOne, valueTwo);
6766
}
6867

68+
declare function testImportReturnNumber(): i32;
69+
export function callTestImportReturnNumber(): i32 {
70+
let response: i32 = testImportReturnNumber();
71+
return response;
72+
}
73+
6974
declare function testImportInt8Array(value: Int8Array): void;
7075
export function callTestImportInt8Array(value: Int8Array): void {
7176
testImportInt8Array(value);

test/assembly/test.wasm

165 Bytes
Binary file not shown.

test/test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe("asbind", () => {
99
test: {
1010
testImportString: () => {},
1111
testImportTwoStrings: () => {},
12+
testImportReturnNumber: () => -1,
1213
testImportInt8Array: () => {},
1314
testImportUint8Array: () => {},
1415
testImportInt16Array: () => {},
@@ -160,6 +161,7 @@ describe("asbind", () => {
160161
testImportTwoStrings: (value1, value2) => {
161162
testImportCalledWith = [value1, value2];
162163
},
164+
testImportReturnNumber: () => -1,
163165
testImportInt8Array: importObjectFunction,
164166
testImportUint8Array: importObjectFunction,
165167
testImportInt16Array: importObjectFunction,
@@ -192,6 +194,11 @@ describe("asbind", () => {
192194
assert.equal(testImportCalledWith[1], "asbind2");
193195
});
194196

197+
it("should allow numbers to be returned from the importObject", () => {
198+
const response = asbindInstance.exports.callTestImportReturnNumber();
199+
assert.equal(response, -1);
200+
});
201+
195202
// TypedArrays
196203
[
197204
"Int8Array",
@@ -234,6 +241,7 @@ describe("asbind", () => {
234241
testImportTwoStrings: (value1, value2) => {
235242
testImportCalledWith = [value1, value2];
236243
},
244+
testImportReturnNumber: () => -1,
237245
testImportInt8Array: importObjectFunction,
238246
testImportUint8Array: importObjectFunction,
239247
testImportInt16Array: importObjectFunction,

0 commit comments

Comments
 (0)