Home

Awesome

Code binding generator for Web Assembly from WebIDL

This is a code generator that is taking WebIDL file and create binding code. It can currently generate DOM/HTML bindings for Go Web Assembly.

Target Languages

Current no other languages is planned. Contributions are welcome :)

Input files

The hardest part is not to write a WebIDL from a specification, but keeping it up to date. The philosophy is extract webidl from a third source, e.g. by taking all IDL part from the DOM specification (https://dom.spec.whatwg.org) and having all the modifications in other files.

The program need following input files:

Status/TODO

Currently the generator can process the DOM and HTML specification and create a compilable output. There are still missing feature, see Go WASM for details.

WebIDL

WebIDL specification can be found at https://heycam.github.io/webidl/

Global scope

The specification files doesn't containts browsers global varibale scope, e.g. access to window. This can be defined with a special annotation OnGlobalScope on a interface be able to define this methods and attributes. Please note that all attributes and methods need to be defined static to get correctly compilable code.

[OnGlobalScope]
interface GlobalScope {
    // access to javascript document variable.
    static readonly attribute Document document;
    // access to javascript window variable.
    static readonly attribute Window window;
};

Note: in the above example, to generator will create a function named Document() to get the document attribute. This will name clash with the interface Document. This is fixed by the language transformation file that is renaming the attribute in the final lanaguage.

Language transformation file

The transformation file are used to fix issues to get a final output that feels more "natrual" than working with raw generated files. Examples:

Current format using MarkDown ending to get some IDE syntax highlightning. With the exception for header tags (##), no other MarkDown synta is supported.


# Initail header have no meaning

    Any line starting with tab or spaces is consider to be a comment line

## Foo ("WebIDL type name")

    any line starting with a dot is modificing properties on type it self, e.g. rename the type to Bar

.name = Bar

    any other lines with equal sign is renaming method or attributes to target lanaguage name.
methodName = languageName

    Developers need to invoke SayHelloWorld() in target language to trigger helloWorld() in javascript.
helloWorld = SayHelloWorld

Callback

Syntax NameDescriptionDefault
.packagepackage namefirst part of the input file
.nametype output nameidl type name in public access format

Dictionary

Syntax NameDescriptionDefault
.packagepackage namefirst part of the input file
.nametype output nameidl type name in public access format

Enum

Syntax NameDescriptionDefault
.packagepackage namefirst part of the input file
.nametype output nameidl type name in public access format
.prefixprefix that is added to every enum valuenothing
.suffixsuffix that is added to every enum valueenum name

Interface

Interfaces have following properites

Syntax NameDescriptionDefault
.packagepackage namefirst part of the input file
.nametype output nameidl type name in public access format
.constPrefixa prefix added to all type constantsempty
.constSuffixa suffix added to all type constantsinterface name
.constructorNamename of constructor"New" + instance name
.index-gettername for 'getter' method with integer indexIndex
.index-settername for 'setter' method with integer indexSetIndex
.key-gettername for 'getter' method with string keyGet
.key-settername for 'setter' method with string keySet
.key-deletername for 'deleter' method with string keyDelete