0

In WebAssembly,we have i32 A 32-bit signed integer,if we load this wasm ,so we can check the type of i32?If cannot check i32 by javascirpt/typescirpt ,is there another way to check the value of wasm ?

So I try to build the wasm,the typeof return a "number"

enter image description here

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);

So,is there another way to check the value of wasm ?

Aya Choo
  • 11
  • 2

1 Answers1

0

You can use typeof Operator

The typeof operator returns the data type of its operand, Operand can be any object, function or variable.

For example:

Input: typeof "raman" outputs string

Tasos K.
  • 7,979
  • 7
  • 39
  • 63
  • Thank you.I post this qustion to the https://github.com/AssemblyScript/assemblyscript/issues/888 export function getTypeOf():string { let x:i32 = 12; return typeof x; } this code does not return "i32" but "number" in assemblyscript. – Aya Choo Oct 06 '19 at 16:20