IDL: Add error handlings to avoid infinite loops
The IDL parser lacks some error propagation rules, which cause
infinite loops when an IDL file contains syntax errors. This
CL fixes following two cases:
(1) Missing arguments:
interface I {
void foo(DOMString arg, );
};
(2) Unexpected "attribute" in dictionary
dictionary D {
attribute DOMString member = "";
};
BUG=435794
Review URL: https://codereview.chromium.org/761223002
Cr-Commit-Position: refs/heads/master@{#306049}
diff --git a/tools/idl_parser/idl_parser.py b/tools/idl_parser/idl_parser.py
index 9b63f94c..16ecc6e 100755
--- a/tools/idl_parser/idl_parser.py
+++ b/tools/idl_parser/idl_parser.py
@@ -283,6 +283,12 @@
"""Dictionary : DICTIONARY error ';'"""
p[0] = self.BuildError(p, 'Dictionary')
+ # [11.2] Error recovery for regular Dictionary
+ # (for errors inside dictionary definition)
+ def p_DictionaryError2(self, p):
+ """Dictionary : DICTIONARY identifier Inheritance '{' error"""
+ p[0] = self.BuildError(p, 'Dictionary')
+
# [12]
def p_DictionaryMembers(self, p):
"""DictionaryMembers : ExtendedAttributeList DictionaryMember DictionaryMembers
@@ -590,6 +596,11 @@
if len(p) > 1:
p[0] = ListFromConcat(p[2], p[3])
+ # [54.1] Arguments error recovery
+ def p_ArgumentsError(self, p):
+ """Arguments : ',' error"""
+ p[0] = self.BuildError(p, 'Arguments')
+
# [55]
def p_Argument(self, p):
"""Argument : ExtendedAttributeList OptionalOrRequiredArgument"""
diff --git a/tools/idl_parser/test_parser/dictionary_web.idl b/tools/idl_parser/test_parser/dictionary_web.idl
index 5030686..ba5b1644c 100644
--- a/tools/idl_parser/test_parser/dictionary_web.idl
+++ b/tools/idl_parser/test_parser/dictionary_web.idl
@@ -92,4 +92,7 @@
DOMString? setString = null;
};
-
+/* ERROR Unexpected keyword "attribute" after "{". */
+dictionary MyDictUnexpectedAttribute {
+ attribute DOMString foo = "";
+};
diff --git a/tools/idl_parser/test_parser/interface_web.idl b/tools/idl_parser/test_parser/interface_web.idl
index 09a2902..2d19f89 100644
--- a/tools/idl_parser/test_parser/interface_web.idl
+++ b/tools/idl_parser/test_parser/interface_web.idl
@@ -50,6 +50,21 @@
partial interface MyIFaceInherit : Foo {};
/* TREE
+ *Interface(MyIFaceMissingArgument)
+ * Operation(foo)
+ * Arguments()
+ * Argument(arg)
+ * Type()
+ * PrimitiveType(DOMString)
+ * Error(Missing argument.)
+ * Type()
+ * PrimitiveType(void)
+ */
+interface MyIFaceMissingArgument {
+ void foo(DOMString arg, );
+};
+
+/* TREE
*Interface(MyIFaceBig)
* Const(setString)
* PrimitiveType(DOMString)