-
Notifications
You must be signed in to change notification settings - Fork 478
Description
Functions defined in embedding section provide abstraction of Wasm's mechanics to embedders. However, I found a case in JS API specification that breaks this abstraction: exposing Wasm-specific internal structure. I'm curious whether these are inevitable or intentional.
Some embedding functions abstract over the internal structure of the Wasm store. Fig.1 provides a representative example. It takes a store S
and an address a
, and returns S.funcs[a].type
. When the embedder tries to retrieve the function type, the unnecessary details about the Wasm store can be abstracted away using the embedding function.

Fig.1: Embedding function func_type
However, Fig.2 is the algorithm that breaks this abstraction layer. It accesses the store directly to get a function instance (line 2).
Not only that, this algorithm checks whether the function instance is a host function (line 3) and accesses its fields (line 3.1). This also undermines the abstraction, because, as I understand it, the internal structure of Wasm-specific structures are intended to be exposed only for error, values(val, externval), or types(externtype, memtype, globaltype, valtype).

Fig.2: JS API algorithm for the name of the WebAssembly function
The abstraction over the internal structure of the store and the function instance should be enforced by accessing them only through embedding functions; however, this abstraction is currently not maintained. These exposures might result from accessing Wasm's functionality beyond what the embedding functions provide. I'd like to ask whether this exposure is intentional, and whether it would be possible to add new embedding functions to eliminate it.