From dbce4340c76ef1d4191b7bfb09dcad75630dcd1c Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Tue, 4 Jul 2017 09:51:26 +0900 Subject: [PATCH] feat: support TypeWithExtendedAttributes on generics (#75) * closes #71 --- lib/webidl2.js | 5 +- .../idl/promise-with-extended-attribute.widl | 3 + .../record-key-with-extended-attribute.widl | 3 + .../json/promise-with-extended-attribute.json | 4 ++ .../record-key-with-extended-attribute.json | 4 ++ test/syntax/idl/iterable.widl | 4 ++ test/syntax/idl/maplike.widl | 6 ++ test/syntax/idl/record.widl | 4 ++ test/syntax/idl/sequence.widl | 8 ++- test/syntax/idl/setlike.widl | 4 ++ test/syntax/json/iterable.json | 26 +++++++++ test/syntax/json/maplike.json | 42 ++++++++++++++ test/syntax/json/record.json | 50 ++++++++++++++++ test/syntax/json/sequence.json | 58 ++++++++++++++++++- test/syntax/json/setlike.json | 27 +++++++++ 15 files changed, 245 insertions(+), 3 deletions(-) create mode 100644 test/invalid/idl/promise-with-extended-attribute.widl create mode 100644 test/invalid/idl/record-key-with-extended-attribute.widl create mode 100644 test/invalid/json/promise-with-extended-attribute.json create mode 100644 test/invalid/json/record-key-with-extended-attribute.json diff --git a/lib/webidl2.js b/lib/webidl2.js index f41e0c55..9805ae10 100644 --- a/lib/webidl2.js +++ b/lib/webidl2.js @@ -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, ",")); @@ -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(); diff --git a/test/invalid/idl/promise-with-extended-attribute.widl b/test/invalid/idl/promise-with-extended-attribute.widl new file mode 100644 index 00000000..0ce171fe --- /dev/null +++ b/test/invalid/idl/promise-with-extended-attribute.widl @@ -0,0 +1,3 @@ +interface Foo { + Promise<[XAttr] DOMString> foo(any param); +}; diff --git a/test/invalid/idl/record-key-with-extended-attribute.widl b/test/invalid/idl/record-key-with-extended-attribute.widl new file mode 100644 index 00000000..c11eb741 --- /dev/null +++ b/test/invalid/idl/record-key-with-extended-attribute.widl @@ -0,0 +1,3 @@ +interface Foo { + void foo(record<[XAttr] DOMString, any> param); +}; diff --git a/test/invalid/json/promise-with-extended-attribute.json b/test/invalid/json/promise-with-extended-attribute.json new file mode 100644 index 00000000..e9623ce7 --- /dev/null +++ b/test/invalid/json/promise-with-extended-attribute.json @@ -0,0 +1,4 @@ +{ + "message": "Promise type cannot have extended attribute", + "line": 2 +} diff --git a/test/invalid/json/record-key-with-extended-attribute.json b/test/invalid/json/record-key-with-extended-attribute.json new file mode 100644 index 00000000..3945825c --- /dev/null +++ b/test/invalid/json/record-key-with-extended-attribute.json @@ -0,0 +1,4 @@ +{ + "message": "Record key cannot have extended attribute", + "line": 2 +} diff --git a/test/syntax/idl/iterable.widl b/test/syntax/idl/iterable.widl index c7dfafa4..da8eb711 100644 --- a/test/syntax/idl/iterable.widl +++ b/test/syntax/idl/iterable.widl @@ -4,4 +4,8 @@ interface IterableOne { interface IterableTwo { iterable; +}; + +interface IterableThree { + iterable<[XAttr] long>; }; \ No newline at end of file diff --git a/test/syntax/idl/maplike.widl b/test/syntax/idl/maplike.widl index 7b79b388..ab710ee0 100644 --- a/test/syntax/idl/maplike.widl +++ b/test/syntax/idl/maplike.widl @@ -5,3 +5,9 @@ interface MapLike { interface ReadOnlyMapLike { readonly maplike; }; + +// Extracted from https://heycam.github.io/webidl/#idl-type-extended-attribute-associated-with on 2017-07-01 + +interface I { + maplike<[XAttr2] DOMString, [XAttr3] long>; +}; diff --git a/test/syntax/idl/record.widl b/test/syntax/idl/record.widl index 6cdedb21..c8d93431 100644 --- a/test/syntax/idl/record.widl +++ b/test/syntax/idl/record.widl @@ -6,3 +6,7 @@ interface Foo { // Make sure record can still be registered as a type. record baz(); }; + +interface Bar { + record bar(); +}; diff --git a/test/syntax/idl/sequence.widl b/test/syntax/idl/sequence.widl index 6ba0d390..d31056cf 100644 --- a/test/syntax/idl/sequence.widl +++ b/test/syntax/idl/sequence.widl @@ -9,4 +9,10 @@ interface Canvas { // Make sure sequence can still be registered as a type. interface Foo { sequence bar(); -}; \ No newline at end of file +}; + +// 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); +}; diff --git a/test/syntax/idl/setlike.widl b/test/syntax/idl/setlike.widl index 890e8e5a..f03bb581 100644 --- a/test/syntax/idl/setlike.widl +++ b/test/syntax/idl/setlike.widl @@ -5,3 +5,7 @@ interface SetLike { interface ReadOnlySetLike { readonly setlike; }; + +interface SetLikeExt { + setlike<[XAttr] long>; +}; \ No newline at end of file diff --git a/test/syntax/json/iterable.json b/test/syntax/json/iterable.json index 2614b89d..ecec327b 100644 --- a/test/syntax/json/iterable.json +++ b/test/syntax/json/iterable.json @@ -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": [] } ] diff --git a/test/syntax/json/maplike.json b/test/syntax/json/maplike.json index 85451cba..106f1705 100644 --- a/test/syntax/json/maplike.json +++ b/test/syntax/json/maplike.json @@ -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": [] } ] diff --git a/test/syntax/json/record.json b/test/syntax/json/record.json index 3a714441..5240185b 100644 --- a/test/syntax/json/record.json +++ b/test/syntax/json/record.json @@ -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": [] } ] diff --git a/test/syntax/json/sequence.json b/test/syntax/json/sequence.json index 619a08a7..8815a33a 100644 --- a/test/syntax/json/sequence.json +++ b/test/syntax/json/sequence.json @@ -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": [] + } ] \ No newline at end of file diff --git a/test/syntax/json/setlike.json b/test/syntax/json/setlike.json index e17175d1..62e2d397 100644 --- a/test/syntax/json/setlike.json +++ b/test/syntax/json/setlike.json @@ -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": [] } ]