Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access and modify the document object model (DOM) with Webassembly (wasm)? [closed]

I know webassembly (wasm) is still in its infancy but I'd like to know if and how could I use it to change the DOM (in the same way I'm using Javascript to change the DOM).

Here is the official page:

Wasm MVP

like image 771
brakeroo Avatar asked Nov 02 '16 01:11

brakeroo


People also ask

Can WebAssembly modify DOM?

In order to manipulate the DOM you have to do this via the JavaScript host - your WebAssembly module has to send messages to JavaScript 'asking' it to manipulate the DOM on its behalf.

Can WebAssembly access the DOM?

By itself, WebAssembly cannot currently directly access the DOM; it can only call JavaScript, passing in integer and floating point primitive data types. Thus, to access any Web API, WebAssembly needs to call out to JavaScript, which then makes the Web API call.

Which commonly used file format for WebAssembly is a binary format which can be read and run by virtual machine or browsers )?

wat text format (a human-readable textual representation of WebAssembly) and in . wasm binary format (the raw bytecode, expressed below in hexadecimal), that is executed by a Web browser or run-time environment that supports WebAssembly.

How does a browser WebAssembly work?

“WebAssembly is a new type of code that can be run in modern web browsers — it is a low-level assembly-like language with a compact binary format that runs with near-native performance and provides languages such as C/C++, C# and Rust with a compilation target so that they can run on the web.


2 Answers

according to the docs, DOM access is not supported (as of November 2016) but is planned for the future.

Manipulating the DOM probably won't be supported, if things proceed according to the outline described on that page since references to the DOM are going to be opaque.

like image 101
Dan O Avatar answered Sep 23 '22 18:09

Dan O


A Wasm module can import and call JavaScript functions. A program that wants to manipulate the DOM hence has to come with the right glue layer written in JavaScript. It is more or less the same model as for asm.js code.

like image 32
Andreas Rossberg Avatar answered Sep 26 '22 18:09

Andreas Rossberg