Instance lookup function for Wasm Namespaces#108
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
rossberg
left a comment
There was a problem hiding this comment.
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?
|
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 <rossberg@chromium.org>
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.InstanceAPI for obtaining theWebAssembly.Instanceruntime 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
Instanceobject 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
instancephase 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.