Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/webidl2.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
var types = [];
do {
all_ws();
types.push(type() || error("Error parsing generic type " + value));
types.push(type_with_extended_attributes() || error("Error parsing generic type " + value));
all_ws();
}
while (consume(OTHER, ","));
Expand All @@ -206,6 +206,9 @@
if (!/^(DOMString|USVString|ByteString)$/.test(types[0].idlType)) {
error("Record key must be DOMString, USVString, or ByteString");
}
if (types[0].extAttrs) error("Record key cannot have extended attribute");
} else if (value === "Promise") {
if (types[0].extAttrs) error("Promise type cannot have extended attribute");
}
ret.idlType = types.length === 1 ? types[0] : types;
all_ws();
Expand Down
3 changes: 3 additions & 0 deletions test/invalid/idl/promise-with-extended-attribute.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Foo {
Promise<[XAttr] DOMString> foo(any param);
};
3 changes: 3 additions & 0 deletions test/invalid/idl/record-key-with-extended-attribute.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Foo {
void foo(record<[XAttr] DOMString, any> param);
};
4 changes: 4 additions & 0 deletions test/invalid/json/promise-with-extended-attribute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"message": "Promise type cannot have extended attribute",
"line": 2
}
4 changes: 4 additions & 0 deletions test/invalid/json/record-key-with-extended-attribute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"message": "Record key cannot have extended attribute",
"line": 2
}
4 changes: 4 additions & 0 deletions test/syntax/idl/iterable.widl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ interface IterableOne {

interface IterableTwo {
iterable<short, double?>;
};

interface IterableThree {
iterable<[XAttr] long>;
};
6 changes: 6 additions & 0 deletions test/syntax/idl/maplike.widl
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ interface MapLike {
interface ReadOnlyMapLike {
readonly maplike<long, float>;
};

// Extracted from https://heycam.github.io/webidl/#idl-type-extended-attribute-associated-with on 2017-07-01

interface I {
maplike<[XAttr2] DOMString, [XAttr3] long>;
};
4 changes: 4 additions & 0 deletions test/syntax/idl/record.widl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ interface Foo {
// Make sure record can still be registered as a type.
record baz();
};

interface Bar {
record<DOMString, [XAttr] float> bar();
};
8 changes: 7 additions & 1 deletion test/syntax/idl/sequence.widl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ interface Canvas {
// Make sure sequence can still be registered as a type.
interface Foo {
sequence bar();
};
};

// Extracted from https://heycam.github.io/webidl/#idl-type-extended-attribute-associated-with on 2017-07-01

interface I {
void f1(sequence<[XAttr] long> arg);
};
4 changes: 4 additions & 0 deletions test/syntax/idl/setlike.widl
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ interface SetLike {
interface ReadOnlySetLike {
readonly setlike<long>;
};

interface SetLikeExt {
setlike<[XAttr] long>;
};
26 changes: 26 additions & 0 deletions test/syntax/json/iterable.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@
],
"inheritance": null,
"extAttrs": []
},
{
"type": "interface",
"name": "IterableThree",
"partial": false,
"members": [
{
"type": "iterable",
"idlType": {
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "long",
"extAttrs": [
{
"name": "XAttr",
"arguments": null
}
]
},
"extAttrs": []
}
],
"inheritance": null,
"extAttrs": []
}
]

42 changes: 42 additions & 0 deletions test/syntax/json/maplike.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,48 @@
],
"inheritance": null,
"extAttrs": []
},
{
"type": "interface",
"name": "I",
"partial": false,
"members": [
{
"type": "maplike",
"idlType": [
{
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "DOMString",
"extAttrs": [
{
"name": "XAttr2",
"arguments": null
}
]
},
{
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "long",
"extAttrs": [
{
"name": "XAttr3",
"arguments": null
}
]
}
],
"readonly": false,
"extAttrs": []
}
],
"inheritance": null,
"extAttrs": []
}
]

50 changes: 50 additions & 0 deletions test/syntax/json/record.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,55 @@
]
}
]
},
{
"type": "interface",
"name": "Bar",
"partial": false,
"members": [
{
"type": "operation",
"getter": false,
"setter": false,
"creator": false,
"deleter": false,
"legacycaller": false,
"static": false,
"stringifier": false,
"idlType": {
"sequence": false,
"generic": "record",
"nullable": false,
"union": false,
"idlType": [
{
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "DOMString"
},
{
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "float",
"extAttrs": [
{
"name": "XAttr",
"arguments": null
}
]
}
]
},
"name": "bar",
"arguments": [],
"extAttrs": []
}
],
"inheritance": null,
"extAttrs": []
}
]
58 changes: 57 additions & 1 deletion test/syntax/json/sequence.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,61 @@
],
"inheritance": null,
"extAttrs": []
}
},

{
"type": "interface",
"name": "I",
"partial": false,
"members": [
{
"type": "operation",
"getter": false,
"setter": false,
"creator": false,
"deleter": false,
"legacycaller": false,
"static": false,
"stringifier": false,
"idlType": {
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "void"
},
"name": "f1",
"arguments": [
{
"optional": false,
"variadic": false,
"extAttrs": [],
"idlType": {
"sequence": true,
"generic": "sequence",
"nullable": false,
"union": false,
"idlType": {
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "long",
"extAttrs": [
{
"name": "XAttr",
"arguments": null
}
]
}
},
"name": "arg"
}
],
"extAttrs": []
}
],
"inheritance": null,
"extAttrs": []
}
]
27 changes: 27 additions & 0 deletions test/syntax/json/setlike.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,33 @@
],
"inheritance": null,
"extAttrs": []
},
{
"type": "interface",
"name": "SetLikeExt",
"partial": false,
"members": [
{
"type": "setlike",
"idlType": {
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "long",
"extAttrs": [
{
"name": "XAttr",
"arguments": null
}
]
},
"readonly": false,
"extAttrs": []
}
],
"inheritance": null,
"extAttrs": []
}
]