JavaScriptCore/ChangeLog

 12010-09-23 Peter Rybin <peter.rybin@gmail.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 HTML parser should provide script column position within HTML document to JavaScript engine
 6 https://bugs.webkit.org/show_bug.cgi?id=45271
 7
 8 Adds TextPosition* classes -- a structure that stores line/column/generation
 9 level coordinates inside text document. Adds *BasedNumber classes -- typesafe int
 10 wrappers that emphasize whether int number is used as zero-based or
 11 one-based.
 12
 13 * GNUmakefile.am:
 14 * JavaScriptCore.gypi:
 15 * wtf/CMakeLists.txt:
 16 * wtf/TextPosition.cpp: Added.
 17 * wtf/TextPosition.h: Added.
 18 (WTF::TextPosition::TextPosition):
 19 (WTF::TextPosition::minimumPosition):
 20 (WTF::TextPosition::belowRangePosition):
 21 (WTF::ZeroBasedNumber::fromZeroBasedInt):
 22 (WTF::ZeroBasedNumber::ZeroBasedNumber):
 23 (WTF::ZeroBasedNumber::zeroBasedInt):
 24 (WTF::OneBasedNumber::fromOneBasedInt):
 25 (WTF::OneBasedNumber::OneBasedNumber):
 26 (WTF::OneBasedNumber::oneBasedInt):
 27 (WTF::OneBasedNumber::convertAsZeroBasedInt):
 28 (WTF::OneBasedNumber::convertToZeroBased):
 29 (WTF::toZeroBasedTextPosition):
 30 (WTF::toOneBasedTextPosition):
 31 (WTF::ZeroBasedNumber::convertToOneBased):
 32 * wtf/wtf.pri:
 33
1342010-09-22 Oliver Hunt <oliver@apple.com>
235
336 Reviewed by Geoff Garen.

JavaScriptCore/GNUmakefile.am

@@javascriptcore_sources += \
513513 JavaScriptCore/wtf/text/StringStatics.cpp \
514514 JavaScriptCore/wtf/text/WTFString.cpp \
515515 JavaScriptCore/wtf/text/WTFString.h \
 516 JavaScriptCore/wtf/TextPosition.cpp \
 517 JavaScriptCore/wtf/TextPosition.h \
516518 JavaScriptCore/wtf/ThreadIdentifierDataPthreads.cpp \
517519 JavaScriptCore/wtf/ThreadIdentifierDataPthreads.h \
518520 JavaScriptCore/wtf/Threading.cpp \

JavaScriptCore/JavaScriptCore.gypi

424424 'wtf/StringExtras.h',
425425 'wtf/StringHashFunctions.h',
426426 'wtf/TCPackedCache.h',
 427 'wtf/TextPosition.h',
 428 'wtf/TextPosition.cpp',
427429 'wtf/qt/MainThreadQt.cpp',
428430 'wtf/qt/StringQt.cpp',
429431 'wtf/qt/ThreadingQt.cpp',

JavaScriptCore/wtf/CMakeLists.txt

@@SET(WTF_SOURCES
99 RandomNumber.cpp
1010 RefCountedLeakCounter.cpp
1111 StringExtras.cpp
 12 TextPosition.cpp
1213 Threading.cpp
1314 TypeTraits.cpp
1415 WTFThreadData.cpp

JavaScriptCore/wtf/TextPosition.cpp

 1/*
 2 * Copyright (C) 2010, Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 23 */
 24
 25#include "config.h"
 26#include "TextPosition.h"
 27
 28namespace WTF {
 29
 30const ZeroBasedNumber ZeroBasedNumber::s_base(0);
 31const ZeroBasedNumber ZeroBasedNumber::s_belowBase(-1);
 32
 33const OneBasedNumber OneBasedNumber::s_base(1);
 34const OneBasedNumber OneBasedNumber::s_belowBase(0);
 35
 36
 37} // namespace WTF

JavaScriptCore/wtf/TextPosition.h

 1/*
 2 * Copyright (C) 2010, Google Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 23 */
 24
 25#ifndef TextPosition_h
 26#define TextPosition_h
 27
 28#include <wtf/Assertions.h>
 29
 30namespace WTF {
 31
 32
 33/*
 34 * Text Position
 35 *
 36 * TextPosition structure specifies coordinates within an text resource. It is used mostly
 37 * for saving script source position. The third field 'generation' reflects the fact
 38 * that in HTML document its any part can be generated on the fly, by a 'document.write'
 39 * call. While elements of the generated part may still have coordinates (probably),
 40 * we need to distinguish them from coordinates in the original text.
 41 * So generation == 0 means that coordinates apply to original text,
 42 * generation == 1 applies to a elements generated by a script in original text,
 43 * generation == 2 to elements generated from a script in a generated part and so on.
 44 *
 45 * Later TextPosition0 and TextPosition1 and both number types can be merged together quite easily.
 46 *
 47 *
 48 * 0-based and 1-based
 49 *
 50 * Line and column numbers could be interpreted as zero-based or 1-based. Since
 51 * both practices coexist in WebKit source base, 'int' type should be replaced with
 52 * a dedicated wrapper types, so that compiler helped us with this ambiguity.
 53 *
 54 * Here we introduce 2 types of numbers: ZeroBasedNumber and OneBasedNumber and
 55 * 2 corresponding types of TextPosition structure. While only one type ought to be enough,
 56 * this is done to keep transition to the new types as transparent as possible:
 57 * e.g. in areas where 0-based integers are used, TextPosition0 should be introduced. This
 58 * way all changes will remain trackable.
 59 *
 60 * Later both number types can be merged in one type quite easily.
 61 *
 62 * For type safety and for the future type merge it is important that all operations in API
 63 * that accept or return integer have a name explicitly defining base of integer. For this reason
 64 * int-receiving constructors are hidden from API.
 65 */
 66
 67template<typename NUMBER>
 68class TextPosition {
 69public:
 70 TextPosition(NUMBER line, NUMBER column, int generation)
 71 : m_line(line)
 72 , m_column(column)
 73 , m_generation(generation)
 74 {
 75 }
 76 TextPosition() {}
 77
 78 // A 'minimum' value of position, used as a default value.
 79 static TextPosition<NUMBER> minimumPosition() { return TextPosition<NUMBER>(NUMBER::s_base, NUMBER::s_base, 0); }
 80
 81 // A value with line value less than a minimum; used as an impossible position.
 82 static TextPosition<NUMBER> belowRangePosition() { return TextPosition<NUMBER>(NUMBER::s_belowBase, NUMBER::s_base, 0); }
 83
 84 NUMBER m_line;
 85 NUMBER m_column;
 86 int m_generation;
 87};
 88
 89
 90class OneBasedNumber;
 91
 92// An int wrapper that always reminds you that the number should be 0-based
 93class ZeroBasedNumber {
 94public:
 95 static ZeroBasedNumber fromZeroBasedInt(int zeroBasedInt) { return ZeroBasedNumber(zeroBasedInt); }
 96
 97 ZeroBasedNumber() {}
 98
 99 int zeroBasedInt() const { return m_value; }
 100
 101 OneBasedNumber convertToOneBased() const;
 102
 103 static const ZeroBasedNumber s_base; // 0
 104 static const ZeroBasedNumber s_belowBase; // -1
 105
 106private:
 107 ZeroBasedNumber(int value) : m_value(value) {}
 108 int m_value;
 109};
 110
 111// An int wrapper that always reminds you that the number should be 1-based
 112class OneBasedNumber {
 113public:
 114 static OneBasedNumber fromOneBasedInt(int oneBasedInt) { return OneBasedNumber(oneBasedInt); }
 115 OneBasedNumber() {}
 116
 117 int oneBasedInt() const { return m_value; }
 118 int convertAsZeroBasedInt() const { return m_value - 1; }
 119 ZeroBasedNumber convertToZeroBased() const { return ZeroBasedNumber::fromZeroBasedInt(m_value - 1); }
 120
 121 static const OneBasedNumber s_base; // 1
 122 static const OneBasedNumber s_belowBase; // 0
 123
 124private:
 125 OneBasedNumber(int value) : m_value(value) {}
 126 int m_value;
 127};
 128
 129typedef TextPosition<ZeroBasedNumber> TextPosition0;
 130typedef TextPosition<OneBasedNumber> TextPosition1;
 131
 132inline TextPosition0 toZeroBasedTextPosition(const TextPosition1& position)
 133{
 134 return TextPosition0(position.m_line.convertToZeroBased(), position.m_column.convertToZeroBased(), position.m_generation);
 135}
 136
 137inline TextPosition1 toOneBasedTextPosition(const TextPosition0& position)
 138{
 139 return TextPosition1(position.m_line.convertToOneBased(), position.m_column.convertToOneBased(), position.m_generation);
 140}
 141
 142inline OneBasedNumber ZeroBasedNumber::convertToOneBased() const
 143{
 144 return OneBasedNumber::fromOneBasedInt(m_value + 1);
 145}
 146
 147}
 148
 149
 150using WTF::TextPosition0;
 151using WTF::TextPosition1;
 152
 153#endif // TextPosition_h

JavaScriptCore/wtf/wtf.pri

@@SOURCES += \
1616 wtf/PageAllocation.cpp \
1717 wtf/RandomNumber.cpp \
1818 wtf/RefCountedLeakCounter.cpp \
 19 wtf/TextPosition.cpp \
1920 wtf/ThreadingNone.cpp \
2021 wtf/Threading.cpp \
2122 wtf/TypeTraits.cpp \

WebCore/ChangeLog

 12010-09-23 Peter Rybin <peter.rybin@gmail.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 HTML parser should provide script column position within HTML document to JavaScript engine
 6 https://bugs.webkit.org/show_bug.cgi?id=45271
 7
 8 Replaces line number with TextPosition struct so that script engine
 9 gets script starting line/column.
 10
 11 * bindings/js/ScriptSourceCode.h:
 12 (WebCore::ScriptSourceCode::ScriptSourceCode):
 13 * bindings/v8/ScheduledAction.cpp:
 14 (WebCore::ScheduledAction::ScheduledAction):
 15 * bindings/v8/ScriptController.cpp:
 16 (WebCore::ScriptController::eventHandlerPosition):
 17 * bindings/v8/ScriptController.h:
 18 * bindings/v8/ScriptEventListener.cpp:
 19 (WebCore::createAttributeEventListener):
 20 * bindings/v8/ScriptSourceCode.h:
 21 (WebCore::ScriptSourceCode::ScriptSourceCode):
 22 (WebCore::ScriptSourceCode::startLine):
 23 (WebCore::ScriptSourceCode::startPosition):
 24 * bindings/v8/V8LazyEventListener.cpp:
 25 (WebCore::V8LazyEventListener::V8LazyEventListener):
 26 (WebCore::V8LazyEventListener::prepareListenerObject):
 27 * bindings/v8/V8LazyEventListener.h:
 28 (WebCore::V8LazyEventListener::create):
 29 * bindings/v8/V8Proxy.cpp:
 30 (WebCore::V8Proxy::compileScript):
 31 (WebCore::V8Proxy::evaluate):
 32 (WebCore::V8Proxy::runScript):
 33 * bindings/v8/V8Proxy.h:
 34 * bindings/v8/WorkerContextExecutionProxy.cpp:
 35 (WebCore::WorkerContextExecutionProxy::evaluate):
 36 (WebCore::WorkerContextExecutionProxy::runScript):
 37 * bindings/v8/WorkerContextExecutionProxy.h:
 38 * bindings/v8/WorkerScriptController.cpp:
 39 (WebCore::WorkerScriptController::evaluate):
 40 * dom/PendingScript.cpp:
 41 (WebCore::PendingScript::releaseElementAndClear):
 42 * dom/PendingScript.h:
 43 (WebCore::PendingScript::PendingScript):
 44 (WebCore::PendingScript::operator=):
 45 (WebCore::PendingScript::startingPosition):
 46 * dom/ScriptableDocumentParser.h:
 47 * dom/XMLDocumentParser.h:
 48 * dom/XMLDocumentParserLibxml2.cpp:
 49 (WebCore::XMLDocumentParser::XMLDocumentParser):
 50 (WebCore::XMLDocumentParser::startElementNs):
 51 (WebCore::XMLDocumentParser::endElementNs):
 52 (WebCore::XMLDocumentParser::lineNumber):
 53 (WebCore::XMLDocumentParser::columnNumber):
 54 (WebCore::XMLDocumentParser::textPosition):
 55 * dom/XMLDocumentParserQt.cpp:
 56 (WebCore::XMLDocumentParser::XMLDocumentParser):
 57 (WebCore::XMLDocumentParser::textPosition):
 58 (WebCore::XMLDocumentParser::parseStartElement):
 59 (WebCore::XMLDocumentParser::parseEndElement):
 60 * html/parser/HTMLDocumentParser.cpp:
 61 (WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder):
 62 (WebCore::HTMLDocumentParser::textPosition):
 63 * html/parser/HTMLDocumentParser.h:
 64 * html/parser/HTMLScriptRunner.cpp:
 65 (WebCore::HTMLScriptRunner::sourceFromPendingScript):
 66 (WebCore::HTMLScriptRunner::execute):
 67 (WebCore::HTMLScriptRunner::runScript):
 68 * html/parser/HTMLScriptRunner.h:
 69 * html/parser/HTMLTreeBuilder.cpp:
 70 (WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
 71 (WebCore::HTMLTreeBuilder::takeScriptToProcess):
 72 (WebCore::HTMLTreeBuilder::processEndTag):
 73 (WebCore::HTMLTreeBuilder::processScriptStartTag):
 74 * html/parser/HTMLTreeBuilder.h:
 75
1762010-09-23 Patrick Gansterer <paroga@webkit.org>
277
378 Reviewed by Adam Roben.

WebCore/bindings/js/ScriptSourceCode.h

3535#include "ScriptSourceProvider.h"
3636#include "StringSourceProvider.h"
3737#include "KURL.h"
 38#include <wtf/TextPosition.h>
3839#include <wtf/RefPtr.h>
3940
4041namespace WebCore {
4142
4243class ScriptSourceCode {
4344public:
44  ScriptSourceCode(const String& source, const KURL& url = KURL(), int startLine = 1)
 45 ScriptSourceCode(const String& source, const KURL& url = KURL(), const TextPosition1& startPosition = TextPosition1::minimumPosition())
4546 : m_provider(StringSourceProvider::create(source, url.isNull() ? String() : url.string()))
46  , m_code(m_provider, startLine)
 47 , m_code(m_provider, startPosition.m_line.oneBasedInt())
4748 , m_url(url)
4849 {
4950 }

WebCore/bindings/v8/ScheduledAction.cpp

@@namespace WebCore {
4545
4646ScheduledAction::ScheduledAction(v8::Handle<v8::Context> context, v8::Handle<v8::Function> func, int argc, v8::Handle<v8::Value> argv[])
4747 : m_context(context)
48  , m_code(String(), KURL(), 0)
 48 , m_code(String(), KURL(), TextPosition1::belowRangePosition())
4949{
5050 m_function = v8::Persistent<v8::Function>::New(func);
5151

WebCore/bindings/v8/ScriptController.cpp

@@ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode, Shoul
260260 return ScriptValue(object);
261261}
262262
263 int ScriptController::eventHandlerLineNumber() const
 263TextPosition0 ScriptController::eventHandlerPosition() const
264264{
265265 ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentParser();
266266 if (parser)
267  return parser->lineNumber();
268  return 0;
269 }
270 
271 int ScriptController::eventHandlerColumnNumber() const
272 {
273  ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentParser();
274  if (parser)
275  return parser->columnNumber();
276  return 0;
 267 return parser->textPosition();
 268 return TextPosition0::minimumPosition();
277269}
278270
279271void ScriptController::finishedWithEvent(Event* event)

WebCore/bindings/v8/ScriptController.h

@@public:
155155
156156 void finishedWithEvent(Event*);
157157
158  int eventHandlerLineNumber() const;
159  int eventHandlerColumnNumber() const;
 158 TextPosition0 eventHandlerPosition() const;
160159
161160 void setProcessingTimerCallback(bool processingTimerCallback) { m_processingTimerCallback = processingTimerCallback; }
162161 // FIXME: Currently we don't use the parameter world at all.

WebCore/bindings/v8/ScriptEventListener.cpp

@@PassRefPtr<V8LazyEventListener> createAttributeEventListener(Node* node, Attribu
5050 if (attr->isNull())
5151 return 0;
5252
53  int lineNumber = 1;
54  int columnNumber = 0;
 53 // FIXME: very strange: we initialize zero-based number with '1'.
 54 TextPosition0 position(WTF::ZeroBasedNumber::fromZeroBasedInt(1), WTF::ZeroBasedNumber::s_base, 0);
5555 String sourceURL;
5656
5757 if (Frame* frame = node->document()->frame()) {

@@PassRefPtr<V8LazyEventListener> createAttributeEventListener(Node* node, Attribu
6464 return 0;
6565 }
6666
67  lineNumber = scriptController->eventHandlerLineNumber();
68  columnNumber = scriptController->eventHandlerColumnNumber();
 67 position = scriptController->eventHandlerPosition();
6968 sourceURL = node->document()->url().string();
7069 }
7170
72  return V8LazyEventListener::create(attr->localName().string(), node->isSVGElement(), attr->value(), sourceURL, lineNumber, columnNumber, WorldContextHandle(UseMainWorld));
 71 return V8LazyEventListener::create(attr->localName().string(), node->isSVGElement(), attr->value(), sourceURL, position, WorldContextHandle(UseMainWorld));
7372}
7473
7574PassRefPtr<V8LazyEventListener> createAttributeEventListener(Frame* frame, Attribute* attr)

@@PassRefPtr<V8LazyEventListener> createAttributeEventListener(Frame* frame, Attri
8180 if (attr->isNull())
8281 return 0;
8382
84  int lineNumber = 1;
85  int columnNumber = 0;
86  String sourceURL;
87 
8883 ScriptController* scriptController = frame->script();
8984 if (!scriptController->canExecuteScripts(AboutToExecuteScript))
9085 return 0;

@@PassRefPtr<V8LazyEventListener> createAttributeEventListener(Frame* frame, Attri
9489 return 0;
9590 }
9691
97  lineNumber = scriptController->eventHandlerLineNumber();
98  columnNumber = scriptController->eventHandlerColumnNumber();
99  sourceURL = frame->document()->url().string();
100  return V8LazyEventListener::create(attr->localName().string(), frame->document()->isSVGDocument(), attr->value(), sourceURL, lineNumber, columnNumber, WorldContextHandle(UseMainWorld));
 92 TextPosition0 position = scriptController->eventHandlerPosition();
 93 String sourceURL = frame->document()->url().string();
 94 return V8LazyEventListener::create(attr->localName().string(), frame->document()->isSVGDocument(), attr->value(), sourceURL, position, WorldContextHandle(UseMainWorld));
10195}
10296
10397String eventListenerHandlerBody(Document* document, EventListener* listener)

WebCore/bindings/v8/ScriptSourceCode.h

3535#include "CachedScript.h"
3636#include "KURL.h"
3737#include "PlatformString.h"
 38#include <wtf/TextPosition.h>
3839
3940namespace WebCore {
4041
4142class ScriptSourceCode {
4243public:
43  ScriptSourceCode(const String& source, const KURL& url = KURL(), int startLine = 1)
 44 ScriptSourceCode(const String& source, const KURL& url = KURL(), const TextPosition1& startPosition = TextPosition1::minimumPosition())
4445 : m_source(source)
4546 , m_cachedScript(0)
4647 , m_url(url)
47  , m_startLine(startLine)
 48 , m_startPosition(startPosition)
4849 {
4950 }
5051

@@public:
5455 : m_source(cs->script())
5556 , m_cachedScript(cs)
5657 , m_url(ParsedURLString, cs->url())
57  , m_startLine(1)
 58 , m_startPosition(TextPosition1::minimumPosition())
5859 {
5960 }
6061

@@public:
6364 const String& source() const { return m_source; }
6465 CachedScript* cachedScript() const { return m_cachedScript.get(); }
6566 const KURL& url() const { return m_url; }
66  int startLine() const { return m_startLine; }
 67 int startLine() const { return m_startPosition.m_line.oneBasedInt(); }
 68 const TextPosition1& startPosition() const { return m_startPosition; }
6769
6870private:
6971 String m_source;
7072 CachedResourceHandle<CachedScript> m_cachedScript;
7173 KURL m_url;
72  int m_startLine;
 74 TextPosition1 m_startPosition;
7375};
7476
7577} // namespace WebCore

WebCore/bindings/v8/V8LazyEventListener.cpp

4141
4242namespace WebCore {
4343
44 V8LazyEventListener::V8LazyEventListener(const String& functionName, bool isSVGEvent, const String& code, const String sourceURL, int lineNumber, int columnNumber, const WorldContextHandle& worldContext)
 44V8LazyEventListener::V8LazyEventListener(const String& functionName, bool isSVGEvent, const String& code, const String sourceURL, const TextPosition0& position, const WorldContextHandle& worldContext)
4545 : V8AbstractEventListener(true, worldContext)
4646 , m_functionName(functionName)
4747 , m_isSVGEvent(isSVGEvent)
4848 , m_code(code)
4949 , m_sourceURL(sourceURL)
50  , m_lineNumber(lineNumber)
51  , m_columnNumber(columnNumber)
 50 , m_position(position)
5251{
5352}
5453

@@void V8LazyEventListener::prepareListenerObject(ScriptExecutionContext* context)
114113 // Insert '\n' otherwise //-style comments could break the handler.
115114 code.append( "\n}).call(this, evt);}}}})");
116115 v8::Handle<v8::String> codeExternalString = v8ExternalString(code);
117  v8::Handle<v8::Script> script = V8Proxy::compileScript(codeExternalString, m_sourceURL, m_lineNumber);
 116 v8::Handle<v8::Script> script = V8Proxy::compileScript(codeExternalString, m_sourceURL, m_position);
118117 if (!script.IsEmpty()) {
119118 v8::Local<v8::Value> value = proxy->runScript(script, false);
120119 if (!value.IsEmpty()) {

WebCore/bindings/v8/V8LazyEventListener.h

3434#include "PlatformString.h"
3535#include "V8AbstractEventListener.h"
3636#include <v8.h>
 37#include <wtf/TextPosition.h>
3738#include <wtf/PassRefPtr.h>
3839
3940namespace WebCore {

@@namespace WebCore {
4546 // A V8LazyEventListener is always a HTML event handler.
4647 class V8LazyEventListener : public V8AbstractEventListener {
4748 public:
48  static PassRefPtr<V8LazyEventListener> create(const String& functionName, bool isSVGEvent, const String& code, const String& sourceURL, int lineNumber, int columnNumber, const WorldContextHandle& worldContext)
 49 static PassRefPtr<V8LazyEventListener> create(const String& functionName, bool isSVGEvent, const String& code, const String& sourceURL, const TextPosition0& position, const WorldContextHandle& worldContext)
4950 {
50  return adoptRef(new V8LazyEventListener(functionName, isSVGEvent, code, sourceURL, lineNumber, columnNumber, worldContext));
 51 return adoptRef(new V8LazyEventListener(functionName, isSVGEvent, code, sourceURL, position, worldContext));
5152 }
5253
5354 virtual bool isLazy() const { return true; }

@@namespace WebCore {
5657 virtual void prepareListenerObject(ScriptExecutionContext*);
5758
5859 private:
59  V8LazyEventListener(const String& functionName, bool isSVGEvent, const String& code, const String sourceURL, int lineNumber, int columnNumber, const WorldContextHandle& worldContext);
 60 V8LazyEventListener(const String& functionName, bool isSVGEvent, const String& code, const String sourceURL, const TextPosition0& position, const WorldContextHandle& worldContext);
6061
6162 virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*);
6263

@@namespace WebCore {
7071 bool m_isSVGEvent;
7172 String m_code;
7273 String m_sourceURL;
73  int m_lineNumber;
74  int m_columnNumber;
 74 TextPosition0 m_position;
7575 };
7676
7777} // namespace WebCore

WebCore/bindings/v8/V8Proxy.cpp

@@V8Proxy::~V8Proxy()
238238 windowShell()->destroyGlobal();
239239}
240240
241 v8::Handle<v8::Script> V8Proxy::compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine, v8::ScriptData* scriptData)
 241v8::Handle<v8::Script> V8Proxy::compileScript(v8::Handle<v8::String> code, const String& fileName, const TextPosition0& scriptStartPosition, v8::ScriptData* scriptData)
242242{
243243 const uint16_t* fileNameString = fromWebCoreString(fileName);
244  v8::Handle<v8::String> name = v8::String::New(fileNameString, fileName.length());
245  v8::Handle<v8::Integer> line = v8::Integer::New(baseLine);
246  v8::ScriptOrigin origin(name, line);
 244 v8::Handle<v8::String> name;
 245 if (!scriptStartPosition.m_generation)
 246 name = v8::String::New(fileNameString, fileName.length());
 247 v8::Handle<v8::Integer> line = v8::Integer::New(scriptStartPosition.m_line.zeroBasedInt());
 248 v8::Handle<v8::Integer> column = v8::Integer::New(scriptStartPosition.m_column.zeroBasedInt());
 249 v8::ScriptOrigin origin(name, line, column);
247250 v8::Handle<v8::Script> script = v8::Script::Compile(code, &origin, scriptData);
248251 return script;
249252}

@@v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* nod
399402
400403 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at
401404 // 1, whereas v8 starts at 0.
402  v8::Handle<v8::Script> script = compileScript(code, source.url(), source.startLine() - 1, scriptData.get());
 405 v8::Handle<v8::Script> script = compileScript(code, source.url(), WTF::toZeroBasedTextPosition(source.startPosition()), scriptData.get());
403406#if PLATFORM(CHROMIUM)
404407 PlatformBridge::traceEventEnd("v8.compile", node, "");
405408

@@v8::Local<v8::Value> V8Proxy::runScript(v8::Handle<v8::Script> script, bool isIn
434437 // FIXME: Ideally, we should be able to re-use the origin of the
435438 // script passed to us as the argument instead of using an empty string
436439 // and 0 baseLine.
437  script = compileScript(code, "", 0);
 440 script = compileScript(code, "", TextPosition0::minimumPosition());
438441 }
439442
440443 if (handleOutOfMemory())

WebCore/bindings/v8/V8Proxy.h

@@namespace WebCore {
289289
290290 static v8::Handle<v8::Value> checkNewLegal(const v8::Arguments&);
291291
292  static v8::Handle<v8::Script> compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine, v8::ScriptData* = 0);
 292 static v8::Handle<v8::Script> compileScript(v8::Handle<v8::String> code, const String& fileName, const TextPosition0& scriptStartPosition, v8::ScriptData* = 0);
293293
294294 // If the exception code is different from zero, a DOM exception is
295295 // schedule to be thrown.

WebCore/bindings/v8/WorkerContextExecutionProxy.cpp

@@bool WorkerContextExecutionProxy::forgetV8EventObject(Event* event)
184184 return false;
185185}
186186
187 ScriptValue WorkerContextExecutionProxy::evaluate(const String& script, const String& fileName, int baseLine, WorkerContextExecutionState* state)
 187ScriptValue WorkerContextExecutionProxy::evaluate(const String& script, const String& fileName, const TextPosition0& scriptStartPosition, WorkerContextExecutionState* state)
188188{
189189 v8::HandleScope hs;
190190

@@ScriptValue WorkerContextExecutionProxy::evaluate(const String& script, const St
196196 v8::TryCatch exceptionCatcher;
197197
198198 v8::Local<v8::String> scriptString = v8ExternalString(script);
199  v8::Handle<v8::Script> compiledScript = V8Proxy::compileScript(scriptString, fileName, baseLine);
 199 v8::Handle<v8::Script> compiledScript = V8Proxy::compileScript(scriptString, fileName, scriptStartPosition);
200200 v8::Local<v8::Value> result = runScript(compiledScript);
201201
202202 if (!exceptionCatcher.CanContinue())

@@v8::Local<v8::Value> WorkerContextExecutionProxy::runScript(v8::Handle<v8::Scrip
227227 // Compute the source string and prevent against infinite recursion.
228228 if (m_recursion >= kMaxRecursionDepth) {
229229 v8::Local<v8::String> code = v8ExternalString("throw RangeError('Recursion too deep')");
230  script = V8Proxy::compileScript(code, "", 0);
 230 script = V8Proxy::compileScript(code, "", TextPosition0::minimumPosition());
231231 }
232232
233233 if (V8Proxy::handleOutOfMemory())

WebCore/bindings/v8/WorkerContextExecutionProxy.h

3636
3737#include "ScriptValue.h"
3838#include <v8.h>
 39#include <wtf/TextPosition.h>
3940#include <wtf/OwnPtr.h>
4041#include <wtf/Vector.h>
4142

@@namespace WebCore {
6667 void trackEvent(Event*);
6768
6869 // Evaluate a script file in the current execution environment.
69  ScriptValue evaluate(const String& script, const String& fileName, int baseLine, WorkerContextExecutionState*);
 70 ScriptValue evaluate(const String& script, const String& fileName, const TextPosition0& scriptStartPosition, WorkerContextExecutionState*);
7071
7172 // Returns a local handle of the context.
7273 v8::Local<v8::Context> context() { return v8::Local<v8::Context>::New(m_context); }

WebCore/bindings/v8/WorkerScriptController.cpp

@@ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode,
7575 }
7676
7777 WorkerContextExecutionState state;
78  ScriptValue result = m_proxy->evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startLine() - 1, &state);
 78 ScriptValue result = m_proxy->evaluate(sourceCode.source(), sourceCode.url().string(), WTF::toZeroBasedTextPosition(sourceCode.startPosition()), &state);
7979 if (state.hadException) {
8080 if (exception)
8181 *exception = state.exception;

WebCore/dom/PendingScript.cpp

@@PendingScript::~PendingScript()
4040PassRefPtr<Element> PendingScript::releaseElementAndClear()
4141{
4242 setCachedScript(0);
43  m_startingLineNumber = 0;
 43 m_startingPosition = TextPosition1::belowRangePosition();
4444 m_watchingForLoad = false;
4545 return m_element.release();
4646}

WebCore/dom/PendingScript.h

2828
2929#include "CachedResourceClient.h"
3030#include "CachedResourceHandle.h"
 31#include <wtf/TextPosition.h>
3132#include <wtf/PassRefPtr.h>
3233
3334namespace WebCore {

@@class Element;
4344class PendingScript : public CachedResourceClient {
4445public:
4546 PendingScript()
46  : m_startingLineNumber(0)
 47 : m_startingPosition(TextPosition1::belowRangePosition())
4748 , m_watchingForLoad(false)
4849 {
4950 }
5051
5152 PendingScript(const PendingScript& other)
5253 : CachedResourceClient(other)
53  , m_startingLineNumber(other.m_startingLineNumber)
 54 , m_startingPosition(other.m_startingPosition)
5455 , m_watchingForLoad(other.m_watchingForLoad)
5556 , m_element(other.m_element)
5657 {

@@public:
6465 if (this == &other)
6566 return *this;
6667
67  m_startingLineNumber = other.m_startingLineNumber;
 68 m_startingPosition = other.m_startingPosition;
6869 m_watchingForLoad = other.m_watchingForLoad;
6970 m_element = other.m_element;
7071 setCachedScript(other.cachedScript());

@@public:
7475
7576 // FIXME: No setter means this is never set to anything other than 0.
7677 // This is either unnecessary or incorrect.
77  int startingLineNumber() const { return m_startingLineNumber; }
 78 TextPosition1 startingPosition() const { return m_startingPosition; }
7879
7980 bool watchingForLoad() const { return m_watchingForLoad; }
8081 void setWatchingForLoad(bool b) { m_watchingForLoad = b; }

@@public:
8990 virtual void notifyFinished(CachedResource*);
9091
9192private:
92  int m_startingLineNumber; // Only used for inline script tags.
 93 TextPosition1 m_startingPosition; // Only used for inline script tags.
9394 bool m_watchingForLoad;
9495 RefPtr<Element> m_element;
9596 CachedResourceHandle<CachedScript> m_cachedScript;

WebCore/dom/ScriptableDocumentParser.h

2727#define ScriptableDocumentParser_h
2828
2929#include "DecodedDataDocumentParser.h"
 30#include <wtf/TextPosition.h>
3031
3132namespace WebCore {
3233
33 class SegmentedString;
3434class XSSAuditor;
3535
3636class ScriptableDocumentParser : public DecodedDataDocumentParser {

@@public:
4747
4848 // These are used to expose the current line/column to the scripting system.
4949 virtual int lineNumber() const = 0;
50  virtual int columnNumber() const = 0;
 50 virtual TextPosition0 textPosition() const = 0;
5151
5252 XSSAuditor* xssAuditor() const { return m_xssAuditor; }
5353 void setXSSAuditor(XSSAuditor* auditor) { m_xssAuditor = auditor; }

WebCore/dom/XMLDocumentParser.h

@@namespace WebCore {
102102 // WMLErrorHandling uses these functions.
103103 virtual bool wellFormed() const { return !m_sawError; }
104104 virtual int lineNumber() const;
105  virtual int columnNumber() const;
 105 TextPosition0 textPosition() const;
106106
107107 static bool supportsXMLVersion(const String&);
108108

@@namespace WebCore {
129129
130130 bool appendFragmentSource(const String&);
131131
 132 int columnNumber() const;
 133
132134#if USE(QXMLSTREAM)
133135private:
134136 void parse();

@@public:
208210
209211 CachedResourceHandle<CachedScript> m_pendingScript;
210212 RefPtr<Element> m_scriptElement;
211  int m_scriptStartLine;
 213 TextPosition1 m_scriptStartPosition;
212214
213215 bool m_parsingFragment;
214216 AtomicString m_defaultNamespaceURI;

WebCore/dom/XMLDocumentParserLibxml2.cpp

@@XMLDocumentParser::XMLDocumentParser(Document* document, FrameView* frameView)
558558 , m_lastErrorLine(0)
559559 , m_lastErrorColumn(0)
560560 , m_pendingScript(0)
561  , m_scriptStartLine(0)
 561 , m_scriptStartPosition(TextPosition1::belowRangePosition())
562562 , m_parsingFragment(false)
563563 , m_scriptingPermission(FragmentScriptingAllowed)
564564{

@@XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parent
585585 , m_lastErrorLine(0)
586586 , m_lastErrorColumn(0)
587587 , m_pendingScript(0)
588  , m_scriptStartLine(0)
 588 , m_scriptStartPosition(TextPosition1::belowRangePosition())
589589 , m_parsingFragment(true)
590590 , m_scriptingPermission(scriptingPermission)
591591{

@@void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha
817817
818818 ScriptElement* scriptElement = toScriptElement(newElement.get());
819819 if (scriptElement)
820  m_scriptStartLine = lineNumber();
 820 m_scriptStartPosition = toOneBasedTextPosition(textPosition());
821821
822822 m_currentNode->deprecatedParserAddChild(newElement.get());
823823

@@void XMLDocumentParser::endElementNs()
903903 } else
904904 m_scriptElement = 0;
905905 } else
906  m_view->frame()->script()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartLine));
 906 m_view->frame()->script()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartPosition));
907907
908908 // JavaScript may have detached the parser
909909 if (isDetached())

@@void* xmlDocPtrForString(CachedResourceLoader* cachedResourceLoader, const Strin
13691369
13701370int XMLDocumentParser::lineNumber() const
13711371{
1372  return context() ? context()->input->line : 1;
 1372 // FIXME: the implementation probably returns 1-based int, but method should return 0-based.
 1373 // New "- 1" fixes this. Is it correct?
 1374 return (context() ? context()->input->line : 1) - 1;
13731375}
13741376
13751377int XMLDocumentParser::columnNumber() const
13761378{
1377  return context() ? context()->input->col : 1;
 1379 // FIXME: the implementation probably returns 1-based int, but method should return 0-based.
 1380 // New "- 1" fixes this. Is it correct?
 1381 return (context() ? context()->input->col : 1) - 1;
 1382}
 1383
 1384TextPosition0 XMLDocumentParser::textPosition() const
 1385{
 1386 xmlParserCtxtPtr context = this->context();
 1387 if (context) {
 1388 return TextPosition0(WTF::OneBasedNumber::fromOneBasedInt(context->input->line).convertToZeroBased(),
 1389 WTF::OneBasedNumber::fromOneBasedInt(context->input->col).convertToZeroBased(), 0);
 1390 }
 1391 return TextPosition0::minimumPosition();
13781392}
13791393
13801394void XMLDocumentParser::stopParsing()

WebCore/dom/XMLDocumentParserQt.cpp

@@XMLDocumentParser::XMLDocumentParser(Document* document, FrameView* frameView)
103103 , m_lastErrorLine(0)
104104 , m_lastErrorColumn(0)
105105 , m_pendingScript(0)
106  , m_scriptStartLine(0)
 106 , m_scriptStartPosition(TextPosition1::belowRangePosition())
107107 , m_parsingFragment(false)
108108 , m_scriptingPermission(FragmentScriptingAllowed)
109109{

@@XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parent
130130 , m_lastErrorLine(0)
131131 , m_lastErrorColumn(0)
132132 , m_pendingScript(0)
133  , m_scriptStartLine(0)
 133 , m_scriptStartPosition(TextPosition1::belowRangePosition())
134134 , m_parsingFragment(true)
135135 , m_scriptingPermission(permission)
136136{

@@int XMLDocumentParser::columnNumber() const
232232 return m_stream.columnNumber();
233233}
234234
 235TextPosition0 XMLDocumentParser::textPosition()
 236{
 237 return TextPosition0(WTF::ZeroBasedNumber(lineNumber()), WTF::ZeroBasedNumber(columnNumber()), 0);
 238}
 239
235240void XMLDocumentParser::stopParsing()
236241{
237242 ScriptableDocumentParser::stopParsing();

@@void XMLDocumentParser::parseStartElement()
516521
517522 ScriptElement* scriptElement = toScriptElement(newElement.get());
518523 if (scriptElement)
519  m_scriptStartLine = lineNumber();
 524 m_scriptStartPosition = WTF::toOneBasedTextPosition(textPosition());
520525
521526 m_currentNode->deprecatedParserAddChild(newElement.get());
522527

@@void XMLDocumentParser::parseEndElement()
588593 } else
589594 m_scriptElement = 0;
590595 } else
591  m_view->frame()->script()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartLine));
 596 m_view->frame()->script()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartPosition));
592597 }
593598 m_requestingScript = false;
594599 popCurrentNode();

@@void XMLDocumentParser::parseDtd()
709714
710715}
711716}
712 

WebCore/html/parser/HTMLDocumentParser.cpp

@@bool HTMLDocumentParser::runScriptsForPausedTreeBuilder()
194194{
195195 ASSERT(m_treeBuilder->isPaused());
196196
197  int scriptStartLine = 0;
198  RefPtr<Element> scriptElement = m_treeBuilder->takeScriptToProcess(scriptStartLine);
 197 TextPosition1 scriptStartPosition = TextPosition1::belowRangePosition();
 198 RefPtr<Element> scriptElement = m_treeBuilder->takeScriptToProcess(scriptStartPosition);
199199 // We will not have a scriptRunner when parsing a DocumentFragment.
200200 if (!m_scriptRunner)
201201 return true;
202  return m_scriptRunner->execute(scriptElement.release(), scriptStartLine);
 202 return m_scriptRunner->execute(scriptElement.release(), scriptStartPosition);
203203}
204204
205205void HTMLDocumentParser::pumpTokenizer(SynchronousMode mode)

@@int HTMLDocumentParser::lineNumber() const
415415 return m_tokenizer->lineNumber();
416416}
417417
418 int HTMLDocumentParser::columnNumber() const
 418TextPosition0 HTMLDocumentParser::textPosition() const
419419{
420  return m_tokenizer->columnNumber();
 420 int lineZeroBased = m_tokenizer->lineNumber();
 421 int columnOneBased = m_tokenizer->columnNumber();
 422 int generation = m_writeNestingLevel;
 423
 424 return TextPosition0(WTF::ZeroBasedNumber::fromZeroBasedInt(lineZeroBased),
 425 WTF::OneBasedNumber::fromOneBasedInt(columnOneBased).convertToZeroBased(), generation);
421426}
422427
423428bool HTMLDocumentParser::isWaitingForScripts() const

WebCore/html/parser/HTMLDocumentParser.h

@@private:
9292 virtual bool isExecutingScript() const;
9393 virtual void executeScriptsWaitingForStylesheets();
9494 virtual int lineNumber() const;
95  virtual int columnNumber() const;
 95 virtual TextPosition0 textPosition() const;
9696
9797 // HTMLScriptRunnerHost
9898 virtual void watchForLoad(CachedResource*);

WebCore/html/parser/HTMLScriptRunner.cpp

@@ScriptSourceCode HTMLScriptRunner::sourceFromPendingScript(const PendingScript&
9898 return ScriptSourceCode(script.cachedScript());
9999 }
100100 errorOccurred = false;
101  return ScriptSourceCode(script.element()->textContent(), documentURLForScriptExecution(m_document), script.startingLineNumber());
 101 return ScriptSourceCode(script.element()->textContent(), documentURLForScriptExecution(m_document), script.startingPosition());
102102}
103103
104104bool HTMLScriptRunner::isPendingScriptReady(const PendingScript& script)

@@void HTMLScriptRunner::stopWatchingForLoad(PendingScript& pendingScript)
170170
171171// This function should match 10.2.5.11 "An end tag whose tag name is 'script'"
172172// Script handling lives outside the tree builder to keep the each class simple.
173 bool HTMLScriptRunner::execute(PassRefPtr<Element> scriptElement, int startLine)
 173bool HTMLScriptRunner::execute(PassRefPtr<Element> scriptElement, const TextPosition1& scriptStartPosition)
174174{
175175 ASSERT(scriptElement);
176176 // FIXME: If scripting is disabled, always just return true;
177177
178178 // Try to execute the script given to us.
179  runScript(scriptElement.get(), startLine);
 179 runScript(scriptElement.get(), scriptStartPosition);
180180
181181 if (haveParsingBlockingScript()) {
182182 if (m_scriptNestingLevel)

@@bool HTMLScriptRunner::requestPendingScript(PendingScript& pendingScript, Elemen
288288
289289// This method is meant to match the HTML5 definition of "running a script"
290290// http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#running-a-script
291 void HTMLScriptRunner::runScript(Element* script, int startingLineNumber)
 291void HTMLScriptRunner::runScript(Element* script, const TextPosition1& scriptStartPosition)
292292{
293293 ASSERT(m_document);
294294 ASSERT(!haveParsingBlockingScript());

@@void HTMLScriptRunner::runScript(Element* script, int startingLineNumber)
315315 // See https://bugs.webkit.org/show_bug.cgi?id=40047
316316 // ASSERT(document()->haveStylesheetsLoaded());
317317 ASSERT(isExecutingScript());
318  ScriptSourceCode sourceCode(script->textContent(), documentURLForScriptExecution(m_document), startingLineNumber);
 318 ScriptSourceCode sourceCode(script->textContent(), documentURLForScriptExecution(m_document), scriptStartPosition);
319319 executeScript(sourceCode);
320320 }
321321 }

WebCore/html/parser/HTMLScriptRunner.h

2828
2929#include "PendingScript.h"
3030#include <wtf/Deque.h>
 31#include <wtf/TextPosition.h>
3132#include <wtf/Noncopyable.h>
3233#include <wtf/PassRefPtr.h>
3334

@@public:
5253 void detach();
5354
5455 // Processes the passed in script and any pending scripts if possible.
55  bool execute(PassRefPtr<Element> scriptToProcess, int scriptStartLine);
 56 bool execute(PassRefPtr<Element> scriptToProcess, const TextPosition1& scriptStartPosition);
5657
5758 bool executeScriptsWaitingForLoad(CachedResource*);
5859 bool hasScriptsWaitingForStylesheets() const { return m_hasScriptsWaitingForStylesheets; }

@@private:
7677 void requestDeferredScript(Element*);
7778 bool requestPendingScript(PendingScript&, Element*) const;
7879
79  void runScript(Element*, int startingLineNumber);
 80 void runScript(Element*, const TextPosition1& scriptStartPosition);
8081
8182 // Helpers for dealing with HTMLScriptRunnerHost
8283 void watchForLoad(PendingScript&);

WebCore/html/parser/HTMLTreeBuilder.cpp

4949#include "XLinkNames.h"
5050#include "XMLNSNames.h"
5151#include "XMLNames.h"
 52#include <wtf/Assertions.h>
5253
5354namespace WebCore {
5455
5556using namespace HTMLNames;
5657
5758static const int uninitializedLineNumberValue = -1;
 59static const TextPosition0 uninitializedPositionValue0 = TextPosition0::belowRangePosition();
 60static const TextPosition1 uninitializedPositionValue1(WTF::OneBasedNumber::fromOneBasedInt(-1), WTF::OneBasedNumber::s_base, -1);
5861
5962namespace {
6063

@@HTMLTreeBuilder::HTMLTreeBuilder(HTMLTokenizer* tokenizer, HTMLDocument* documen
333336 , m_originalInsertionMode(InitialMode)
334337 , m_secondaryInsertionMode(InitialMode)
335338 , m_tokenizer(tokenizer)
336  , m_scriptToProcessStartLine(uninitializedLineNumberValue)
337  , m_lastScriptElementStartLine(uninitializedLineNumberValue)
 339 , m_scriptToProcessStartPosition(uninitializedPositionValue1)
 340 , m_lastScriptElementStartPosition(uninitializedPositionValue0)
338341 , m_usePreHTML5ParserQuirks(usePreHTML5ParserQuirks)
339342{
340343}

@@HTMLTreeBuilder::HTMLTreeBuilder(HTMLTokenizer* tokenizer, DocumentFragment* fra
352355 , m_originalInsertionMode(InitialMode)
353356 , m_secondaryInsertionMode(InitialMode)
354357 , m_tokenizer(tokenizer)
355  , m_scriptToProcessStartLine(uninitializedLineNumberValue)
356  , m_lastScriptElementStartLine(uninitializedLineNumberValue)
 358 , m_scriptToProcessStartPosition(uninitializedPositionValue1)
 359 , m_lastScriptElementStartPosition(uninitializedPositionValue0)
357360 , m_usePreHTML5ParserQuirks(usePreHTML5ParserQuirks)
358361{
359362 if (contextElement) {

@@HTMLTreeBuilder::FragmentParsingContext::~FragmentParsingContext()
415418{
416419}
417420
418 PassRefPtr<Element> HTMLTreeBuilder::takeScriptToProcess(int& scriptStartLine)
 421PassRefPtr<Element> HTMLTreeBuilder::takeScriptToProcess(TextPosition1& scriptStartPosition)
419422{
420423 // Unpause ourselves, callers may pause us again when processing the script.
421424 // The HTML5 spec is written as though scripts are executed inside the tree
422425 // builder. We pause the parser to exit the tree builder, and then resume
423426 // before running scripts.
424427 m_isPaused = false;
425  scriptStartLine = m_scriptToProcessStartLine;
426  m_scriptToProcessStartLine = uninitializedLineNumberValue;
 428 scriptStartPosition = m_scriptToProcessStartPosition;
 429 m_scriptToProcessStartPosition = uninitializedPositionValue1;
427430 return m_scriptToProcess.release();
428431}
429432

@@void HTMLTreeBuilder::processEndTag(AtomicHTMLToken& token)
22012204 m_isPaused = true;
22022205 ASSERT(m_tree.currentElement()->hasTagName(scriptTag));
22032206 m_scriptToProcess = m_tree.currentElement();
2204  m_scriptToProcessStartLine = m_lastScriptElementStartLine + 1;
 2207 m_scriptToProcessStartPosition = WTF::toOneBasedTextPosition(m_lastScriptElementStartPosition);
22052208 m_tree.openElements()->pop();
22062209 if (isParsingFragment() && m_fragmentContext.scriptingPermission() == FragmentScriptingNotAllowed)
22072210 m_scriptToProcess->removeAllChildren();

@@void HTMLTreeBuilder::processScriptStartTag(AtomicHTMLToken& token)
27502753 m_tree.insertScriptElement(token);
27512754 m_tokenizer->setState(HTMLTokenizer::ScriptDataState);
27522755 m_originalInsertionMode = m_insertionMode;
2753  m_lastScriptElementStartLine = m_tokenizer->lineNumber();
 2756
 2757 TextPosition0 position = TextPosition0(WTF::ZeroBasedNumber::fromZeroBasedInt(m_tokenizer->lineNumber()), WTF::ZeroBasedNumber::s_base, 0);
 2758 m_lastScriptElementStartPosition = position;
 2759
27542760 setInsertionMode(TextMode);
27552761}
27562762

WebCore/html/parser/HTMLTreeBuilder.h

3232#include "HTMLElementStack.h"
3333#include "HTMLFormattingElementList.h"
3434#include "HTMLTokenizer.h"
 35#include <wtf/TextPosition.h>
3536#include <wtf/Noncopyable.h>
3637#include <wtf/OwnPtr.h>
3738#include <wtf/PassOwnPtr.h>

@@public:
7172 void constructTreeFromAtomicToken(AtomicHTMLToken&);
7273
7374 // Must be called when parser is paused before calling the parser again.
74  PassRefPtr<Element> takeScriptToProcess(int& scriptStartLine);
 75 PassRefPtr<Element> takeScriptToProcess(TextPosition1& scriptStartPosition);
7576
7677 // Done, close any open tags, etc.
7778 void finished();

@@private:
246247 HTMLTokenizer* m_tokenizer;
247248
248249 RefPtr<Element> m_scriptToProcess; // <script> tag which needs processing before resuming the parser.
249  int m_scriptToProcessStartLine; // Starting line number of the script tag needing processing.
 250 TextPosition1 m_scriptToProcessStartPosition; // Starting line number of the script tag needing processing.
250251
251252 // FIXME: We probably want to remove this member. Originally, it was
252253 // created to service the legacy tree builder, but it seems to be used for
253254 // some other things now.
254  int m_lastScriptElementStartLine;
255 
 255 TextPosition0 m_lastScriptElementStartPosition;
256256 bool m_usePreHTML5ParserQuirks;
257257};
258258

WebKit/chromium/ChangeLog

 12010-09-23 Peter Rybin <peter.rybin@gmail.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 HTML parser should provide script column position within HTML document to JavaScript engine
 6 https://bugs.webkit.org/show_bug.cgi?id=45271
 7
 8 Replaces script line number with TextPosition structure.
 9
 10 * src/WebFrameImpl.cpp:
 11 (WebKit::WebFrameImpl::executeScript):
 12 (WebKit::WebFrameImpl::executeScriptInIsolatedWorld):
 13 (WebKit::WebFrameImpl::executeScriptAndReturnValue):
 14
1152010-09-23 Tony Chang <tony@chromium.org>
216
317 Reviewed by David Levin.

WebKit/chromium/src/WebFrameImpl.cpp

@@void WebFrameImpl::bindToWindowObject(const WebString& name, NPObject* object)
741741
742742void WebFrameImpl::executeScript(const WebScriptSource& source)
743743{
 744 TextPosition1 position(WTF::OneBasedNumber::fromOneBasedInt(source.startLine), WTF::OneBasedNumber::s_base, 0);
744745 m_frame->script()->executeScript(
745  ScriptSourceCode(source.code, source.url, source.startLine));
 746 ScriptSourceCode(source.code, source.url, position));
746747}
747748
748749void WebFrameImpl::executeScriptInIsolatedWorld(

@@void WebFrameImpl::executeScriptInIsolatedWorld(
752753 Vector<ScriptSourceCode> sources;
753754
754755 for (unsigned i = 0; i < numSources; ++i) {
 756 TextPosition1 position(WTF::OneBasedNumber::fromOneBasedInt(sourcesIn[i].startLine), WTF::OneBasedNumber::s_base, 0);
755757 sources.append(ScriptSourceCode(
756  sourcesIn[i].code, sourcesIn[i].url, sourcesIn[i].startLine));
 758 sourcesIn[i].code, sourcesIn[i].url, position));
757759 }
758760
759761 m_frame->script()->evaluateInIsolatedWorld(worldId, sources, extensionGroup);

@@void WebFrameImpl::collectGarbage()
805807v8::Handle<v8::Value> WebFrameImpl::executeScriptAndReturnValue(
806808 const WebScriptSource& source)
807809{
 810 TextPosition1 position(WTF::OneBasedNumber::fromOneBasedInt(source.startLine), WTF::OneBasedNumber::s_base, 0);
808811 return m_frame->script()->executeScript(
809  ScriptSourceCode(source.code, source.url, source.startLine)).v8Value();
 812 ScriptSourceCode(source.code, source.url, position)).v8Value();
810813}
811814
812815// Returns the V8 context for this frame, or an empty handle if there is none.