AssemblyScript loader experiments (#13)

This commit is contained in:
Ashwin Phatak
2021-12-28 16:08:04 +05:30
committed by nabarun
parent 889e96572d
commit 9e6f6b4519
3 changed files with 48 additions and 6 deletions
+34 -4
View File
@@ -3,13 +3,43 @@
//
import path from 'path';
import { expect } from 'chai';
import { instantiate } from './index';
const WASM_FILE_PATH = '../build/debug.wasm';
it('should execute exported function', async () => {
const filePath = path.resolve(__dirname, WASM_FILE_PATH);
const { exports } = await instantiate(filePath);
exports.callGraphAPI();
describe('wasm loader tests', () => {
let exports: any;
before(async () => {
const filePath = path.resolve(__dirname, WASM_FILE_PATH);
const instance = await instantiate(filePath);
exports = instance.exports;
});
it('should execute exported function', async () => {
const { callGraphAPI } = exports;
callGraphAPI();
});
it('should use a class/instance created in wasm from JS', async () => {
const { Foo, __getString, __pin, __unpin } = exports;
const fooPtr = __pin(Foo.getFoo());
const foo = Foo.wrap(fooPtr);
const strPtr = foo.getString();
expect(__getString(strPtr)).to.equal('hello world!');
__unpin(fooPtr);
});
it('should instantiate a class in wasm from JS', async () => {
const { Foo, FooID, __getString, __new, __pin, __unpin } = exports;
const newFooPtr = __pin(__new(FooID));
const newFoo = Foo.wrap(newFooPtr);
const newStrPtr = newFoo.getString();
expect(__getString(newStrPtr)).to.equal('hello world!');
__unpin(newFooPtr);
});
});