Commit b891addd authored by hyatt's avatar hyatt

Rework line numbering (again). This time I finally think I have

        it right for all the document.write insanity that can occur.

        Reviewed by aroben

        * html/HTMLParser.cpp:
        (WebCore::HTMLParser::reportErrorToConsole):
        * html/HTMLParserErrorCodes.cpp:
        (WebCore::htmlParserDocumentWriteMessage):
        * html/HTMLParserErrorCodes.h:
        * html/HTMLTokenizer.cpp:
        (WebCore::HTMLTokenizer::write):
        * html/HTMLTokenizer.h:
        (WebCore::HTMLTokenizer::lineNumberPtr):
        (WebCore::HTMLTokenizer::processingContentWrittenByScript):
        * platform/SegementedSring.cpp
        (WebCore::SegmentedString::setExcludeLineNumbers):
        * platform/SegmentedString.h:
        (WebCore::SegmentedSubstring::SegmentedSubstring):
        (WebCore::SegmentedSubstring::clear):
        (WebCore::SegmentedSubstring::excludeLineNumbers):
        (WebCore::SegmentedSubstring::setExcludeLineNumbers):
        (WebCore::SegmentedString::excludeLineNumbers):
        (WebCore::SegmentedString::advance):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@21746 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ea8c0392
2007-05-25 David Hyatt <hyatt@apple.com>
Rework line numbering (again). This time I finally think I have
it right for all the document.write insanity that can occur.
Reviewed by aroben
* html/HTMLParser.cpp:
(WebCore::HTMLParser::reportErrorToConsole):
* html/HTMLParserErrorCodes.cpp:
(WebCore::htmlParserDocumentWriteMessage):
* html/HTMLParserErrorCodes.h:
* html/HTMLTokenizer.cpp:
(WebCore::HTMLTokenizer::write):
* html/HTMLTokenizer.h:
(WebCore::HTMLTokenizer::lineNumberPtr):
(WebCore::HTMLTokenizer::processingContentWrittenByScript):
* platform/SegementedSring.cpp
(WebCore::SegmentedString::setExcludeLineNumbers):
* platform/SegmentedString.h:
(WebCore::SegmentedSubstring::SegmentedSubstring):
(WebCore::SegmentedSubstring::clear):
(WebCore::SegmentedSubstring::excludeLineNumbers):
(WebCore::SegmentedSubstring::setExcludeLineNumbers):
(WebCore::SegmentedString::excludeLineNumbers):
(WebCore::SegmentedString::advance):
2007-05-24 Geoffrey Garen <ggaren@apple.com>
Reviewed by Adam Roben.
......@@ -1447,7 +1447,11 @@ void HTMLParser::reportErrorToConsole(HTMLParserErrorCode errorCode, const Atomi
const char* errorMsg = htmlParserErrorMessageTemplate(errorCode);
if (!errorMsg)
return;
String message(errorMsg);
String message;
if (htmlTokenizer->processingContentWrittenByScript())
message += htmlParserDocumentWriteMessage();
message += errorMsg;
message.replace("%tag1", tag1);
message.replace("%tag2", tag2);
......
......@@ -57,6 +57,11 @@ const char* htmlParserErrorMessageTemplate(HTMLParserErrorCode errorCode)
return 0;
}
const char* htmlParserDocumentWriteMessage()
{
return "[The HTML that caused this error was generated by a script.] ";
}
bool isWarning(HTMLParserErrorCode code)
{
return code >= IncorrectXMLCloseScriptWarning;
......
......@@ -51,6 +51,8 @@ enum HTMLParserErrorCode {
};
const char* htmlParserErrorMessageTemplate(HTMLParserErrorCode);
const char* htmlParserDocumentWriteMessage();
bool isWarning(HTMLParserErrorCode);
}
......
......@@ -1314,20 +1314,23 @@ bool HTMLTokenizer::write(const SegmentedString& str, bool appendData)
if (m_parserStopped)
return false;
if ( ( m_executingScript && appendData ) || !pendingScripts.isEmpty() ) {
SegmentedString source(str);
if (m_executingScript)
source.setExcludeLineNumbers();
if ((m_executingScript && appendData) || !pendingScripts.isEmpty()) {
// don't parse; we will do this later
if (currentPrependingSrc) {
currentPrependingSrc->append(str);
} else {
pendingSrc.append(str);
}
if (currentPrependingSrc)
currentPrependingSrc->append(source);
else
pendingSrc.append(source);
return false;
}
if (!src.isEmpty())
src.append(str);
src.append(source);
else
setSrc(str);
setSrc(source);
// Once a timer is set, it has control of when the tokenizer continues.
if (m_timer.isActive())
......@@ -1444,7 +1447,7 @@ bool HTMLTokenizer::write(const SegmentedString& str, bool appendData)
else {
// Process this LF
*dest++ = '\n';
if (cc == '\r')
if (cc == '\r' && !src.excludeLineNumbers())
lineno++;
}
......
......@@ -103,7 +103,9 @@ public:
virtual int lineNumber() const { return lineno; }
virtual int columnNumber() const { return 1; }
int* lineNumberPtr() { return m_executingScript ? 0 : &lineno; }
int* lineNumberPtr() { return &lineno; }
bool processingContentWrittenByScript() const { return src.excludeLineNumbers(); }
private:
class State;
......@@ -126,7 +128,7 @@ private:
State scriptHandler(State);
State scriptExecution(const DeprecatedString& script, State, DeprecatedString scriptURL, int baseLine = 0);
void setSrc(const SegmentedString&);
// check if we have enough space in the buffer.
// if not enlarge it
inline void checkBuffer(int len = 10)
......
......@@ -69,6 +69,17 @@ unsigned SegmentedString::length() const
return length;
}
void SegmentedString::setExcludeLineNumbers()
{
if (m_composite) {
DeprecatedValueListIterator<SegmentedSubstring> i = m_substrings.begin();
DeprecatedValueListIterator<SegmentedSubstring> e = m_substrings.end();
for (; i != e; ++i)
(*i).setExcludeLineNumbers();
} else
m_currentString.setExcludeLineNumbers();
}
void SegmentedString::clear()
{
m_pushedChar1 = 0;
......
......@@ -33,15 +33,18 @@ class SegmentedSubstring {
private:
friend class SegmentedString;
SegmentedSubstring() : m_length(0), m_current(0) {}
SegmentedSubstring(const String& str) : m_string(str), m_length(str.length()) {
SegmentedSubstring() : m_length(0), m_current(0), m_excludeLineNumbers(false) {}
SegmentedSubstring(const String& str) : m_string(str), m_length(str.length()), m_excludeLineNumbers(false) {
m_current = m_length == 0 ? 0 : m_string.characters();
}
SegmentedSubstring(const UChar* str, int length) : m_length(length), m_current(length == 0 ? 0 : str) {}
SegmentedSubstring(const UChar* str, int length) : m_length(length), m_current(length == 0 ? 0 : str), m_excludeLineNumbers(false) {}
void clear() { m_length = 0; m_current = 0; }
void clear() { m_length = 0; m_current = 0; m_excludeLineNumbers = false; }
bool excludeLineNumbers() const { return m_excludeLineNumbers; }
void setExcludeLineNumbers() { m_excludeLineNumbers = true; }
void appendTo(String& str) const {
if (m_string.characters() == m_current) {
if (str.isEmpty())
......@@ -56,6 +59,7 @@ private:
String m_string;
int m_length;
const UChar* m_current;
bool m_excludeLineNumbers;
};
class SegmentedString {
......@@ -76,6 +80,9 @@ public:
void append(const SegmentedString &);
void prepend(const SegmentedString &);
bool excludeLineNumbers() const { return m_currentString.excludeLineNumbers(); }
void setExcludeLineNumbers();
void push(UChar c) {
if (!m_pushedChar1) {
m_pushedChar1 = c;
......@@ -94,7 +101,7 @@ public:
m_pushedChar1 = m_pushedChar2;
m_pushedChar2 = 0;
} else if (m_currentString.m_current) {
if (*m_currentString.m_current++ == '\n' && lineNumber)
if (*m_currentString.m_current++ == '\n' && lineNumber && !m_currentString.excludeLineNumbers())
*lineNumber = *lineNumber + 1;
if (--m_currentString.m_length == 0)
advanceSubstring();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment