WebAssembly 2.0新特性

官网: Change History

  1. Multiple values

    • Function types allow more than one result.
      适配go语言等函数多返回值的特性。
    • Block types can be arbitrary function types.
      控制块带参数,适配C语言等内联函数的展开。Wasm1.0里调用内联函数使用的是call指令。
  2. Reference types

    • Added funcref and externref as new value types and respective.
      表元素增加新类型。

      externref allows modules to hold references to objects provided by the host environment; in other words, you can pass a JavaScript object to your .wasm module. The .wasm module can’t really do much with the object via the type. What’s more important is that the module is holding a reference to a garbage collected object on the JavaScript heap. 持有外部引用,为将来wasm引入GC准备。 参看Upcoming Features and Proposals

  3. Bulk memory

    • New memory instructions: memory.fill, memory.init, memory.copy, data.drop.
      对应C里的memcpy, memmove等,目的提高处理大块内存的性能。Wasm1.0里使用load, store指令操作内存,只能处理基本类型的数值。
  4. Multiple table
    coming soon