weedle icon indicating copy to clipboard operation
weedle copied to clipboard

Failure on servo's WebGLContextEvent.webidl

Open JMLX42 opened this issue 5 years ago • 2 comments

Describe the Bug

The parsing of WebGLContextEvent.webidl:

* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15
[Exposed=Window]
interface WebGLContextEvent : Event {
    [Throws] constructor(DOMString type, optional WebGLContextEventInit eventInit = {});
    readonly attribute DOMString statusMessage;
};

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15
dictionary WebGLContextEventInit : EventInit {
    DOMString statusMessage;
};

fails the following error:

[src/main.rs:29] parsed = Err(
    Failure(
        Code(
            CompleteStr(
                "/* This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at https://mozilla.org/MPL/2.0/. */\n\n// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15\n[Exposed=Window]\ninterface WebGLContextEvent : Event {\n    [Throws] constructor(DOMString type, optional WebGLContextEventInit eventInit = {});\n    readonly attribute DOMString statusMessage;\n};\n\n// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15\ndictionary WebGLContextEventInit : EventInit {\n    DOMString statusMessage;\n};\n",
            ),
            Custom(
                0,
            ),
        ),
    ),
)

Steps to Reproduce

let parsed = weedle::parse("
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15
[Exposed=Window]
interface WebGLContextEvent : Event {
    [Throws] constructor(DOMString type, optional WebGLContextEventInit eventInit = {});
    readonly attribute DOMString statusMessage;
};

// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15
dictionary WebGLContextEventInit : EventInit {
    DOMString statusMessage;
};
");

The problem appears to be the following content: optional WebGLContextEventInit eventInit = {}. Removing the default value declaration to have optional WebGLContextEventInit eventInit makes the parsing work OK.

Expected Behavior

The WebIDL is parsed properly and the corresponding AST is returned.

JMLX42 avatar Aug 11 '20 14:08 JMLX42

Replacing:

    [Throws] constructor(DOMString type, optional WebGLContextEventInit eventInit = {});

with:

    [Throws] constructor(DOMString type, optional WebGLContextEventInit eventInit = 0);

make the parsing works. My understanding is that maybe {} is not a handled as a default value for args.

It looks like this part of the parsing is done here:

https://github.com/rustwasm/weedle/blob/master/src/argument.rs#L19

But I don't understand yet why 0 works but {} does not work.

JMLX42 avatar Aug 11 '20 14:08 JMLX42

Default is defined in common.rs and relies on DefaultValue which is defined in literals.rs and does have a specific case for the empty dict initializer:

https://github.com/rustwasm/weedle/blob/master/src/literal.rs#L63

So it's still unclear why 0 works but not {}.

JMLX42 avatar Aug 11 '20 14:08 JMLX42