wasm-bindgen/crates/webidl-tests/dictionary.webidl
Alex Crichton d6e48195b3 Implement support for WebIDL dictionaries
This commit adds support for generating bindings for dictionaries defined in
WebIDL. Dictionaries are associative arrays which are simply objects in JS with
named keys and some values. In Rust given a dictionary like:

    dictionary Foo {
        long field;
    };

we'll generate a struct like:

    pub struct Foo {
        obj: js_sys::Object,
    }

    impl Foo {
        pub fn new() -> Foo { /* make a blank object */ }

        pub fn field(&mut self, val: i32) -> &mut Self {
            // set the field using `js_sys::Reflect`
        }
    }

    // plus a bunch of AsRef, From, and wasm abi impls

At the same time this adds support for partial dictionaries and dictionary
inheritance. All dictionary fields are optional by default and hence only have
builder-style setters, but dictionaries can also have required fields. Required
fields are exposed as arguments to the `new` constructor.

Closes #241
2018-08-15 17:08:27 -07:00

48 lines
598 B
Plaintext
Vendored

// example from https://heycam.github.io/webidl/#idl-dictionaries
dictionary B : A {
long b;
long a;
};
dictionary A {
long c;
long g;
};
dictionary C : B {
long e;
long f;
};
partial dictionary A {
long h;
long d;
};
// case needs changing
dictionary camel_case_me {
long snakeCaseMe;
};
dictionary ManyTypes {
DOMString a;
octet n1;
byte n2;
unsigned short n3;
short n4;
unsigned long n5;
long n6;
// TODO: needs fixing
// OtherDict c;
};
dictionary OtherDict {
long a;
};
dictionary Required {
required DOMString b;
required long a;
long c;
};