[Webkit-unassigned] [Bug 231114] New: [WebAssembly][modules] Importing globals into Wasm from JS doesn't work
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Fri Oct 1 17:22:51 PDT 2021
https://bugs.webkit.org/show_bug.cgi?id=231114
Bug ID: 231114
Summary: [WebAssembly][modules] Importing globals into Wasm
from JS doesn't work
Product: WebKit
Version: WebKit Nightly Build
Hardware: Unspecified
OS: Unspecified
Status: NEW
Severity: Normal
Priority: P2
Component: WebAssembly
Assignee: webkit-unassigned at lists.webkit.org
Reporter: asumu at igalia.com
Wasm/ES module integration should allow globals and other values to be imported in the JS->Wasm direction, such as in the example below. This is based on this example from the proposal explainer: https://github.com/WebAssembly/esm-integration/blob/main/proposals/esm-integration/EXAMPLES.md#value-imports
Entry script (global.js):
```
import * as assert from '../assert.js';
import {incrementCount} from "./global.wasm";
import {count} from "./global.mjs";
incrementCount();
assert.eq(count.valueOf(), 43);
```
global.mjs:
```
export const count = new WebAssembly.Global({
value: 'i32',
mutable: true,
}, 42);
```
global.wat:
```
;; global.wat --> global.wasm
(module
;; this import should work normally
(import "./global.mjs" "count" (global (mut i32)))
(func (export "incrementCount")
(global.set 0
(i32.add
(global.get 0)
(i32.const 1))))
)
```
Currently, this doesn't work in JSC and produces a `LinkError` like the following:
```
$ ~/WebKit/WebKitBuild/GTK/Release/bin/jsc -m global.js
Exception: LinkError: imported global ./global.mjs:count must be a WebAssembly.Global object since it is mutable
moduleDeclarationInstantiation@[native code]
link@[native code]
link@[native code]
linkAndEvaluateModule@[native code]
@[native code]
asyncFunctionResume@[native code]
@[native code]
promiseReactionJobWithoutPromise@[native code]
promiseReactionJob@[native code]
```
The issue appears to be that Wasm is fetching the value from JS too early, when it's still `undefined`. JSC's Wasm module records look at the imports in the `link` step of module execution, rather than in the `evaluate` step (as the Wasm/ESM proposal spec says: https://webassembly.github.io/esm-integration/js-api/index.html#module-execution).
I'm working on a draft patch that would move the work in the `link` step into the `evaluate` step. This appears to pass almost all of the current Wasm modules tests (except in one case where I think the test might be wrong). I'll share the patch after writing more tests to check various edge cases. Even with this change, more work is probably needed for `WebAssembly.Memory` to work (because of https://bugs.webkit.org/show_bug.cgi?id=184745).
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20211002/bf1fa343/attachment-0001.htm>
More information about the webkit-unassigned
mailing list