在WebAssembly中,我们有一个32位带符号的整数,如果我们加载这个i32,那么我们可以检查i32的类型?如果不能用javascirpt/i32检查类型,有没有其他方法来检查wasm的值?
所以我尝试构建wasm,typeof返回一个"number“
main.js
WebAssembly.instantiateStreaming(fetch("../out/main.wasm"), {
main: {
sayHello() {
console.log("Hello from WebAssembly!");
}
},
env: {
abort(_msg, _file, line, column) {
console.error("abort called at main.ts:" + line + ":" + column);
}
},
}).then(result => {
const exports = result.instance.exports;
const addResult = exports.add(19, 23);
document.getElementById("container").textContent = "Result: " + exports.add(19, 23) + "Type:" + (typeof addResult);
}).catch(console.error);那么,有没有其他方法来检查wasm的值呢?
发布于 2019-10-04 20:25:11
您可以使用typeof运算符
typeof运算符返回其操作数的数据类型,操作数可以是任何对象、函数或变量。
例如:
输入:typeof "raman"输出字符串
https://stackoverflow.com/questions/58223739
复制相似问题