Skip to content

Conversation

guybedford
Copy link
Collaborator

@guybedford guybedford commented Mar 30, 2025

This is a PR against the PR in #104 to address the Wasm CG feedback from @rossberg that being able to obtain global handles is still a required use case for runtime reflection on instance phase ESM Integration Wasm modules.

This is an alternative to the original suggestion in #107, coming out of that discussion.

In this approach, we introduce a new WebAssembly.Instance.namespaceInstance(ns) -> WebAssembly.Instance API for obtaining the WebAssembly.Instance runtime instance reflection object for a WebAssembly module imported in the instance phase ESM Integration (import * as ns from './mod.wasm').

This is useful because where #104 would directly provide global values in Wasm exports, the Instance object would provide more features such as having global runtime type introspection per https://github.com/WebAssembly/js-types/blob/main/proposals/js-types/Overview.md, and possibly other features in future.

This is something like what was previously discussed as the instance phase import form in the import phase discussions, providing instance reflection APIs. So doesn't seem like a major departure from existing semantics. This wouldn't be supporting or advocating a new instance phase, but could also align with it if runtime instance controller reflections for JS became useful in future.

@guybedford

This comment was marked as outdated.

Copy link
Member

@rossberg rossberg left a comment

Choose a reason for hiding this comment

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

Personally I think it fits better in the WebAssembly namespace, since it isn't a method on instances, but rather a static function in the same category as instantiate.

Also, is "namespace" a notion that most JS programmers are familiar with? Sounds more like a spec technicality. Would importInstance make sense, given that these are always the result of imports?

@guybedford
Copy link
Collaborator Author

Yes, module namespace is a term used by JavaScript programmers (eg https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import#module_namespace_object).

While it is not an instance method, it is an instance static function as it is a static function associated with instances, so I think it makes sense to be on the instance as a specific function for working with instances.

Merging this into #104 as part of that overall change.

Co-authored-by: Andreas Rossberg <[email protected]>
@guybedford guybedford merged commit 447b95d into module-bindings Apr 8, 2025
3 checks passed
@guybedford guybedford deleted the instance-lookup branch April 8, 2025 16:34
@guybedford
Copy link
Collaborator Author

@rossberg FYI I went ahead and moved this back down to WebAssembly.namespaceInstance on the upstream PR in ef477aa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants