Wasm DOM访问和引用类型 [英] Wasm DOM access and Reference types

查看:334
本文介绍了Wasm DOM访问和引用类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在密切关注Web组装路线图,特别是调用JS interop的性能影响.作为引用类型建议我们将能够对Wasm中的表进行基本操作.第四阶段已批准 6月23日的会议. Firefox和Chrome正在致力于实施该提案 WebAssembly路线图. 铬实施.根据此答案 Wasm访问dom .并引用铬说明

I have been following very closely the roadmap for webassembly, specially the performance hit of calling JS interop. As part of this reference types proposal we are going to be able to have basic manipulation of tables inside Wasm. Phase 4 has been approved June 23rd meeting. Firefox and Chrome are working on the implementation of this proposal WebAssembly roadmap. Chromium implementation. Based on this answer Wasm access dom. and quoting chromium description

允许WebAssembly模块保存对JS/DOM对象的引用,将其作为参数传递,将其存储在本地和全局变量中,并将其存储在WebAssembly.Table对象中.

Allow WebAssembly modules to hold references to JS/DOM objects, passing them as arguments, storing them in locals and globals, and storing them in WebAssembly.Table objects.

这是否允许从wasm访问DOM?还是需要进一步的实现?可以提高/匹配访问DOM的JS性能吗?这会允许在wasm中拥有虚拟DOM并仅对实际DOM进行必要的更改吗? @Andreas Rossberg ?

Is this going to allow accessing the DOM from wasm? or there are further implementations required? Will improve/match JS performance accessing the DOM? Will this allow to have a virtual DOM in wasm and make only necessary changes in the real DOM? @Andreas Rossberg?

添加来自Andreas Rossberg的回复解释GC和DOM-Access的结合

Adding this response from Andreas Rossberg Explain the conection of GC and DOM-Access

但是,我们从GC提案中分离出来的有关引用类型的新提案试图对此给出更细微的回答.它引入了引用类型,但没有在Wasm本身中分配任何内容的任何功能.在主机引用被垃圾收集的嵌入中,仍然需要Wasm实现来理解GC.但是在其他嵌入中则不需要.

However, the new proposal for reference types that we split off from the GC proposal tries to give a more nuanced answer to that. It introduces reference types without any functionality for allocating anything within Wasm itself. In an embedding where host references are garbage-collected that still requires a Wasm implementation to understand GC. But in other embeddings it does not need to.

为完整性起见进行编辑 webassembly-interface-types

Edit for completeness webassembly-interface-types

推荐答案

模块可以在Wasm中存储对DOM对象(或相应主机环境提供的任何内容)的引用,但是要访问它们,它需要导入相应的功能.那不会改变. Wasm是一个虚拟指令集,而不是API.而且它不是特定于Web的.

A module can store references to DOM objects (or whatever the respective host environment provides) in Wasm, but to access them, it needs to import respective functionality. That will not change. Wasm is a virtual instruction set, not an API. And it is not Web-specific.

但是,当然,您现在可以在Wasm中实现丰富的库,例如影子DOM或虚拟DOM,它可以在Wasm中完成大部分工作,并且仅在需要时调出真正的DOM.

But of course, you could now implement a rich library in Wasm, such as a shadow DOM or virtual DOM, that does most of the work in Wasm and only calls out to the real DOM where needed.

这篇关于Wasm DOM访问和引用类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆