Skip to content

Conversation

@shiavm006
Copy link
Contributor

Description

What is the purpose of this pull request?
Fixes a critical bug in @stdlib/wasm/module-wrapper where the onResolve callback in both initialize() and initializeAsync() methods incorrectly expected two separate parameters (module, instance) when WebAssembly.instantiate() returns a Promise resolving to a single object {module, instance}. Updates the onResolve callback signature to accept a single result parameter and correctly extract result.module and result.instance properties.Adds comprehensive test coverage for both async initialization methods to verify the fix works correctly and prevent regressions.

Related Issues

Does this pull request have any related issues?

This pull request has no related issues.

Bug Impact

The bug caused this._instance to be undefined after async initialization, breaking all WebAssembly operations that depend on instance exports. Any code using initialize() or initializeAsync() would fail when trying to access this._instance.exports.*.

Technical Details

The WebAssembly.instantiate() API returns Promise<{module: WebAssembly.Module, instance: WebAssembly.Instance}>. The previous implementation incorrectly destructured this as two separate parameters in the Promise .then() callback, which only receives a single argument.

Testing

All new tests pass and verify:

  • _module and _instance are correctly set after initialization
  • Both properties are instances of WebAssembly.Module and WebAssembly.Instance respectively
  • The exports property is accessible after initialization

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

@stdlib-js/reviewers

@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 13, 2026
@shiavm006
Copy link
Contributor Author

CC @kgryte what do u feel about it ?
like any suggestions ?

@stdlib-bot
Copy link
Contributor

stdlib-bot commented Jan 13, 2026

Coverage Report

Package Statements Branches Functions Lines
wasm/module-wrapper $\color{red}409/514$
$\color{green}+0.00%$
$\color{red}11/18$
$\color{green}+0.00%$
$\color{red}7/20$
$\color{green}+0.00%$
$\color{red}409/514$
$\color{green}+0.00%$

The above coverage report was generated for the changes in this PR.

@shiavm006
Copy link
Contributor Author

modeled the new tests on existing WASM module tests

});

// TODO: add tests
tape( 'the `initialize` method properly sets `_module` and `_instance` properties', opts, function test( t ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we wouldn't be checking for private properties. Those are implementation details. I suggest removing all private property checks here and below.

}
});

tape( 'the `exports` property returns instance exports after initialization', opts, function test( t ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid approach to ensure that initialization works as expected.

Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let initial comments.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Changes Pull request which needs changes before being merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants