WebAssembly / WebAssembly/spec

[js-api] Exposing Wasm-specific internal structure

Open
#1,958 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
3.5k
Forks
539
Avg merge
2d 1h
Merged PRs (30d)
13

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.

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the JS API specification algorithm for the WebAssembly function name and compare its direct store and function-instance access with the embedding section's functions. Determine whether the exposure is intentional; done means the specification records that decision and, if needed, defines the required embedding functions and updates the JS API algorithm.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, wasm
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.