Changeset 209632 in webkit


Ignore:
Timestamp:
Dec 9, 2016, 2:59:52 PM (9 years ago)
Author:
ggaren@apple.com
Message:

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

Reviewed by Michael Saboff.

Source/JavaScriptCore:

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 >.

Location:
trunk/Source
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r209630 r209632  
     12016-12-09  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Deploy OrdinalNumber in JSC::SourceCode
     4        https://bugs.webkit.org/show_bug.cgi?id=165687
     5
     6        Reviewed by Michael Saboff.
     7
     8        We have a lot of confusion between 1-based and 0-based counting in line
     9        and column numbers. Let's use OrdinalNumber to clear up the confusion.
     10
     11        * bytecode/UnlinkedFunctionExecutable.cpp:
     12        (JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable):
     13        (JSC::UnlinkedFunctionExecutable::link):
     14        * bytecompiler/BytecodeGenerator.h:
     15        (JSC::BytecodeGenerator::emitExpressionInfo):
     16        * inspector/JSInjectedScriptHost.cpp:
     17        (Inspector::JSInjectedScriptHost::functionDetails):
     18        * parser/Lexer.cpp:
     19        (JSC::Lexer<T>::setCode):
     20        * parser/Parser.cpp:
     21        (JSC::Parser<LexerType>::Parser):
     22        * parser/Parser.h:
     23        (JSC::Parser<LexerType>::parse):
     24        * parser/SourceCode.h:
     25        (JSC::SourceCode::SourceCode):
     26        (JSC::SourceCode::firstLine):
     27        (JSC::SourceCode::startColumn):
     28        * runtime/CodeCache.cpp:
     29        (JSC::CodeCache::getUnlinkedGlobalCodeBlock):
     30        * runtime/ScriptExecutable.h:
     31        (JSC::ScriptExecutable::firstLine):
     32        (JSC::ScriptExecutable::startColumn):
     33        * tools/CodeProfile.h:
     34        (JSC::CodeProfile::CodeProfile):
     35
    1362016-12-09  Saam Barati  <sbarati@apple.com>
    237
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.cpp

    r209501 r209632  
    7878UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM* vm, Structure* structure, const SourceCode& parentSource, SourceCode&& parentSourceOverride, FunctionMetadataNode* node, UnlinkedFunctionKind kind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, VariableEnvironment& parentScopeTDZVariables, DerivedContextType derivedContextType)
    7979    : Base(*vm, structure)
    80     , m_firstLineOffset(node->firstLine() - parentSource.firstLine())
     80    , m_firstLineOffset(node->firstLine() - parentSource.firstLine().oneBasedInt())
    8181    , m_lineCount(node->lastLine() - node->firstLine())
    8282    , m_unlinkedFunctionNameStart(node->functionNameStart() - parentSource.startOffset())
     
    135135{
    136136    const SourceCode& parentSource = m_parentSourceOverride.isNull() ? passedParentSource : m_parentSourceOverride;
    137     unsigned firstLine = parentSource.firstLine() + m_firstLineOffset;
     137    unsigned firstLine = parentSource.firstLine().oneBasedInt() + m_firstLineOffset;
    138138    unsigned startOffset = parentSource.startOffset() + m_startOffset;
    139139    unsigned lineCount = m_lineCount;
    140140
    141     unsigned startColumn = linkedStartColumn(parentSource.startColumn());
     141    unsigned startColumn = linkedStartColumn(parentSource.startColumn().oneBasedInt());
    142142    unsigned endColumn = linkedEndColumn(startColumn);
    143143
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r208985 r209632  
    446446
    447447            int sourceOffset = m_scopeNode->source().startOffset();
    448             unsigned firstLine = m_scopeNode->source().firstLine();
     448            unsigned firstLine = m_scopeNode->source().firstLine().oneBasedInt();
    449449
    450450            int divotOffset = divot.offset - sourceOffset;
  • trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp

    r208923 r209632  
    216216
    217217    // In the inspector protocol all positions are 0-based while in SourceCode they are 1-based
    218     int lineNumber = sourceCode->firstLine();
     218    int lineNumber = sourceCode->firstLine().oneBasedInt();
    219219    if (lineNumber)
    220220        lineNumber -= 1;
    221     int columnNumber = sourceCode->startColumn();
     221    int columnNumber = sourceCode->startColumn().oneBasedInt();
    222222    if (columnNumber)
    223223        columnNumber -= 1;
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r207798 r209632  
    542542    m_arena = &arena->identifierArena();
    543543   
    544     m_lineNumber = source.firstLine();
     544    m_lineNumber = source.firstLine().oneBasedInt();
    545545    m_lastToken = -1;
    546546   
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r209350 r209632  
    208208    m_lexer = std::make_unique<LexerType>(vm, builtinMode, scriptMode);
    209209    m_lexer->setCode(source, &m_parserArena);
    210     m_token.m_location.line = source.firstLine();
     210    m_token.m_location.line = source.firstLine().oneBasedInt();
    211211    m_token.m_location.startOffset = source.startOffset();
    212212    m_token.m_location.endOffset = source.startOffset();
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r208933 r209632  
    17911791
    17921792    JSTokenLocation startLocation(tokenLocation());
    1793     ASSERT(m_source->startColumn() > 0);
    1794     unsigned startColumn = m_source->startColumn() - 1;
     1793    ASSERT(m_source->startColumn() > OrdinalNumber::beforeFirst());
     1794    unsigned startColumn = m_source->startColumn().zeroBasedInt();
    17951795
    17961796    String parseError = parseInner(calleeName, parseMode);
     
    18311831                                    m_numConstants,
    18321832                                    WTFMove(m_moduleScopeData));
    1833         result->setLoc(m_source->firstLine(), m_lexer->lineNumber(), m_lexer->currentOffset(), m_lexer->currentLineStartOffset());
     1833        result->setLoc(m_source->firstLine().oneBasedInt(), m_lexer->lineNumber(), m_lexer->currentOffset(), m_lexer->currentLineStartOffset());
    18341834        result->setEndOffset(m_lexer->currentOffset());
    18351835
  • trunk/Source/JavaScriptCore/parser/SourceCode.h

    r209627 r209632  
    3737        SourceCode()
    3838            : UnlinkedSourceCode()
    39             , m_firstLine(0)
    40             , m_startColumn(0)
     39            , m_firstLine(OrdinalNumber::beforeFirst())
     40            , m_startColumn(OrdinalNumber::beforeFirst())
    4141        {
    4242        }
     
    4444        SourceCode(PassRefPtr<SourceProvider> provider)
    4545            : UnlinkedSourceCode(provider)
    46             , m_firstLine(1)
    47             , m_startColumn(1)
    4846        {
    4947        }
     
    5149        SourceCode(PassRefPtr<SourceProvider> provider, int firstLine, int startColumn)
    5250            : UnlinkedSourceCode(provider)
    53             , m_firstLine(std::max(firstLine, 1))
    54             , m_startColumn(std::max(startColumn, 1))
     51            , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1)))
     52            , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1)))
    5553        {
    5654        }
     
    5856        SourceCode(PassRefPtr<SourceProvider> provider, int startOffset, int endOffset, int firstLine, int startColumn)
    5957            : UnlinkedSourceCode(provider, startOffset, endOffset)
    60             , m_firstLine(std::max(firstLine, 1))
    61             , m_startColumn(std::max(startColumn, 1))
     58            , m_firstLine(OrdinalNumber::fromOneBasedInt(std::max(firstLine, 1)))
     59            , m_startColumn(OrdinalNumber::fromOneBasedInt(std::max(startColumn, 1)))
    6260        {
    6361        }
    6462
    65         int firstLine() const { return m_firstLine; }
    66         int startColumn() const { return m_startColumn; }
     63        OrdinalNumber firstLine() const { return m_firstLine; }
     64        OrdinalNumber startColumn() const { return m_startColumn; }
    6765
    6866        intptr_t providerID() const
     
    7876
    7977    private:
    80         int m_firstLine;
    81         int m_startColumn;
     78        OrdinalNumber m_firstLine;
     79        OrdinalNumber m_startColumn;
    8280    };
    8381
  • trunk/Source/JavaScriptCore/runtime/CodeCache.cpp

    r209353 r209632  
    6363        UnlinkedCodeBlockType* unlinkedCodeBlock = jsCast<UnlinkedCodeBlockType*>(cache->cell.get());
    6464        unsigned lineCount = unlinkedCodeBlock->lineCount();
    65         unsigned startColumn = unlinkedCodeBlock->startColumn() + source.startColumn();
     65        unsigned startColumn = unlinkedCodeBlock->startColumn() + source.startColumn().oneBasedInt();
    6666        bool endColumnIsOnStartLine = !lineCount;
    6767        unsigned endColumn = unlinkedCodeBlock->endColumn() + (endColumnIsOnStartLine ? startColumn : 1);
    68         executable->recordParse(unlinkedCodeBlock->codeFeatures(), unlinkedCodeBlock->hasCapturedVariables(), source.firstLine() + lineCount, endColumn);
     68        executable->recordParse(unlinkedCodeBlock->codeFeatures(), unlinkedCodeBlock->hasCapturedVariables(), source.firstLine().oneBasedInt() + lineCount, endColumn);
    6969        source.provider()->setSourceURLDirective(unlinkedCodeBlock->sourceURLDirective());
    7070        source.provider()->setSourceMappingURLDirective(unlinkedCodeBlock->sourceMappingURLDirective());
  • trunk/Source/JavaScriptCore/runtime/ScriptExecutable.h

    r209353 r209632  
    4242    intptr_t sourceID() const { return m_source.providerID(); }
    4343    const String& sourceURL() const { return m_source.provider()->url(); }
    44     int firstLine() const { return m_source.firstLine(); }
     44    int firstLine() const { return m_source.firstLine().oneBasedInt(); }
    4545    void setOverrideLineNumber(int overrideLineNumber) { m_overrideLineNumber = overrideLineNumber; }
    4646    bool hasOverrideLineNumber() const { return m_overrideLineNumber != -1; }
    4747    int overrideLineNumber() const { return m_overrideLineNumber; }
    4848    int lastLine() const { return m_lastLine; }
    49     unsigned startColumn() const { return m_source.startColumn(); }
     49    unsigned startColumn() const { return m_source.startColumn().oneBasedInt(); }
    5050    unsigned endColumn() const { return m_endColumn; }
    5151    unsigned typeProfilingStartOffset() const { return m_typeProfilingStartOffset; }
  • trunk/Source/JavaScriptCore/tools/CodeProfile.h

    r206525 r209632  
    3737    CodeProfile(const SourceCode& source, CodeProfile* parent)
    3838        : m_file(source.provider()->url().utf8())
    39         , m_lineNumber(source.firstLine())
     39        , m_lineNumber(source.firstLine().oneBasedInt())
    4040        , m_parent(parent)
    4141    {
  • trunk/Source/WTF/ChangeLog

    r209627 r209632  
     12016-12-09  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Deploy OrdinalNumber in JSC::SourceCode
     4        https://bugs.webkit.org/show_bug.cgi?id=165687
     5
     6        Reviewed by Michael Saboff.
     7
     8        * wtf/text/OrdinalNumber.h:
     9        (WTF::OrdinalNumber::operator>): Added a >.
     10
    1112016-12-09  Geoffrey Garen  <ggaren@apple.com>
    212
  • trunk/Source/WTF/wtf/text/OrdinalNumber.h

    r209627 r209632  
    3232class OrdinalNumber {
    3333public:
     34    static OrdinalNumber beforeFirst() { return OrdinalNumber(-1); }
    3435    static OrdinalNumber fromZeroBasedInt(int zeroBasedInt) { return OrdinalNumber(zeroBasedInt); }
    3536    static OrdinalNumber fromOneBasedInt(int oneBasedInt) { return OrdinalNumber(oneBasedInt - 1); }
     
    4243    bool operator==(OrdinalNumber other) { return m_zeroBasedValue == other.m_zeroBasedValue; }
    4344    bool operator!=(OrdinalNumber other) { return !((*this) == other); }
    44 
    45     static OrdinalNumber beforeFirst() { return OrdinalNumber(-1); }
     45    bool operator>(OrdinalNumber other) { return m_zeroBasedValue > other.m_zeroBasedValue; }
    4646
    4747private:
  • trunk/Source/WebCore/ChangeLog

    r209629 r209632  
     12016-12-09  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Deploy OrdinalNumber in JSC::SourceCode
     4        https://bugs.webkit.org/show_bug.cgi?id=165687
     5
     6        Reviewed by Michael Saboff.
     7
     8        Updated for interface changes.
     9
     10        * bindings/js/ScriptController.cpp:
     11        (WebCore::ScriptController::evaluateModule):
     12        * bindings/js/ScriptSourceCode.h:
     13        (WebCore::ScriptSourceCode::startLine):
     14
    1152016-12-09  Joseph Pecoraro  <pecoraro@apple.com>
    216
  • trunk/Source/WebCore/bindings/js/ScriptController.cpp

    r209627 r209632  
    257257    Ref<Frame> protector(m_frame);
    258258
    259     auto cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, jsSourceCode.firstLine());
     259    auto cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, jsSourceCode.firstLine().oneBasedInt());
    260260
    261261    auto returnValue = moduleRecord.evaluate(&state);
  • trunk/Source/WebCore/bindings/js/ScriptSourceCode.h

    r209627 r209632  
    6363    StringView source() const { return m_provider->source(); }
    6464
    65     int startLine() const { return m_code.firstLine(); }
     65    int startLine() const { return m_code.firstLine().oneBasedInt(); }
    6666
    6767    CachedScript* cachedScript() const { return m_cachedScript.get(); }
Note: See TracChangeset for help on using the changeset viewer.