Skip to content

Commit

Permalink
Fixed values not being returned by import funciton, #14
Browse files Browse the repository at this point in the history
  • Loading branch information
torch2424 committed Jan 19, 2020
1 parent 80ba800 commit 458b65a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/bind-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ export function bindImportFunction(
});

// Call the import function
originalImport.apply(null, argumentsWithReplacedRefs);
const response = originalImport.apply(null, argumentsWithReplacedRefs);

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

// Initialize the state of our function
Expand Down
7 changes: 6 additions & 1 deletion test/assembly/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export function mapFloat64Array(array: Float64Array): Float64Array {
return array.map((value: f64) => value * 2);
}

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

declare function testImportReturnNumber(): i32;
export function callTestImportReturnNumber(): i32 {
let response: i32 = testImportReturnNumber();
return response;
}

declare function testImportInt8Array(value: Int8Array): void;
export function callTestImportInt8Array(value: Int8Array): void {
testImportInt8Array(value);
Expand Down
Binary file modified test/assembly/test.wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("asbind", () => {
test: {
testImportString: () => {},
testImportTwoStrings: () => {},
testImportReturnNumber: () => -1,
testImportInt8Array: () => {},
testImportUint8Array: () => {},
testImportInt16Array: () => {},
Expand Down Expand Up @@ -160,6 +161,7 @@ describe("asbind", () => {
testImportTwoStrings: (value1, value2) => {
testImportCalledWith = [value1, value2];
},
testImportReturnNumber: () => -1,
testImportInt8Array: importObjectFunction,
testImportUint8Array: importObjectFunction,
testImportInt16Array: importObjectFunction,
Expand Down Expand Up @@ -192,6 +194,11 @@ describe("asbind", () => {
assert.equal(testImportCalledWith[1], "asbind2");
});

it("should allow numbers to be returned from the importObject", () => {
const response = asbindInstance.exports.callTestImportReturnNumber();
assert.equal(response, -1);
});

// TypedArrays
[
"Int8Array",
Expand Down Expand Up @@ -234,6 +241,7 @@ describe("asbind", () => {
testImportTwoStrings: (value1, value2) => {
testImportCalledWith = [value1, value2];
},
testImportReturnNumber: () => -1,
testImportInt8Array: importObjectFunction,
testImportUint8Array: importObjectFunction,
testImportInt16Array: importObjectFunction,
Expand Down

0 comments on commit 458b65a

Please sign in to comment.