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

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
@shiavm006
Copy link
Contributor Author

shiavm006 commented Jan 14, 2026

made the changes @kgryte

@shiavm006
Copy link
Contributor Author

@kgryte any suggestions or update

@shiavm006 shiavm006 requested a review from kgryte January 18, 2026 09:34
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 18, 2026
Signed-off-by: Athan <kgryte@gmail.com>
kgryte
kgryte previously approved these changes Jan 25, 2026
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.

LGTM

@kgryte kgryte added difficulty: 2 May require some initial design or R&D, but should be straightforward to resolve and/or implement. review: 3 and removed Needs Review A pull request which needs code review. Needs Changes Pull request which needs changes before being merged. labels Jan 25, 2026
@kgryte kgryte changed the title fix: correct WebAssembly.instantiate callback signature in module-wrapper fix: use correct WebAssembly.instantiate callback signature in wasm/module-wrapper Jan 25, 2026
Signed-off-by: Athan <kgryte@gmail.com>
@kgryte kgryte merged commit a1443d1 into stdlib-js:develop Jan 25, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

difficulty: 2 May require some initial design or R&D, but should be straightforward to resolve and/or implement. review: 3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants