forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
i64
to the set of JS-compatible wasm types in syncWebAssembly
…
… mode (Note: this fix is mainly meant for being backported to webpack 4, since `syncWebAssembly` is deprecated anyway, but I've implemented it against webpack 5 first.) It's now supported in all major browsers, and is represented by `bigint` in JS. There was an existing test that used `i64` as an example of a non-JS-compatible type; I replaced that with `v128`. Ref rustwasm/wasm-bindgen#3095
- Loading branch information
1 parent
9fcaa24
commit 7528146
Showing
9 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
it("should allow to run a WebAssembly module with non-js-compatible imports", function() { | ||
return import("./wasm.wasm").then(function(wasm) { | ||
const result = wasm.testI64(); | ||
const result = wasm.testV128(); | ||
expect(result).toEqual(42); | ||
}); | ||
}); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly"); | ||
const fs = require("fs"); | ||
|
||
module.exports = function(config) { | ||
return supportsWebAssembly(); | ||
try { | ||
// Compile the wasm module to test that the runtime supports v128 in the first place. | ||
// Use synchronous instantation because this has to be synchronous. | ||
new WebAssembly.Module(fs.readFileSync(`${__dirname}/wasm.wasm`)); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getI64, takeI64 } from "./wasm.wat"; | ||
|
||
it("should allow converting i64s to JS bigints", function() { | ||
expect(getI64()).toEqual(42n); | ||
}); | ||
|
||
it("should allow converting JS bigints to i64s", function() { | ||
takeI64(42n); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const fs = require("fs"); | ||
|
||
module.exports = function(config) { | ||
try { | ||
// Compile the wasm module to test that the runtime supports i64 in the first place. | ||
// Use synchronous instantation because this has to be synchronous. | ||
const module = new WebAssembly.Module(fs.readFileSync(`${__dirname}/wasm.wasm`)); | ||
const instance = new WebAssembly.Instance(module); | ||
// Test that WebAssembly bigint integration is supported. | ||
// Note that what we're testing isn't that the *runtime* supports it, | ||
// it's that *webpack* supports it; the test relies on it already | ||
// being supported by the runtime, so we check that here by calling a | ||
// function that returns `i64`, outside of webpack. | ||
instance.exports.getI64(); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(module | ||
(func (export "getI64") (result i64) | ||
i64.const 42) | ||
(func (export "takeI64") (param i64))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** @type {import("../../../../").Configuration} */ | ||
module.exports = { | ||
entry: "./index", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.wat$/, | ||
loader: "wast-loader", | ||
type: "webassembly/sync" | ||
} | ||
] | ||
}, | ||
experiments: { | ||
syncWebAssembly: true | ||
} | ||
}; |