-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
60 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class X { | ||
x: string; | ||
constructor(x: string) { | ||
this.x = x; | ||
} | ||
} | ||
export function makeAThing(v: string): X { | ||
return new X(v); | ||
} | ||
|
||
export function readAThing(v: X): u32 { | ||
return v.x.length; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
describe("as-bind", function() { | ||
it("should be extensible with custom type handlers", async function() { | ||
AsBind.converters.set(/^tests\/custom-type\/asc\/X$/, { | ||
ascToJs(asbindInstance, value, typeName) { | ||
const dv = new DataView(asbindInstance.exports.memory.buffer); | ||
const strPtr = dv.getUint32(value, true); | ||
return asbindInstance.exports.__getString(strPtr); | ||
}, | ||
jsToAsc(asbindInstance, value, typeName) { | ||
const ptr = asbindInstance.exports.__new( | ||
asbindInstance.getTypeId(typeName), | ||
asbindInstance.getTypeSize(typeName) | ||
); | ||
const strPtr = asbindInstance.exports.__newString(value); | ||
const dv = new DataView(asbindInstance.exports.memory.buffer); | ||
dv.setUint32(ptr, strPtr, true); | ||
return ptr; | ||
} | ||
}); | ||
const instance = await AsBind.instantiate(this.rawModule); | ||
assert(instance.exports.makeAThing("hello") === "hello"); | ||
assert(instance.exports.readAThing("hello") === 5); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters