design icon indicating copy to clipboard operation
design copied to clipboard

WebAssembly Browser Interface

Open redradist opened this issue 4 years ago • 11 comments

Consider making WebAssembly as cross-platform low-level language (new LLVM language) without bound it to Browser directly

The same way as in spec https://github.com/WebAssembly/WASI, we can introduce the new spec WABI - WebAssembly Browser Interface

My suggestion is not adding DOM API to WebAssembly, but to add DOM API in WABI - WebAssembly Browser Interface

In this way we will have a cross-platform low-level language that can be bound to any sub-system (Browser Interface, System Interface, GPU Interface) !!

Related links: #nonweb https://github.com/WebAssembly/design/blob/master/NonWeb.md

redradist avatar Apr 24 '20 12:04 redradist

There isn't anything tying WebAssembly to the browser, it's already fully cross platform.

WebAssembly is already used in a lot of non-browser cases: as sandboxing in Firefox, in the blockchain (e.g. ewasm), in Lambda AWS, in Cloudflare, etc.

Pauan avatar Apr 24 '20 20:04 Pauan

@Pauan

There isn't anything tying WebAssembly to the browser, it's already fully cross platform.

WebAssembly is already used in a lot of non-browser cases: as sandboxing in Firefox, in the blockchain (e.g. ewasm), in Lambda AWS, in Cloudflare, etc.

Why I either bother ? ... Because I see some usefull specification/propousals as DOM API, GPU API and for me it seems like this propousals go to WebAssembly specification

My concern are not that it is cross-platform now, but to leave it is a cross-patform low-level language by default by not tieing it to Browser directly, but instead all Browser specific API provide in separate specification

redradist avatar Apr 27 '20 15:04 redradist

@redradist All of the browser specific APIs are already in a separate specification. The browser specific APIs are specified by the W3C:

https://webassembly.github.io/spec/js-api/

The browser APIs are optional, which means that Wasm hosts do not need to implement them. Wasm will always remain cross-platform.

Pauan avatar Apr 28 '20 02:04 Pauan

All of the browser specific APIs are already in a separate specification. The browser specific APIs are specified by the W3C:

https://webassembly.github.io/spec/js-api/

@Pauan The request means an inverse API. API which can assess from inside of WASM to the DOM, GPU, etc. Currently you need to write custom JavaScripts code which will be imported. This code will be typical generated with the compiling of the WASM code. If you have multiple modules with a generated JavaScript then this must be loaded multiple times. If there is a standard API then every module can use this API which can reduce load and parse time.

Horcrux7 avatar Apr 28 '20 16:04 Horcrux7

@Horcrux7 I don't see how that's relevant to this issue. This issue is about making browser-specific APIs optional so that way Wasm remains portable.

And that's already true today: any browser-specific API will be in a separate spec which is optional. I gave an example of one browser-specific API, but there are others:

https://github.com/WebAssembly/JS-BigInt-integration

https://github.com/WebAssembly/esm-integration

https://github.com/WebAssembly/interface-types

Pauan avatar Apr 28 '20 17:04 Pauan

My understanding is that the suggestion is an API like WASI for a WASM runtime that run inside a browser or any other WASM runtime with a GUI. And of course is such API optional because not every WASM runtime has a GUI.

What you thing is JavaScript <-> Wasm but the suggestion is Display <-> Wasm without an intermediate JavaScript. A possible use case is app with a GUI without a browser. With the WASI interface you can write command line programs but not programs with a GUI.

Horcrux7 avatar Apr 28 '20 18:04 Horcrux7

@Horcrux7

My understanding is that the suggestion is an API like WASI for a WASM runtime that run inside a browser or any other WASM runtime with a GUI. And of course is such API optional because not every WASM runtime has a GUI.

What you thing is JavaScript <-> Wasm but the suggestion is Display <-> Wasm without an intermediate JavaScript. A possible use case is app with a GUI without a browser. With the WASI interface you can write command line programs but not programs with a GUI.

You are almost right !! There are considering DOM API directly from Wasm to Browser without JavaScript glue code and my suggestion is for any such sub-API create the separate specification ...

Consider the following examples API-s that is accessed from Wasm:

  1. Wasm <-> WebAssembly Browser API (directly to browser without JavaScript glue code) Should be a separate specification

  2. Wasm <-> WebAssembly GPU API Should be a separate specification

  3. Wasm <-> WebAssembly System API Have already a separate specification https://github.com/WebAssembly/WASI

  4. WebAssembly Garbage Collector Should be a separate specification Not all systems can support it for performance reason (example is embedded systems with low memory constraint)

  5. JavaScript <-> Wasm As well as API from High-level languages like JavaScript Have already a separate specification https://webassembly.github.io/spec/js-api/

The main point of all of this that WebAssembly as it is should be a core base for other building blocks, 'cause it is minimal language for executing some code !!

redradist avatar Apr 29 '20 08:04 redradist

@redradist There are considering DOM API directly from Wasm to Browser without JavaScript glue code and my suggestion is for any such sub-API create the separate specification ...

They already are a separate specification, and are optional. What you are asking for already exists.

As I have said multiple times, Wasm will remain low level. High level or browser-specific features will always be optional.

Pauan avatar Apr 29 '20 08:04 Pauan

If eliminating the JavaScript glue code that you currently need to write to web APIs is you goal then most of the interesting work in that area is currently happening in the interface types proposal: https://github.com/WebAssembly/interface-types/.

One of the goals of this proposal is one day to be able consume APIs (including Web APIs) more directly from a just a wasm module by specifying how the types in the wasm module correspond to types outside.

sbc100 avatar Apr 29 '20 15:04 sbc100

@sbc100

If eliminating the JavaScript glue code that you currently need to write to web APIs is you goal then most of the interesting work in that area is currently happening in the interface types proposal: https://github.com/WebAssembly/interface-types/.

One of the goals of this proposal is one day to be able consume APIs (including Web APIs) more directly from a just a wasm module by specifying how the types in the wasm module correspond to types outside.

Thanks, @sbc100 I know about interface-types ... But my suggestion was leave WebAssembly specification as Core Specification and all other specification should be based on it without extending original one

Like in Rust:

  1. libcore (WebAssembly "Core") - for any embedded solution,
  2. libstd (WebAssembly System Interface) - basic api ... all other libraries/specifications

redradist avatar May 07 '20 11:05 redradist

I think I see what you're getting at @redradist, but the browser already has a specified API, using WebIDL. WebAssembly doesn't need to create its own, it needs a way to integrate with WebIDL. The interface-types proposal is designed to do this, see the section here https://github.com/WebAssembly/interface-types/blob/master/proposals/interface-types/Explainer.md#web-idl-integration.

binji avatar May 13 '20 19:05 binji