WebAssembly / js-string-builtins

JS String Builtins
Other
8 stars 6 forks source link

Clarification requests #17

Closed jakobkummerow closed 9 months ago

jakobkummerow commented 9 months ago

While I don't expect any contentious debates here, I would suggest that the following details be called out explicitly in the specification, to avoid any uncertainty or surprises:

(1) When a module's import that has been satisfied at compile time is again provided at instantiation time, the copy provided at instantiation time is ignored. For example, for a module with: (import "wasm:js-string" "equals" ...) that's instantiated with:

let module = new WebAssembly.Module(..., {builtins: ["js-string"]});
let instance = new WebAssembly.Instance(module, {
  get "js-string"() {
    throw "unreachable";
  }
});
let instance2 = new WebAssembly.Instance(module, {
  "js-string": {
    get equals() { throw "unreachable"; }
  }
});

no exception is thrown.

(2) When a module attempts to import a function at compile time that isn't being provided by the engine it is running on, then this import simply and silently remains unsatisfied until regular instantiation time, for example: (import "wasm:js-string" "nonexistent" ...)

let module = new WebAssembly.Module(..., {builtins: ["js-string"]});
let import_has_been_retrieved = false;
let instance = new WebAssembly.Instance(module, {
  "js-string": {
    get nonexistent() { import_has_been_retrieved = true; return () => 42; },
  }
}
assert(import_has_been_retrieved);

(3) When builtins are exported and inspected from JavaScript, they must have names. Presumably these names match their name within the respective collection, for example:

  (import "wasm:js-string" "equals" $f1 ...)
  (export "foo" $f1)
let module = new WebAssembly.Module(..., {builtins: ["js-string"]});
let instance = new WebAssembly.Instance(module);
assert(instance.exports.foo.name === "equals");
eqrion commented 9 months ago

Yes, those all make sense to me. Good catch on the function name, I didn't know about that.