wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

The order of constructor arguments in dictionary bindings is not obvious

Open Sixshaman opened this issue 3 years ago • 0 comments

Suppose we have a WebIDL for a dictionary:

dictionary TestDictionary {
  required long foo;
  required long bar;
};

After generating the bindings with cargo run --release --package wasm-bindgen-webidl -- webidls src/features, we get the constructor with reversed order of arguments:

impl TestDictionary {
    pub fn new(bar: i32, foo: i32) -> Self {
        //...
    }
//...
}

This is unexpected and as far as I know, it's not documented. This happens because the dictionary members get sorted during the generation of the bindings. The issue was addressed in the original pull request.

The most common case of encountering the problem is generating and immediately using the bindings for experimental or browser-specific APIs.

Suggestions: fixing this now would be a breaking change, but this behavior is still not obvious to the user. At least the problem should be documented in the guide, along with other quirks of generating the bindings.

Sixshaman avatar Mar 27 '22 09:03 Sixshaman