Title: [106589] trunk
Revision
106589
Author
[email protected]
Date
2012-02-02 13:19:53 -0800 (Thu, 02 Feb 2012)

Log Message

Getters and setters cause line numbers in errors/console.log to be offset for the whole file
https://bugs.webkit.org/show_bug.cgi?id=77675

Reviewed by Timothy Hatcher.

Source/_javascript_Core:

Our default literal parsing logic doesn't handle the extra work required for
getters and setters.  When it encounters one, it rolls back the lexer and
then switches to a more complete parsing function.  Unfortunately it was only
winding back the character position, and was ignoring the line number and
other lexer data.  This led to every getter and setter causing the line number
to be incorrectly incremented leading to increasingly incorrect numbers for
the rest of the file.

* parser/Parser.cpp:
(JSC::::parseObjectLiteral):

LayoutTests:

Add getter and setter line number tests.

* fast/js/exception-linenums-expected.txt:
* fast/js/script-tests/exception-linenums.js:
(firstPropIsGetter.get getter):
(secondPropIsGetter.prop.1.get getter):
(firstPropIsSetter.set setter):
(secondPropIsSetter.prop.1.set setter):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (106588 => 106589)


--- trunk/LayoutTests/ChangeLog	2012-02-02 21:18:37 UTC (rev 106588)
+++ trunk/LayoutTests/ChangeLog	2012-02-02 21:19:53 UTC (rev 106589)
@@ -1,3 +1,19 @@
+2012-02-02  Oliver Hunt  <[email protected]>
+
+        Getters and setters cause line numbers in errors/console.log to be offset for the whole file
+        https://bugs.webkit.org/show_bug.cgi?id=77675
+
+        Reviewed by Timothy Hatcher.
+
+        Add getter and setter line number tests.
+
+        * fast/js/exception-linenums-expected.txt:
+        * fast/js/script-tests/exception-linenums.js:
+        (firstPropIsGetter.get getter):
+        (secondPropIsGetter.prop.1.get getter):
+        (firstPropIsSetter.set setter):
+        (secondPropIsSetter.prop.1.set setter):
+
 2012-02-02  Nate Chapin  <[email protected]>
 
         Unreviewed, chromium expectations update.

Modified: trunk/LayoutTests/fast/js/exception-linenums-expected.txt (106588 => 106589)


--- trunk/LayoutTests/fast/js/exception-linenums-expected.txt	2012-02-02 21:18:37 UTC (rev 106588)
+++ trunk/LayoutTests/fast/js/exception-linenums-expected.txt	2012-02-02 21:19:53 UTC (rev 106589)
@@ -15,6 +15,10 @@
 PASS e.line is 5
 PASS typeof e.sourceURL is "string"
 PASS e.line is 64
+PASS e.line is 74
+PASS e.line is 78
+PASS e.line is 81
+PASS e.line is 85
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/js/script-tests/exception-linenums.js (106588 => 106589)


--- trunk/LayoutTests/fast/js/script-tests/exception-linenums.js	2012-02-02 21:18:37 UTC (rev 106588)
+++ trunk/LayoutTests/fast/js/script-tests/exception-linenums.js	2012-02-02 21:19:53 UTC (rev 106589)
@@ -69,3 +69,46 @@
 eval = realEval;
 shouldBe("typeof e.sourceURL", '"string"');
 shouldBe("e.line", '64');
+
+var firstPropIsGetter = {
+    get getter() { throw {} }
+};
+var secondPropIsGetter = {
+    prop: 1,
+    get getter() { throw {} }
+};
+var firstPropIsSetter = {
+    set setter(a) { throw {} }
+};
+var secondPropIsSetter = {
+    prop: 1,
+    set setter(a) { throw {} }
+};
+
+try {
+    firstPropIsGetter.getter;
+} catch(ex) {
+    e = ex;
+    shouldBe("e.line", "74");
+}
+
+try {
+    secondPropIsGetter.getter;
+} catch(ex) {
+    e = ex;
+    shouldBe("e.line", "78");
+}
+
+try {
+    firstPropIsSetter.setter = '';
+} catch(ex) {
+    e = ex;
+    shouldBe("e.line", "81");
+}
+
+try {
+    secondPropIsSetter.setter = '';
+} catch(ex) {
+    e = ex;
+    shouldBe("e.line", "85");
+}

Modified: trunk/Source/_javascript_Core/ChangeLog (106588 => 106589)


--- trunk/Source/_javascript_Core/ChangeLog	2012-02-02 21:18:37 UTC (rev 106588)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-02-02 21:19:53 UTC (rev 106589)
@@ -1,3 +1,21 @@
+2012-02-02  Oliver Hunt  <[email protected]>
+
+        Getters and setters cause line numbers in errors/console.log to be offset for the whole file
+        https://bugs.webkit.org/show_bug.cgi?id=77675
+
+        Reviewed by Timothy Hatcher.
+
+        Our default literal parsing logic doesn't handle the extra work required for
+        getters and setters.  When it encounters one, it rolls back the lexer and 
+        then switches to a more complete parsing function.  Unfortunately it was only
+        winding back the character position, and was ignoring the line number and
+        other lexer data.  This led to every getter and setter causing the line number
+        to be incorrectly incremented leading to increasingly incorrect numbers for
+        the rest of the file.
+
+        * parser/Parser.cpp:
+        (JSC::::parseObjectLiteral):
+
 2012-02-02  Andy Wingo  <[email protected]>
 
         Fix type punning warning in HashTable.h debug builds

Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (106588 => 106589)


--- trunk/Source/_javascript_Core/parser/Parser.cpp	2012-02-02 21:18:37 UTC (rev 106588)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp	2012-02-02 21:19:53 UTC (rev 106589)
@@ -1240,6 +1240,8 @@
 template <class TreeBuilder> TreeExpression Parser<LexerType>::parseObjectLiteral(TreeBuilder& context)
 {
     int startOffset = m_token.m_data.intValue;
+    unsigned oldLastLineNumber = m_lexer->lastLineNumber();
+    unsigned oldLineNumber = m_lexer->lineNumber();
     consumeOrFailWithFlags(OPENBRACE, TreeBuilder::DontBuildStrings);
     
     if (match(CLOSEBRACE)) {
@@ -1252,6 +1254,8 @@
     if (!m_syntaxAlreadyValidated && context.getType(property) != PropertyNode::Constant) {
         m_lexer->setOffset(startOffset);
         next();
+        m_lexer->setLastLineNumber(oldLastLineNumber);
+        m_lexer->setLineNumber(oldLineNumber);
         return parseStrictObjectLiteral(context);
     }
     TreePropertyList propertyList = context.createPropertyList(m_lexer->lastLineNumber(), property);
@@ -1266,6 +1270,8 @@
         if (!m_syntaxAlreadyValidated && context.getType(property) != PropertyNode::Constant) {
             m_lexer->setOffset(startOffset);
             next();
+            m_lexer->setLastLineNumber(oldLastLineNumber);
+            m_lexer->setLineNumber(oldLineNumber);
             return parseStrictObjectLiteral(context);
         }
         tail = context.createPropertyList(m_lexer->lastLineNumber(), property, tail);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to