Title: [209632] trunk/Source
Revision
209632
Author
gga...@apple.com
Date
2016-12-09 14:59:52 -0800 (Fri, 09 Dec 2016)

Log Message

Deploy OrdinalNumber in JSC::SourceCode
https://bugs.webkit.org/show_bug.cgi?id=165687

Reviewed by Michael Saboff.

Source/_javascript_Core:

We have a lot of confusion between 1-based and 0-based counting in line
and column numbers. Let's use OrdinalNumber to clear up the confusion.

* bytecode/UnlinkedFunctionExecutable.cpp:
(JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
(JSC::UnlinkedFunctionExecutable::link):
* bytecompiler/BytecodeGenerator.h:
(JSC::BytecodeGenerator::emitExpressionInfo):
* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::functionDetails):
* parser/Lexer.cpp:
(JSC::Lexer<T>::setCode):
* parser/Parser.cpp:
(JSC::Parser<LexerType>::Parser):
* parser/Parser.h:
(JSC::Parser<LexerType>::parse):
* parser/SourceCode.h:
(JSC::SourceCode::SourceCode):
(JSC::SourceCode::firstLine):
(JSC::SourceCode::startColumn):
* runtime/CodeCache.cpp:
(JSC::CodeCache::getUnlinkedGlobalCodeBlock):
* runtime/ScriptExecutable.h:
(JSC::ScriptExecutable::firstLine):
(JSC::ScriptExecutable::startColumn):
* tools/CodeProfile.h:
(JSC::CodeProfile::CodeProfile):

Source/WebCore:

Updated for interface changes.

* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::evaluateModule):
* bindings/js/ScriptSourceCode.h:
(WebCore::ScriptSourceCode::startLine):

Source/WTF:

* wtf/text/OrdinalNumber.h:
(WTF::OrdinalNumber::operator>): Added a >.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (209631 => 209632)


--- trunk/Source/_javascript_Core/ChangeLog	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-12-09 22:59:52 UTC (rev 209632)
@@ -1,3 +1,38 @@
+2016-12-09  Geoffrey Garen  <gga...@apple.com>
+
+        Deploy OrdinalNumber in JSC::SourceCode
+        https://bugs.webkit.org/show_bug.cgi?id=165687
+
+        Reviewed by Michael Saboff.
+
+        We have a lot of confusion between 1-based and 0-based counting in line
+        and column numbers. Let's use OrdinalNumber to clear up the confusion.
+
+        * bytecode/UnlinkedFunctionExecutable.cpp:
+        (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
+        (JSC::UnlinkedFunctionExecutable::link):
+        * bytecompiler/BytecodeGenerator.h:
+        (JSC::BytecodeGenerator::emitExpressionInfo):
+        * inspector/JSInjectedScriptHost.cpp:
+        (Inspector::JSInjectedScriptHost::functionDetails):
+        * parser/Lexer.cpp:
+        (JSC::Lexer<T>::setCode):
+        * parser/Parser.cpp:
+        (JSC::Parser<LexerType>::Parser):
+        * parser/Parser.h:
+        (JSC::Parser<LexerType>::parse):
+        * parser/SourceCode.h:
+        (JSC::SourceCode::SourceCode):
+        (JSC::SourceCode::firstLine):
+        (JSC::SourceCode::startColumn):
+        * runtime/CodeCache.cpp:
+        (JSC::CodeCache::getUnlinkedGlobalCodeBlock):
+        * runtime/ScriptExecutable.h:
+        (JSC::ScriptExecutable::firstLine):
+        (JSC::ScriptExecutable::startColumn):
+        * tools/CodeProfile.h:
+        (JSC::CodeProfile::CodeProfile):
+
 2016-12-09  Saam Barati  <sbar...@apple.com>
 
         WebAssembly JS API: implement importing and defining Memory

Modified: trunk/Source/_javascript_Core/bytecode/UnlinkedFunctionExecutable.cpp (209631 => 209632)


--- trunk/Source/_javascript_Core/bytecode/UnlinkedFunctionExecutable.cpp	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/bytecode/UnlinkedFunctionExecutable.cpp	2016-12-09 22:59:52 UTC (rev 209632)
@@ -77,7 +77,7 @@
 
 UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM* vm, Structure* structure, const SourceCode& parentSource, SourceCode&& parentSourceOverride, FunctionMetadataNode* node, UnlinkedFunctionKind kind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, VariableEnvironment& parentScopeTDZVariables, DerivedContextType derivedContextType)
     : Base(*vm, structure)
-    , m_firstLineOffset(node->firstLine() - parentSource.firstLine())
+    , m_firstLineOffset(node->firstLine() - parentSource.firstLine().oneBasedInt())
     , m_lineCount(node->lastLine() - node->firstLine())
     , m_unlinkedFunctionNameStart(node->functionNameStart() - parentSource.startOffset())
     , m_unlinkedBodyStartColumn(node->startColumn())
@@ -134,11 +134,11 @@
 FunctionExecutable* UnlinkedFunctionExecutable::link(VM& vm, const SourceCode& passedParentSource, std::optional<int> overrideLineNumber, Intrinsic intrinsic)
 {
     const SourceCode& parentSource = m_parentSourceOverride.isNull() ? passedParentSource : m_parentSourceOverride;
-    unsigned firstLine = parentSource.firstLine() + m_firstLineOffset;
+    unsigned firstLine = parentSource.firstLine().oneBasedInt() + m_firstLineOffset;
     unsigned startOffset = parentSource.startOffset() + m_startOffset;
     unsigned lineCount = m_lineCount;
 
-    unsigned startColumn = linkedStartColumn(parentSource.startColumn());
+    unsigned startColumn = linkedStartColumn(parentSource.startColumn().oneBasedInt());
     unsigned endColumn = linkedEndColumn(startColumn);
 
     SourceCode source(parentSource.provider(), startOffset, startOffset + m_sourceLength, firstLine, startColumn);

Modified: trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h (209631 => 209632)


--- trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/bytecompiler/BytecodeGenerator.h	2016-12-09 22:59:52 UTC (rev 209632)
@@ -445,7 +445,7 @@
             ASSERT(divotEnd.offset >= divot.offset);
 
             int sourceOffset = m_scopeNode->source().startOffset();
-            unsigned firstLine = m_scopeNode->source().firstLine();
+            unsigned firstLine = m_scopeNode->source().firstLine().oneBasedInt();
 
             int divotOffset = divot.offset - sourceOffset;
             int startOffset = divot.offset - divotStart.offset;

Modified: trunk/Source/_javascript_Core/inspector/JSInjectedScriptHost.cpp (209631 => 209632)


--- trunk/Source/_javascript_Core/inspector/JSInjectedScriptHost.cpp	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/inspector/JSInjectedScriptHost.cpp	2016-12-09 22:59:52 UTC (rev 209632)
@@ -215,10 +215,10 @@
         return jsUndefined();
 
     // In the inspector protocol all positions are 0-based while in SourceCode they are 1-based
-    int lineNumber = sourceCode->firstLine();
+    int lineNumber = sourceCode->firstLine().oneBasedInt();
     if (lineNumber)
         lineNumber -= 1;
-    int columnNumber = sourceCode->startColumn();
+    int columnNumber = sourceCode->startColumn().oneBasedInt();
     if (columnNumber)
         columnNumber -= 1;
 

Modified: trunk/Source/_javascript_Core/parser/Lexer.cpp (209631 => 209632)


--- trunk/Source/_javascript_Core/parser/Lexer.cpp	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/parser/Lexer.cpp	2016-12-09 22:59:52 UTC (rev 209632)
@@ -541,7 +541,7 @@
 {
     m_arena = &arena->identifierArena();
     
-    m_lineNumber = source.firstLine();
+    m_lineNumber = source.firstLine().oneBasedInt();
     m_lastToken = -1;
     
     StringView sourceString = source.provider()->source();

Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (209631 => 209632)


--- trunk/Source/_javascript_Core/parser/Parser.cpp	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp	2016-12-09 22:59:52 UTC (rev 209632)
@@ -207,7 +207,7 @@
 {
     m_lexer = std::make_unique<LexerType>(vm, builtinMode, scriptMode);
     m_lexer->setCode(source, &m_parserArena);
-    m_token.m_location.line = source.firstLine();
+    m_token.m_location.line = source.firstLine().oneBasedInt();
     m_token.m_location.startOffset = source.startOffset();
     m_token.m_location.endOffset = source.startOffset();
     m_token.m_location.lineStartOffset = source.startOffset();

Modified: trunk/Source/_javascript_Core/parser/Parser.h (209631 => 209632)


--- trunk/Source/_javascript_Core/parser/Parser.h	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/parser/Parser.h	2016-12-09 22:59:52 UTC (rev 209632)
@@ -1790,8 +1790,8 @@
     errMsg = String();
 
     JSTokenLocation startLocation(tokenLocation());
-    ASSERT(m_source->startColumn() > 0);
-    unsigned startColumn = m_source->startColumn() - 1;
+    ASSERT(m_source->startColumn() > OrdinalNumber::beforeFirst());
+    unsigned startColumn = m_source->startColumn().zeroBasedInt();
 
     String parseError = parseInner(calleeName, parseMode);
 
@@ -1830,7 +1830,7 @@
                                     currentScope()->innerArrowFunctionFeatures(),
                                     m_numConstants,
                                     WTFMove(m_moduleScopeData));
-        result->setLoc(m_source->firstLine(), m_lexer->lineNumber(), m_lexer->currentOffset(), m_lexer->currentLineStartOffset());
+        result->setLoc(m_source->firstLine().oneBasedInt(), m_lexer->lineNumber(), m_lexer->currentOffset(), m_lexer->currentLineStartOffset());
         result->setEndOffset(m_lexer->currentOffset());
 
         if (!isFunctionParseMode(parseMode)) {

Modified: trunk/Source/_javascript_Core/parser/SourceCode.h (209631 => 209632)


--- trunk/Source/_javascript_Core/parser/SourceCode.h	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/parser/SourceCode.h	2016-12-09 22:59:52 UTC (rev 209632)
@@ -36,34 +36,32 @@
     public:
         SourceCode()
             : UnlinkedSourceCode()
-            , m_firstLine(0)
-            , m_startColumn(0)
+            , m_firstLine(OrdinalNumber::beforeFirst())
+            , m_startColumn(OrdinalNumber::beforeFirst())
         {
         }
 
         SourceCode(PassRefPtr<SourceProvider> provider)
             : UnlinkedSourceCode(provider)
-            , m_firstLine(1)
-            , m_startColumn(1)
         {
         }
 
         SourceCode(PassRefPtr<SourceProvider> provider, int firstLine, int startColumn)
             : UnlinkedSourceCode(provider)
-            , m_firstLine(std::max(firstLine, 1))
-            , m_startColumn(std::max(startColumn, 1))
+            , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1)))
+            , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1)))
         {
         }
 
         SourceCode(PassRefPtr<SourceProvider> provider, int startOffset, int endOffset, int firstLine, int startColumn)
             : UnlinkedSourceCode(provider, startOffset, endOffset)
-            , m_firstLine(std::max(firstLine, 1))
-            , m_startColumn(std::max(startColumn, 1))
+            , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1)))
+            , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1)))
         {
         }
 
-        int firstLine() const { return m_firstLine; }
-        int startColumn() const { return m_startColumn; }
+        OrdinalNumber firstLine() const { return m_firstLine; }
+        OrdinalNumber startColumn() const { return m_startColumn; }
 
         intptr_t providerID() const
         {
@@ -77,8 +75,8 @@
         SourceCode subExpression(unsigned openBrace, unsigned closeBrace, int firstLine, int startColumn);
 
     private:
-        int m_firstLine;
-        int m_startColumn;
+        OrdinalNumber m_firstLine;
+        OrdinalNumber m_startColumn;
     };
 
     inline SourceCode makeSource(const String& source, const String& url = "" const TextPosition& startPosition = TextPosition(), SourceProviderSourceType sourceType = SourceProviderSourceType::Program)

Modified: trunk/Source/_javascript_Core/runtime/CodeCache.cpp (209631 => 209632)


--- trunk/Source/_javascript_Core/runtime/CodeCache.cpp	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/runtime/CodeCache.cpp	2016-12-09 22:59:52 UTC (rev 209632)
@@ -62,10 +62,10 @@
     if (cache && Options::useCodeCache()) {
         UnlinkedCodeBlockType* unlinkedCodeBlock = jsCast<UnlinkedCodeBlockType*>(cache->cell.get());
         unsigned lineCount = unlinkedCodeBlock->lineCount();
-        unsigned startColumn = unlinkedCodeBlock->startColumn() + source.startColumn();
+        unsigned startColumn = unlinkedCodeBlock->startColumn() + source.startColumn().oneBasedInt();
         bool endColumnIsOnStartLine = !lineCount;
         unsigned endColumn = unlinkedCodeBlock->endColumn() + (endColumnIsOnStartLine ? startColumn : 1);
-        executable->recordParse(unlinkedCodeBlock->codeFeatures(), unlinkedCodeBlock->hasCapturedVariables(), source.firstLine() + lineCount, endColumn);
+        executable->recordParse(unlinkedCodeBlock->codeFeatures(), unlinkedCodeBlock->hasCapturedVariables(), source.firstLine().oneBasedInt() + lineCount, endColumn);
         source.provider()->setSourceURLDirective(unlinkedCodeBlock->sourceURLDirective());
         source.provider()->setSourceMappingURLDirective(unlinkedCodeBlock->sourceMappingURLDirective());
         return unlinkedCodeBlock;

Modified: trunk/Source/_javascript_Core/runtime/ScriptExecutable.h (209631 => 209632)


--- trunk/Source/_javascript_Core/runtime/ScriptExecutable.h	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/runtime/ScriptExecutable.h	2016-12-09 22:59:52 UTC (rev 209632)
@@ -41,12 +41,12 @@
     const SourceCode& source() const { return m_source; }
     intptr_t sourceID() const { return m_source.providerID(); }
     const String& sourceURL() const { return m_source.provider()->url(); }
-    int firstLine() const { return m_source.firstLine(); }
+    int firstLine() const { return m_source.firstLine().oneBasedInt(); }
     void setOverrideLineNumber(int overrideLineNumber) { m_overrideLineNumber = overrideLineNumber; }
     bool hasOverrideLineNumber() const { return m_overrideLineNumber != -1; }
     int overrideLineNumber() const { return m_overrideLineNumber; }
     int lastLine() const { return m_lastLine; }
-    unsigned startColumn() const { return m_source.startColumn(); }
+    unsigned startColumn() const { return m_source.startColumn().oneBasedInt(); }
     unsigned endColumn() const { return m_endColumn; }
     unsigned typeProfilingStartOffset() const { return m_typeProfilingStartOffset; }
     unsigned typeProfilingEndOffset() const { return m_typeProfilingEndOffset; }

Modified: trunk/Source/_javascript_Core/tools/CodeProfile.h (209631 => 209632)


--- trunk/Source/_javascript_Core/tools/CodeProfile.h	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/_javascript_Core/tools/CodeProfile.h	2016-12-09 22:59:52 UTC (rev 209632)
@@ -36,7 +36,7 @@
 public:
     CodeProfile(const SourceCode& source, CodeProfile* parent)
         : m_file(source.provider()->url().utf8())
-        , m_lineNumber(source.firstLine())
+        , m_lineNumber(source.firstLine().oneBasedInt())
         , m_parent(parent)
     {
         if (parent)

Modified: trunk/Source/WTF/ChangeLog (209631 => 209632)


--- trunk/Source/WTF/ChangeLog	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/WTF/ChangeLog	2016-12-09 22:59:52 UTC (rev 209632)
@@ -1,5 +1,15 @@
 2016-12-09  Geoffrey Garen  <gga...@apple.com>
 
+        Deploy OrdinalNumber in JSC::SourceCode
+        https://bugs.webkit.org/show_bug.cgi?id=165687
+
+        Reviewed by Michael Saboff.
+
+        * wtf/text/OrdinalNumber.h:
+        (WTF::OrdinalNumber::operator>): Added a >.
+
+2016-12-09  Geoffrey Garen  <gga...@apple.com>
+
         TextPosition and OrdinalNumber should be more like idiomatic numbers
         https://bugs.webkit.org/show_bug.cgi?id=165678
 

Modified: trunk/Source/WTF/wtf/text/OrdinalNumber.h (209631 => 209632)


--- trunk/Source/WTF/wtf/text/OrdinalNumber.h	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/WTF/wtf/text/OrdinalNumber.h	2016-12-09 22:59:52 UTC (rev 209632)
@@ -31,6 +31,7 @@
 // call a first element '0' or '1' which makes integer type ambiguous.
 class OrdinalNumber {
 public:
+    static OrdinalNumber beforeFirst() { return OrdinalNumber(-1); }
     static OrdinalNumber fromZeroBasedInt(int zeroBasedInt) { return OrdinalNumber(zeroBasedInt); }
     static OrdinalNumber fromOneBasedInt(int oneBasedInt) { return OrdinalNumber(oneBasedInt - 1); }
 
@@ -41,9 +42,8 @@
 
     bool operator==(OrdinalNumber other) { return m_zeroBasedValue == other.m_zeroBasedValue; }
     bool operator!=(OrdinalNumber other) { return !((*this) == other); }
+    bool operator>(OrdinalNumber other) { return m_zeroBasedValue > other.m_zeroBasedValue; }
 
-    static OrdinalNumber beforeFirst() { return OrdinalNumber(-1); }
-
 private:
     OrdinalNumber(int zeroBasedInt) : m_zeroBasedValue(zeroBasedInt) { }
     int m_zeroBasedValue;

Modified: trunk/Source/WebCore/ChangeLog (209631 => 209632)


--- trunk/Source/WebCore/ChangeLog	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/WebCore/ChangeLog	2016-12-09 22:59:52 UTC (rev 209632)
@@ -1,3 +1,17 @@
+2016-12-09  Geoffrey Garen  <gga...@apple.com>
+
+        Deploy OrdinalNumber in JSC::SourceCode
+        https://bugs.webkit.org/show_bug.cgi?id=165687
+
+        Reviewed by Michael Saboff.
+
+        Updated for interface changes.
+
+        * bindings/js/ScriptController.cpp:
+        (WebCore::ScriptController::evaluateModule):
+        * bindings/js/ScriptSourceCode.h:
+        (WebCore::ScriptSourceCode::startLine):
+
 2016-12-09  Joseph Pecoraro  <pecor...@apple.com>
 
         Web Inspector: Some resources fetched via Fetch API do not have data

Modified: trunk/Source/WebCore/bindings/js/ScriptController.cpp (209631 => 209632)


--- trunk/Source/WebCore/bindings/js/ScriptController.cpp	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/WebCore/bindings/js/ScriptController.cpp	2016-12-09 22:59:52 UTC (rev 209632)
@@ -256,7 +256,7 @@
 
     Ref<Frame> protector(m_frame);
 
-    auto cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, jsSourceCode.firstLine());
+    auto cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, jsSourceCode.firstLine().oneBasedInt());
 
     auto returnValue = moduleRecord.evaluate(&state);
     InspectorInstrumentation::didEvaluateScript(cookie, m_frame);

Modified: trunk/Source/WebCore/bindings/js/ScriptSourceCode.h (209631 => 209632)


--- trunk/Source/WebCore/bindings/js/ScriptSourceCode.h	2016-12-09 22:43:54 UTC (rev 209631)
+++ trunk/Source/WebCore/bindings/js/ScriptSourceCode.h	2016-12-09 22:59:52 UTC (rev 209632)
@@ -62,7 +62,7 @@
 
     StringView source() const { return m_provider->source(); }
 
-    int startLine() const { return m_code.firstLine(); }
+    int startLine() const { return m_code.firstLine().oneBasedInt(); }
 
     CachedScript* cachedScript() const { return m_cachedScript.get(); }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to