Difference between revisions of "WebAssembly/JS-Promise Integration"

From Lazarus wiki
Jump to navigationJump to search
(basic info about the language extension (suspending externals + promising exports))
(Added section "browser support" with more info on how to enable this feature)
Line 1: Line 1:
 
The WebAssembly JavaScript-Promise Integration Proposal is a proposed extension to the browser JavaScript API: [https://github.com/WebAssembly/js-promise-integration/blob/main/proposals/js-promise-integration/Overview.md]
 
The WebAssembly JavaScript-Promise Integration Proposal is a proposed extension to the browser JavaScript API: [https://github.com/WebAssembly/js-promise-integration/blob/main/proposals/js-promise-integration/Overview.md]
There is currently experimental support implemented in Chrome, Chromium and Edge. TODO: which versions, how to enable?
+
 
 +
=Browser support=
 +
 
 +
There is currently experimental support implemented in Chrome, Chromium and Edge. So far, browser support is only implemented on the x86_64 and aarch64 platforms. Minimum Chrome versions that support it are 110.0.5473.0 (macOS) / 110.0.5469.0 (Windows, Android) / 110.0.5478.4 (Linux). As an experimental feature, it is disabled by default. To enable it, go to the URL:
 +
chrome://flags
 +
Search for "Experimental WebAssembly JavaScript Promise Integration (JSPI)". Click on the box, select "enable", then restart the browser to enable the feature.
  
 
=Free Pascal support=
 
=Free Pascal support=

Revision as of 14:57, 20 June 2023

The WebAssembly JavaScript-Promise Integration Proposal is a proposed extension to the browser JavaScript API: [1]

Browser support

There is currently experimental support implemented in Chrome, Chromium and Edge. So far, browser support is only implemented on the x86_64 and aarch64 platforms. Minimum Chrome versions that support it are 110.0.5473.0 (macOS) / 110.0.5469.0 (Windows, Android) / 110.0.5478.4 (Linux). As an experimental feature, it is disabled by default. To enable it, go to the URL:

chrome://flags

Search for "Experimental WebAssembly JavaScript Promise Integration (JSPI)". Click on the box, select "enable", then restart the browser to enable the feature.

Free Pascal support

Work on adding Free Pascal support for this extension is being done in the wasm_js_promise_integration branch: [2]

Free Pascal language extensions

Suspending externals

Suspending externals allows calling JavaScript functions that are run asynchronously on the JavaScript side, even though they are called as if they are synchronous on the WebAssembly side. Example:

function compute_delta: double; external 'js' suspending;

TODO: add info how to implement compute_delta on the JavaScript side.

Promising exports

In order for calls to suspending functions to work, WebAssembly code execution must be entered via an export, marked as 'promising'. Example:

var
  state: double;

function update_state: double;
begin
  state := state + compute_delta;  // this calls the suspending function 'compute_delta'
  update_state := state;
end;

exports
  update_state promising;

TODO: add info how to invoke a promising function from the JavaScript side.

See Also