Skip to content

Commit a74f64e

Browse files
committed
Add i64 to the set of JS-compatible wasm types in syncWebAssembly mode
For quite a while now, it's been possible for WebAssembly `i64`s to be converted to/from JS bigints (as function parameters, results, etc.). However, `syncWebAssembly` mode currently rejects any modules that attempt to do so, because `i64` isn't in it's list of JS-compatible types. This fixes that by adding `i64` to that list. There was an existing test that used `i64` as an example of a non-JS-compatible type; I replaced that with `v128`.
1 parent 9fcaa24 commit a74f64e

9 files changed

Lines changed: 38 additions & 4 deletions

File tree

lib/wasm-sync/WebAssemblyParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
1717
/** @typedef {import("../Parser").ParserState} ParserState */
1818
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
1919

20-
const JS_COMPAT_TYPES = new Set(["i32", "f32", "f64"]);
20+
const JS_COMPAT_TYPES = new Set(["i32", "i64", "f32", "f64"]);
2121

2222
/**
2323
* @param {t.Signature} signature the func signature
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
it("should allow to run a WebAssembly module with non-js-compatible imports", function() {
22
return import("./wasm.wasm").then(function(wasm) {
3-
const result = wasm.testI64();
3+
const result = wasm.testV128();
44
expect(result).toEqual(42);
55
});
66
});
-20 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");
1+
const wasmFeatures = require("webassembly-feature");
22

33
module.exports = function(config) {
4-
return supportsWebAssembly();
4+
return wasmFeatures["simd"];
55
};
-29 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
it("should allow converting i64s to JS bigints", async () => {
2+
const { getI64 } = await import("./wasm.wat");
3+
expect(getI64()).toEqual(42n);
4+
});
5+
6+
it("should allow converting JS bigints to i64s", async () => {
7+
const { takeI64 } = await import("./wasm.wat");
8+
takeI64(42n);
9+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const wasmFeatures = require("webassembly-feature");
2+
3+
module.exports = function(config) {
4+
return wasmFeatures["JS-BigInt-integration"];
5+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(module
2+
(func (export "getI64") (result i64)
3+
i64.const 42)
4+
(func (export "takeI64") (param i64)))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** @type {import("../../../../").Configuration} */
2+
module.exports = {
3+
entry: "./index",
4+
module: {
5+
rules: [
6+
{
7+
test: /\.wat$/,
8+
loader: "wast-loader",
9+
type: "webassembly/sync"
10+
}
11+
]
12+
},
13+
experiments: {
14+
syncWebAssembly: true
15+
}
16+
};

0 commit comments

Comments
 (0)