Skip to content

[js-api] Exposing Wasm-specific internal structure #1958

@ShinWonho

Description

@ShinWonho

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.

Image

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).

Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions