浏览器中 WebAssembly MVP 的现状

State of affairs of WebAssembly MVP in browsers

https://webassembly.github.io/demo/ 说:"Full execution semantics implemented." 听起来 MVP 已经完成,但究竟缺少什么或者我做错了什么?

浪费:

(module
    (memory 1)

    (export "growMemory" $growMemory)
    (func $growMemory (param [=10=] i32) (result i32) (grow_memory (get_local [=10=])))

    (export "getMemorySize" $getMemorySize)
    (func $getMemorySize (result i32) (memory_size))
)

JS 代码:

var xhr = new XMLHttpRequest();
xhr.open('GET', 'build/test.wasm', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
    var module = Wasm.instantiateModule(new Uint8Array(xhr.response));
    console.log(module.exports.getMemorySize());
    console.log(module.exports.growMemory(1));
    console.log(module.exports.getMemorySize());
};
xhr.send(null);

Chrome Canary 加载 WASM 文件,但 grow_memory 似乎未实现:

65536
0
65536

Firefox Nightly 加载失败:

TypeError: wasm validation error at offset 124: bad expression code

此外,页面大小似乎是 0x10000 而不是 0x1000。但我在设计或规格中找不到它。

2017 年 3 月更新:

WebAssembly MVP 有 reached consensus:

WebAssembly CG members representing four browsers, Chrome, Edge, Firefox, and WebKit, have reached consensus that the design of the initial (MVP) WebAssembly API and binary format is complete to the extent that no further design work is possible without implementation experience and significant usage. This marks the end of the Browser Preview and signals that browsers can begin shipping WebAssembly on-by-default. From this point forward, future features will be designed to ensure backwards compatibility.

This consensus includes a JavaScript API and binary format accompanied by a reference interpreter. You can test out WebAssembly today using the Emscripten toolchain by following the developer’s guide and reading more on MDN.

The next steps will be to form a W3C Working Group, to produce a specification for the initial version of WebAssembly, and to continue iterating on future features in the current Community Group. To get involved, you can join design discussions and contribute to the the WebAssembly GitHub project.

当前 webassembly.org 站点记录了在 MVP 之后要遵循的以下后续步骤:

The WebAssembly community group and contributors plan to:

  • distill the design and spec interpreter repos into a single unified specification in the spec repo
  • propose a new charter for a W3C WebAssembly Working Group
  • graduate the WebAssembly LLVM backend from experimental to stable (and update Emscripten)
  • prototype additional WebAssembly integration into browser developer tools
  • Start work on post-MVP features

2016 年 11 月更新:

目前有浏览器预览,征求开发者反馈。来自 webassembly.org:

The WebAssembly Community Group has an initial (MVP) binary format release candidate and JavaScript API which are implemented in several browsers. The CG is now soliciting feedback from the broader community as part of a Browser Preview period. The tentative goal of the CG is for the Browser Preview to conclude in Q1 2017, though significant findings during the Browser Preview could potentially extend the duration. When the Browser Preview concludes, the CG will produce a draft specification of WebAssembly and browser vendors can start to ship conforming implementations on-by-default.

Developers should be aware that between the Browser Preview and public launch of WebAssembly, there will be at least one breaking change which will require developers to update their toolchain and binaries. These changes will be announced ahead of time and are listed below.

See Getting Started to start experimenting and Feedback for how and where to direct feedback.


原回答:

我们同步了演示浏览器之间的功能奇偶校验,并打算从现在开始同步更新所有浏览器和演示,以实现 MVP。

我们有一些目前可用的东西,但它不稳定。当我们使用更大、更多样化的代码库时,我们希望试一试,看看有什么可以改进的,并相信 post-MVP 功能将可以毫不费力地实现。我们还希望开发人员提供反馈,以确保我们构建的内容可用!

它缺少一些功能,例如 Wasm JavaScript 对象的 API,Wasm 实例之间的内存和指针共享。我们也没有确定二进制格式,目前最大的变化是 post-order,但还有很多较小的变化。

也缺乏浏览器集成:我们希望提供查看源代码和可能的一些调试支持。还有一些性能调整和大量安全测试。

要跟踪这些问题,我建议查看 design and spec 问题跟踪器。

关于您的具体问题,我们尚未在 Chrome 中完成 grow_memory。不过工作已经开始了。