Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/node_modules/@stdlib/wasm/module-wrapper/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
} else {
fcn = instantiate;
}
// FIXME: replace with `@stdlib/promise/ctor`

Check warning on line 175 in lib/node_modules/@stdlib/wasm/module-wrapper/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: replace with...'
return new Promise( fcn ); // eslint-disable-line stdlib/require-globals

/**
Expand All @@ -196,20 +196,21 @@
* @returns {void}
*/
function instantiate( resolve, reject ) {
var p = WebAssembly.instantiate( self._binary, self._imports ); // TODO: replace with `@stdlib/wasm/instantiate`

Check warning on line 199 in lib/node_modules/@stdlib/wasm/module-wrapper/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: replace with...'
p.then( onResolve, onReject );

/**
* Callback invoked upon fulfilling a promise.
*
* @private
* @param {Object} module - WebAssembly module
* @param {Object} instance - WebAssembly instance
* @param {Object} result - WebAssembly instantiation result
* @param {Object} result.module - WebAssembly module
* @param {Object} result.instance - WebAssembly instance
* @returns {void}
*/
function onResolve( module, instance ) {
self._module = module;
self._instance = instance;
function onResolve( result ) {
self._module = result.module;
self._instance = result.instance;
resolve( self );
}

Expand Down Expand Up @@ -247,20 +248,21 @@
return clbk( null, this );
}
self = this;
p = WebAssembly.instantiate( this._binary, this._imports ); // TODO: replace with `@stdlib/wasm/instantiate`

Check warning on line 251 in lib/node_modules/@stdlib/wasm/module-wrapper/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: replace with...'
p.then( onResolve, onReject );

/**
* Callback invoked upon fulfilling a promise.
*
* @private
* @param {Object} module - WebAssembly module
* @param {Object} instance - WebAssembly instance
* @param {Object} result - WebAssembly instantiation result
* @param {Object} result.module - WebAssembly module
* @param {Object} result.instance - WebAssembly instance
* @returns {void}
*/
function onResolve( module, instance ) {
self._module = module;
self._instance = instance;
function onResolve( result ) {
self._module = result.module;
self._instance = result.instance;
clbk( null, self );
}

Expand Down Expand Up @@ -292,8 +294,8 @@
if ( this._instance ) {
return this;
}
this._module = new WebAssembly.Module( this._binary ); // TODO: replace with `@stdlib/wasm/module`

Check warning on line 297 in lib/node_modules/@stdlib/wasm/module-wrapper/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: replace with `@stdlib/wasm/module`'
this._instance = new WebAssembly.Instance( this._module, this._imports ); // TODO: replace with `@stdlib/wasm/instantiate`

Check warning on line 298 in lib/node_modules/@stdlib/wasm/module-wrapper/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: replace with...'
return this;
});

Expand Down
102 changes: 100 additions & 2 deletions lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,107 @@ tape( 'if an environment does not support `WebAssembly`, the function throws an
});

tape( 'the function is a constructor', opts, function test( t ) {
// TODO: write tests
var wasm;
var mod;

wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] );
mod = new Module( wasm, null );

t.strictEqual( mod instanceof Module, true, 'returns expected value' );
t.end();
});

// TODO: add tests
tape( 'the function returns an instance having an `initialize` method which returns a promise', opts, function test( t ) {
var wasm;
var mod;
var p;

wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] );
mod = new Module( wasm, null );
p = mod.initialize();

t.strictEqual( typeof p.then, 'function', 'returns expected value' );
t.end();
});

tape( 'the function returns an instance having an `initialize` method which returns a promise resolving with the module instance', opts, function test( t ) {
var wasm;
var mod;

wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] );
mod = new Module( wasm, null );

mod.initialize().then( onResolve, onReject );

function onResolve( result ) {
t.strictEqual( result, mod, 'resolves expected value' );
t.strictEqual( typeof result.exports, 'object', 'returns expected value' );
t.end();
}

function onReject( error ) {
t.fail( 'should not reject: ' + error.message );
t.end();
}
});

tape( 'the function returns an instance having an `initializeAsync` method which invokes a callback', opts, function test( t ) {
var wasm;
var mod;

wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] );
mod = new Module( wasm, null );

mod.initializeAsync( clbk );

function clbk( error ) {
if ( error ) {
t.fail( 'callback received an error: ' + error.message );
} else {
t.pass( 'callback invoked without error' );
}
t.end();
}
});

tape( 'the function returns an instance having an `initializeAsync` method which invokes a callback with the module instance', opts, function test( t ) {
var wasm;
var mod;

wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] );
mod = new Module( wasm, null );

mod.initializeAsync( clbk );

function clbk( error, result ) {
if ( error ) {
t.fail( 'callback received an error: ' + error.message );
t.end();
return;
}
t.strictEqual( result, mod, 'returns expected value' );
t.strictEqual( typeof result.exports, 'object', 'returns expected value' );
t.end();
}
});

tape( 'the function returns an instance having an `exports` property which is available after initialization', opts, function test( t ) {
var wasm;
var mod;

wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] );
mod = new Module( wasm, null );

mod.initialize().then( onResolve, onReject );

function onResolve( result ) {
var exports = result.exports;
t.strictEqual( typeof exports, 'object', 'returns expected value' );
t.end();
}

function onReject( error ) {
t.fail( 'should not reject: ' + error.message );
t.end();
}
});