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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants