WebAssembly.instantiateStreaming 需要一个可选参数
WebAssembly.instantiateStreaming requires an optional argument
当我 运行 以下代码时出现 Uncaught (in promise) TypeError: second argument must be an object
错误:
async function loadWasm(url) {
const fetchPromise = fetch(url)
const { module, instance } = await WebAssembly.instantiateStreaming(fetchPromise)
// [...]
}
loadWasm('http://localhost:3000/path/to/file.wasm')
查看documentation,它说WebAssembly.instantiateStreaming
(importObject
)的第二个参数是可选的,所以我不明白为什么浏览器仍然强制要求它?
我已经在 Firefox 78.7.0esr(64 位)和 Chrome88.0.4324.96(正式版)(64 位)中测试过。如果它有任何重要性,代码将在 rails 6.1 应用程序的 ruby 中使用 webpack 5 进行转译。
更新:
我打开了 an issue on mdn's github repository thinking the documentation might need an update. So far it seems the documentation is good 所以这可能是一个实施问题。待确认。
更新:
这既不是实施问题也不是文档错误。我在下面的答案中发布了关于这个问题的结论。
https://github.com/WebAssembly/spec/issues/1284#issuecomment-772286062
It is required only if the module you're instantiating actually imports something.
它在文档中被标记为可选,因为它并不总是需要,而不是因为我们可以选择是否提供它。是 wasm 包决定它是可选的还是必需的。
当我 运行 以下代码时出现 Uncaught (in promise) TypeError: second argument must be an object
错误:
async function loadWasm(url) {
const fetchPromise = fetch(url)
const { module, instance } = await WebAssembly.instantiateStreaming(fetchPromise)
// [...]
}
loadWasm('http://localhost:3000/path/to/file.wasm')
查看documentation,它说WebAssembly.instantiateStreaming
(importObject
)的第二个参数是可选的,所以我不明白为什么浏览器仍然强制要求它?
我已经在 Firefox 78.7.0esr(64 位)和 Chrome88.0.4324.96(正式版)(64 位)中测试过。如果它有任何重要性,代码将在 rails 6.1 应用程序的 ruby 中使用 webpack 5 进行转译。
更新:
我打开了 an issue on mdn's github repository thinking the documentation might need an update. So far it seems the documentation is good 所以这可能是一个实施问题。待确认。
更新:
这既不是实施问题也不是文档错误。我在下面的答案中发布了关于这个问题的结论。
https://github.com/WebAssembly/spec/issues/1284#issuecomment-772286062
It is required only if the module you're instantiating actually imports something.
它在文档中被标记为可选,因为它并不总是需要,而不是因为我们可以选择是否提供它。是 wasm 包决定它是可选的还是必需的。