Title: [146452] trunk
Revision
146452
Author
[email protected]
Date
2013-03-21 04:41:39 -0700 (Thu, 21 Mar 2013)

Log Message

Web Inspector: Track CSS error location information.
https://bugs.webkit.org/show_bug.cgi?id=111314

Source/WebCore:

Added CSS syntax error reporting to some (other rules will be covered later) error recovery grammar rules.
Added code to CSSParser to allow track error location information.
Added empty rule to declaration_list. Needed to not report error about declarations like "body {}".
Added helper grammar rule "errors: error | errors error". Handles the same grammar as "error" but simplifies error location tracking.

Patch by Sergey Ryazanov <[email protected]> on 2013-03-21
Reviewed by Pavel Feldman.

Test: inspector/console/console-css-warnings.html

* css/CSSGrammar.y.in:
* css/CSSParser.cpp:
(WebCore::CSSParser::CSSParser):
(WebCore::CSSParser::currentLocation):
(WebCore):
(WebCore::CSSParser::realLex):
* css/CSSParser.h:
(CSSParser):

LayoutTests:

Patch by Sergey Ryazanov <[email protected]> on 2013-03-21
Reviewed by Pavel Feldman.

* inspector/console/console-css-warnings-expected.txt: Added.
* inspector/console/console-css-warnings.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (146451 => 146452)


--- trunk/LayoutTests/ChangeLog	2013-03-21 11:17:30 UTC (rev 146451)
+++ trunk/LayoutTests/ChangeLog	2013-03-21 11:41:39 UTC (rev 146452)
@@ -1,3 +1,13 @@
+2013-03-21  Sergey Ryazanov  <[email protected]>
+
+        Web Inspector: Track CSS error location information.
+        https://bugs.webkit.org/show_bug.cgi?id=111314
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/console/console-css-warnings-expected.txt: Added.
+        * inspector/console/console-css-warnings.html: Added.
+
 2013-03-21  Ádám Kallai  <[email protected]>
 
         [Qt] Unreviewed gardening.

Added: trunk/LayoutTests/inspector/console/console-css-warnings-expected.txt (0 => 146452)


--- trunk/LayoutTests/inspector/console/console-css-warnings-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/console/console-css-warnings-expected.txt	2013-03-21 11:41:39 UTC (rev 146452)
@@ -0,0 +1,5 @@
+Tests CSS warnings are properly exposed.
+
+Unexpected CSS token: # console-css-warnings.html:10
+Unexpected CSS token: * console-css-warnings.html:14
+

Added: trunk/LayoutTests/inspector/console/console-css-warnings.html (0 => 146452)


--- trunk/LayoutTests/inspector/console/console-css-warnings.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/console/console-css-warnings.html	2013-03-21 11:41:39 UTC (rev 146452)
@@ -0,0 +1,39 @@
+<html>
+<head>
+<script src=""
+<script src=""
+
+<style>
+x {}
+
+x {
+    #
+}
+
+x {
+    color: *;  /* Test simple error to ensure parsing recovered. */
+}
+
+</style>
+
+<script>
+
+function test()
+{
+    // Ensure script generated errors don't go to the console.
+    var style = document.createElement('style');
+    style.textContent = "x{y:*}";
+    document.head.appendChild(style);
+
+    InspectorTest.expandConsoleMessages();
+    InspectorTest.dumpConsoleMessages();
+    InspectorTest.completeTest();
+}
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p id="p">Tests CSS warnings are properly exposed.</p>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (146451 => 146452)


--- trunk/Source/WebCore/ChangeLog	2013-03-21 11:17:30 UTC (rev 146451)
+++ trunk/Source/WebCore/ChangeLog	2013-03-21 11:41:39 UTC (rev 146452)
@@ -1,5 +1,28 @@
 2013-03-21  Sergey Ryazanov  <[email protected]>
 
+        Web Inspector: Track CSS error location information.
+        https://bugs.webkit.org/show_bug.cgi?id=111314
+
+        Added CSS syntax error reporting to some (other rules will be covered later) error recovery grammar rules.
+        Added code to CSSParser to allow track error location information.
+        Added empty rule to declaration_list. Needed to not report error about declarations like "body {}".
+        Added helper grammar rule "errors: error | errors error". Handles the same grammar as "error" but simplifies error location tracking.
+
+        Reviewed by Pavel Feldman.
+
+        Test: inspector/console/console-css-warnings.html
+
+        * css/CSSGrammar.y.in:
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::CSSParser):
+        (WebCore::CSSParser::currentLocation):
+        (WebCore):
+        (WebCore::CSSParser::realLex):
+        * css/CSSParser.h:
+        (CSSParser):
+
+2013-03-21  Sergey Ryazanov  <[email protected]>
+
         Changing "#define YYDEBUG 0" to 1 causing compilation error
         https://bugs.webkit.org/show_bug.cgi?id=111178
 

Modified: trunk/Source/WebCore/css/CSSGrammar.y.in (146451 => 146452)


--- trunk/Source/WebCore/css/CSSGrammar.y.in	2013-03-21 11:17:30 UTC (rev 146451)
+++ trunk/Source/WebCore/css/CSSGrammar.y.in	2013-03-21 11:41:39 UTC (rev 146452)
@@ -50,6 +50,7 @@
     Vector<RefPtr<StyleKeyframe> >* keyframeRuleList;
     float val;
     CSSPropertyID id;
+    CSSParser::Location location;
 }
 
 %{
@@ -336,6 +337,8 @@
 %type <string> element_name
 %type <string> attr_name
 
+%type <location> errors
+
 %%
 
 stylesheet:
@@ -1534,7 +1537,8 @@
   ;
 
 declaration_list:
-    declaration {
+    /* empty */ { $$ = false; }
+    | declaration {
         $$ = $1;
     }
     | decl_list declaration {
@@ -1545,10 +1549,12 @@
     | decl_list {
         $$ = $1;
     }
-    | error invalid_block_list error {
+    | errors invalid_block_list error {
+        parser->syntaxError($1);
         $$ = false;
     }
-    | error {
+    | errors {
+        parser->syntaxError($1);
         $$ = false;
     }
     | decl_list error {
@@ -1570,11 +1576,13 @@
     | declaration invalid_block_list ';' maybe_space {
         $$ = false;
     }
-    | error ';' maybe_space {
+    | errors ';' maybe_space {
+        parser->syntaxError($1);
         parser->markPropertyStart();
         $$ = false;
     }
-    | error invalid_block_list error ';' maybe_space {
+    | errors invalid_block_list error ';' maybe_space {
+        parser->syntaxError($1);
         $$ = false;
     }
     | decl_list declaration ';' maybe_space {
@@ -2011,5 +2019,14 @@
   | invalid_block_list error invalid_block
 ;
 
+errors:
+    error {
+        $$ = parser->currentLocation();
+    }
+  | errors error {
+        $$ = $1;
+    }
+    ;
+
 %%
 

Modified: trunk/Source/WebCore/css/CSSParser.cpp (146451 => 146452)


--- trunk/Source/WebCore/css/CSSParser.cpp	2013-03-21 11:17:30 UTC (rev 146451)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2013-03-21 11:41:39 UTC (rev 146452)
@@ -334,6 +334,7 @@
     , m_length(0)
     , m_token(0)
     , m_lineNumber(0)
+    , m_tokenStartLineNumber(0)
     , m_lastSelectorLineNumber(0)
     , m_allowImportRules(true)
     , m_allowNamespaceDeclarations(true)
@@ -9737,6 +9738,17 @@
     return m_tokenStart.ptr16;
 }
 
+CSSParser::Location CSSParser::currentLocation()
+{
+    Location location;
+    location.lineNumber = m_tokenStartLineNumber;
+    if (is8BitSource())
+        location.token.init(tokenStart<LChar>(), currentCharacter<LChar>() - tokenStart<LChar>());
+    else
+        location.token.init(tokenStart<UChar>(), currentCharacter<UChar>() - tokenStart<UChar>());
+    return location;
+}
+
 template <typename CharacterType>
 inline bool CSSParser::isIdentifierStart()
 {
@@ -10592,6 +10604,7 @@
 restartAfterComment:
     result = currentCharacter<SrcCharacterType>();
     setTokenStart(result);
+    m_tokenStartLineNumber = m_lineNumber;
     m_token = *currentCharacter<SrcCharacterType>();
     ++currentCharacter<SrcCharacterType>();
 

Modified: trunk/Source/WebCore/css/CSSParser.h (146451 => 146452)


--- trunk/Source/WebCore/css/CSSParser.h	2013-03-21 11:17:30 UTC (rev 146451)
+++ trunk/Source/WebCore/css/CSSParser.h	2013-03-21 11:41:39 UTC (rev 146452)
@@ -439,6 +439,8 @@
 
     static KURL completeURL(const CSSParserContext&, const String& url);
 
+    Location currentLocation();
+
 private:
     bool is8BitSource() { return m_is8BitSource; }
 
@@ -577,6 +579,7 @@
     unsigned m_length;
     int m_token;
     int m_lineNumber;
+    int m_tokenStartLineNumber;
     int m_lastSelectorLineNumber;
 
     bool m_allowImportRules;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to