Skip to content

Interacting with JavaScript

Volker Berlin edited this page Jan 18, 2020 · 3 revisions

An HTML page and JavaScript are required to run WebAssembly. It cannot be displayed like an image alone. This starts with loading the WebAssembly bytecode and continues with calling the first method, accessing the DOM and completing the lean functionality of WebAssembly. There are annotations to declare the bindings between Java and WebAssembly.

@Export

With the @Export annotation you can mark as callable from JavaScript. By default the method name is used as export name. But you can also define another name. The method must be a static method. There must be minimum one method with this annotation.

@Import

With the @Import annotation you give WebAssembly the possibility to call JavaScript code. But WebAssembly can only call JavaScript code that you have pass when instantiating. To simplify this JWebAssembly also create a JavaScript file that contains code for all imports. There are 2 times of imports. You can import a completely JavaScript object like the Math object. Or you define specific JavaScript code in the annotation like in currentTimeMillis.

Clone this wiki locally