The output should be considers as helping libraries to syscall/js than a standalone library. For some types, e.g. any is converted into js.Value.
- Dividing into multplie packages is missing. Currently everything is created into a single package.
- Method/Enum rename - transformation support to get a better API.
- Union support are missing as methods depending of this is unusable.
- js.Wrapper is moving away from syscall/js package for performance reasons. I couldn't find a way to preserve compatibility, so this will be a breaking change -- the fix for clients of the library should be easy though.
- Added a
go.mod
.
- Change from js.Value to js.Wrapper?
- Callback changed to Func + return value
The following will be applied to different WebIDL types:
Any type is currently handled converted into a js.Value.
A function is generated with conversion method.
TODO: Move conversion Go->WASM from implementation to public method.
callback Foo = void (int a, int b);
// FooFromJS is converted a returned js.Value into a function that can be invoked.
func FooFromJS(_value js.Value) FunctionStringCallback {
An interface that the developer should implement to get callback from javscript. There is a NewFoo()
that is used to allocate a javascript
object that can be used to get callbacks. The function is retuning an instance of
type FooValue
that holds the reference to underlaying javascript object.
On that instance there is also a Release()
method that need to be invoked when
the callback is no longer needed.
If the interface is only having a single method, there will also a NewFooFunc
method that is taking a function as input and will allocate corresponding javascript object. There is a generator option that let NewFooFunc
a javascript function instead of an object.
callback interface Foo {
void bar();
};
Will generate a structure with corresponding field. When convered to/from js.Value, values are copied into a new javascript object.
TODO: required values
A WebIDL enum is transformed into a Go enum.
Input
enum Foo {
"hello",
"world"
};
Will be turned into following:
type Foo int
const (
Hello Foo = iota
World
)
The most used type in WebIDL. Generate a struct.
Annotation | Desciption |
---|---|
NoGlobalScope | Generate an interface without a struct |
Any constants are converted into a Go const value.
For every attribute, a get and set method is generated. For read only attributes only a getter is created.
interface Foo {
attribute int bar;
};
A Go method or function is created for every method, depending if it's static or not. The method is trying to take care most of the conversion code.
interface Foo {
int bar(int a, int b);
};
For types that can be used as a js.TypeArray, a js.Value is used as method input type. Other sequence types are converted part of method invoke.
WebIDL keyword or can be used to define multiple input or output values that can be returned. It's like a very limitied any type.
TODO: unions are currently completey unusable. Any method or attribute that is depending on this union get a reference to an empty interface.
Example:
typedef (DOMString or Function) TimerHandler;