From 25301a39ac0eb83e6fba87049139ac07a4c4e364 Mon Sep 17 00:00:00 2001 From: shiavm006 Date: Tue, 13 Jan 2026 11:12:57 +0530 Subject: [PATCH 1/5] fix: correct WebAssembly.instantiate callback signature in module-wrapper --- .../@stdlib/wasm/module-wrapper/lib/main.js | 22 ++-- .../@stdlib/wasm/module-wrapper/test/test.js | 108 +++++++++++++++++- 2 files changed, 118 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/wasm/module-wrapper/lib/main.js b/lib/node_modules/@stdlib/wasm/module-wrapper/lib/main.js index 1653a9971200..036504131b1a 100644 --- a/lib/node_modules/@stdlib/wasm/module-wrapper/lib/main.js +++ b/lib/node_modules/@stdlib/wasm/module-wrapper/lib/main.js @@ -203,13 +203,14 @@ setReadOnly( WasmModule.prototype, 'initialize', function initialize() { * 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 ); } @@ -254,13 +255,14 @@ setReadOnly( WasmModule.prototype, 'initializeAsync', function initializeAsync( * 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 ); } diff --git a/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js b/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js index d505ebcb4a19..b1f833dce643 100644 --- a/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js +++ b/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js @@ -67,9 +67,113 @@ 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 mod; + var wasm; + wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); + mod = new Module( wasm, null ); + + t.strictEqual( mod instanceof Module, true, 'returns an instance' ); + t.end(); +}); + +tape( 'the `initialize` method returns a promise', opts, function test( t ) { + var mod; + var wasm; + 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 a promise' ); t.end(); }); -// TODO: add tests +tape( 'the `initialize` method properly sets `_module` and `_instance` properties', opts, function test( t ) { + var mod; + var wasm; + + 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 with module instance' ); + t.strictEqual( typeof result._module, 'object', '_module is set' ); + t.strictEqual( typeof result._instance, 'object', '_instance is set' ); + t.strictEqual( result._module.constructor.name, 'Module', '_module is a WebAssembly.Module' ); + t.strictEqual( result._instance.constructor.name, 'Instance', '_instance is a WebAssembly.Instance' ); + t.end(); + } + + function onReject( error ) { + t.fail( 'should not reject: ' + error.message ); + t.end(); + } +}); + +tape( 'the `initializeAsync` method invokes a callback', opts, function test( t ) { + var mod; + var wasm; + + 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 ); + } else { + t.pass( 'callback invoked without error' ); + } + t.end(); + } +}); + +tape( 'the `initializeAsync` method properly sets `_module` and `_instance` properties', opts, function test( t ) { + var mod; + var wasm; + + 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, 'callback receives module instance' ); + t.strictEqual( typeof result._module, 'object', '_module is set' ); + t.strictEqual( typeof result._instance, 'object', '_instance is set' ); + t.strictEqual( result._module.constructor.name, 'Module', '_module is a WebAssembly.Module' ); + t.strictEqual( result._instance.constructor.name, 'Instance', '_instance is a WebAssembly.Instance' ); + t.end(); + } +}); + +tape( 'the `exports` property returns instance exports after initialization', opts, function test( t ) { + var mod; + var wasm; + + 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', 'exports is an object' ); + t.end(); + } + + function onReject( error ) { + t.fail( 'should not reject: ' + error.message ); + t.end(); + } +}); From ae8554c303b16cf157c1f0fe59a1eb6ad40f7cf3 Mon Sep 17 00:00:00 2001 From: shiavm006 Date: Tue, 13 Jan 2026 11:21:27 +0530 Subject: [PATCH 2/5] fix: resolve linting errors in test file --- .../@stdlib/wasm/module-wrapper/test/test.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js b/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js index b1f833dce643..24d68cbd26f4 100644 --- a/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js +++ b/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js @@ -16,6 +16,8 @@ * limitations under the License. */ +/* eslint-disable no-underscore-dangle */ + 'use strict'; // MODULES // @@ -67,8 +69,8 @@ tape( 'if an environment does not support `WebAssembly`, the function throws an }); tape( 'the function is a constructor', opts, function test( t ) { - var mod; var wasm; + var mod; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); mod = new Module( wasm, null ); @@ -78,8 +80,8 @@ tape( 'the function is a constructor', opts, function test( t ) { }); tape( 'the `initialize` method returns a promise', opts, function test( t ) { - var mod; var wasm; + var mod; var p; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); @@ -91,8 +93,8 @@ tape( 'the `initialize` method returns a promise', opts, function test( t ) { }); tape( 'the `initialize` method properly sets `_module` and `_instance` properties', opts, function test( t ) { - var mod; var wasm; + var mod; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); mod = new Module( wasm, null ); @@ -115,15 +117,15 @@ tape( 'the `initialize` method properly sets `_module` and `_instance` propertie }); tape( 'the `initializeAsync` method invokes a callback', opts, function test( t ) { - var mod; 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 ) { + function clbk( error ) { if ( error ) { t.fail( 'callback received an error: ' + error.message ); } else { @@ -134,8 +136,8 @@ tape( 'the `initializeAsync` method invokes a callback', opts, function test( t }); tape( 'the `initializeAsync` method properly sets `_module` and `_instance` properties', opts, function test( t ) { - var mod; var wasm; + var mod; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); mod = new Module( wasm, null ); @@ -158,8 +160,8 @@ tape( 'the `initializeAsync` method properly sets `_module` and `_instance` prop }); tape( 'the `exports` property returns instance exports after initialization', opts, function test( t ) { - var mod; var wasm; + var mod; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); mod = new Module( wasm, null ); From 60c616a7ee455d5d2a7c49d3c8dcaff1956c1d1f Mon Sep 17 00:00:00 2001 From: shiavm006 Date: Wed, 14 Jan 2026 23:26:06 +0530 Subject: [PATCH 3/5] test: remove private property checks from wasm module-wrapper tests --- .../@stdlib/wasm/module-wrapper/test/test.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js b/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js index 24d68cbd26f4..c530d2b148ba 100644 --- a/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js +++ b/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js @@ -16,8 +16,6 @@ * limitations under the License. */ -/* eslint-disable no-underscore-dangle */ - 'use strict'; // MODULES // @@ -92,7 +90,7 @@ tape( 'the `initialize` method returns a promise', opts, function test( t ) { t.end(); }); -tape( 'the `initialize` method properly sets `_module` and `_instance` properties', opts, function test( t ) { +tape( 'the `initialize` method resolves with the module instance', opts, function test( t ) { var wasm; var mod; @@ -103,10 +101,7 @@ tape( 'the `initialize` method properly sets `_module` and `_instance` propertie function onResolve( result ) { t.strictEqual( result, mod, 'resolves with module instance' ); - t.strictEqual( typeof result._module, 'object', '_module is set' ); - t.strictEqual( typeof result._instance, 'object', '_instance is set' ); - t.strictEqual( result._module.constructor.name, 'Module', '_module is a WebAssembly.Module' ); - t.strictEqual( result._instance.constructor.name, 'Instance', '_instance is a WebAssembly.Instance' ); + t.strictEqual( typeof result.exports, 'object', 'exports is accessible after initialization' ); t.end(); } @@ -135,7 +130,7 @@ tape( 'the `initializeAsync` method invokes a callback', opts, function test( t } }); -tape( 'the `initializeAsync` method properly sets `_module` and `_instance` properties', opts, function test( t ) { +tape( 'the `initializeAsync` method invokes callback with the module instance', opts, function test( t ) { var wasm; var mod; @@ -151,10 +146,7 @@ tape( 'the `initializeAsync` method properly sets `_module` and `_instance` prop return; } t.strictEqual( result, mod, 'callback receives module instance' ); - t.strictEqual( typeof result._module, 'object', '_module is set' ); - t.strictEqual( typeof result._instance, 'object', '_instance is set' ); - t.strictEqual( result._module.constructor.name, 'Module', '_module is a WebAssembly.Module' ); - t.strictEqual( result._instance.constructor.name, 'Instance', '_instance is a WebAssembly.Instance' ); + t.strictEqual( typeof result.exports, 'object', 'exports is accessible after initialization' ); t.end(); } }); From 1c78af9ae3a7bbb30b3b426b4b89a1ebe8c4c3c0 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 25 Jan 2026 15:42:57 -0800 Subject: [PATCH 4/5] test: refactor tests Signed-off-by: Athan --- .../@stdlib/wasm/module-wrapper/test/test.js | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js b/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js index c530d2b148ba..1010e0cae776 100644 --- a/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js +++ b/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js @@ -71,37 +71,37 @@ tape( 'the function is a constructor', opts, function test( t ) { var mod; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); - mod = new Module( wasm, null ); + mod = new Module( wasm, {} ); - t.strictEqual( mod instanceof Module, true, 'returns an instance' ); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); t.end(); }); -tape( 'the `initialize` method returns a promise', opts, function test( t ) { +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 ); + mod = new Module( wasm, {} ); p = mod.initialize(); - t.strictEqual( typeof p.then, 'function', 'returns a promise' ); + t.strictEqual( typeof p.then, 'function', 'returns expected value' ); t.end(); }); -tape( 'the `initialize` method resolves with the module instance', opts, function test( t ) { +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 = new Module( wasm, {} ); mod.initialize().then( onResolve, onReject ); function onResolve( result ) { - t.strictEqual( result, mod, 'resolves with module instance' ); - t.strictEqual( typeof result.exports, 'object', 'exports is accessible after initialization' ); + t.strictEqual( result, mod, 'resolves expected value' ); + t.strictEqual( typeof result.exports, 'object', 'returns expected value' ); t.end(); } @@ -111,12 +111,12 @@ tape( 'the `initialize` method resolves with the module instance', opts, functio } }); -tape( 'the `initializeAsync` method invokes a callback', opts, function test( t ) { +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 = new Module( wasm, {} ); mod.initializeAsync( clbk ); @@ -130,12 +130,12 @@ tape( 'the `initializeAsync` method invokes a callback', opts, function test( t } }); -tape( 'the `initializeAsync` method invokes callback with the module instance', opts, function test( t ) { +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 = new Module( wasm, {} ); mod.initializeAsync( clbk ); @@ -145,24 +145,24 @@ tape( 'the `initializeAsync` method invokes callback with the module instance', t.end(); return; } - t.strictEqual( result, mod, 'callback receives module instance' ); - t.strictEqual( typeof result.exports, 'object', 'exports is accessible after initialization' ); + t.strictEqual( result, mod, 'returns expected value' ); + t.strictEqual( typeof result.exports, 'object', 'returns expected value' ); t.end(); } }); -tape( 'the `exports` property returns instance exports after initialization', opts, function test( t ) { +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 = new Module( wasm, {} ); mod.initialize().then( onResolve, onReject ); function onResolve( result ) { var exports = result.exports; - t.strictEqual( typeof exports, 'object', 'exports is an object' ); + t.strictEqual( typeof exports, 'object', 'returns expected value' ); t.end(); } From 0619cef3bf80811f11fc7068e162df7efaa8dc6d Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 25 Jan 2026 15:50:02 -0800 Subject: [PATCH 5/5] test: fix invocations Signed-off-by: Athan --- .../@stdlib/wasm/module-wrapper/test/test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js b/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js index 1010e0cae776..bb149eef7a07 100644 --- a/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js +++ b/lib/node_modules/@stdlib/wasm/module-wrapper/test/test.js @@ -71,7 +71,7 @@ tape( 'the function is a constructor', opts, function test( t ) { var mod; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); - mod = new Module( wasm, {} ); + mod = new Module( wasm, null ); t.strictEqual( mod instanceof Module, true, 'returns expected value' ); t.end(); @@ -83,7 +83,7 @@ tape( 'the function returns an instance having an `initialize` method which retu var p; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); - mod = new Module( wasm, {} ); + mod = new Module( wasm, null ); p = mod.initialize(); t.strictEqual( typeof p.then, 'function', 'returns expected value' ); @@ -95,7 +95,7 @@ tape( 'the function returns an instance having an `initialize` method which retu var mod; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); - mod = new Module( wasm, {} ); + mod = new Module( wasm, null ); mod.initialize().then( onResolve, onReject ); @@ -116,7 +116,7 @@ tape( 'the function returns an instance having an `initializeAsync` method which var mod; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); - mod = new Module( wasm, {} ); + mod = new Module( wasm, null ); mod.initializeAsync( clbk ); @@ -135,7 +135,7 @@ tape( 'the function returns an instance having an `initializeAsync` method which var mod; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); - mod = new Module( wasm, {} ); + mod = new Module( wasm, null ); mod.initializeAsync( clbk ); @@ -156,7 +156,7 @@ tape( 'the function returns an instance having an `exports` property which is av var mod; wasm = new Uint8Array( [ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ] ); - mod = new Module( wasm, {} ); + mod = new Module( wasm, null ); mod.initialize().then( onResolve, onReject );