Changeset 181213 in webkit


Ignore:
Timestamp:
Mar 7, 2015 2:10:10 PM (9 years ago)
Author:
rniwa@webkit.org
Message:

The code to link FunctionExecutable is duplicated everywhere
https://bugs.webkit.org/show_bug.cgi?id=142436

Reviewed by Darin Adler.

Reduced code duplication by factoring out linkInsideExecutable and linkGlobalCode.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::CodeBlock): Calls linkInsideExecutable.

  • bytecode/UnlinkedCodeBlock.cpp:

(JSC::UnlinkedFunctionExecutable::linkInsideExecutable): Renamed from link. Now takes care of startOffset.
This change was needed to use this function in CodeBlock::CodeBlock. Also, this function no longer takes
lineOffset since this information is already stored in the source code.
(JSC::UnlinkedFunctionExecutable::linkGlobalCode): Extracted from FunctionExecutable::fromGlobalCode.

  • bytecode/UnlinkedCodeBlock.h:
  • generate-js-builtins: Calls linkGlobalCode.
  • runtime/Executable.cpp:

(JSC::ProgramExecutable::initializeGlobalProperties): Calls linkGlobalCode.
(JSC::FunctionExecutable::fromGlobalCode): Calls linkGlobalCode.

Location:
trunk/Source/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r181210 r181213  
     12015-03-07  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        The code to link FunctionExecutable is duplicated everywhere
     4        https://bugs.webkit.org/show_bug.cgi?id=142436
     5
     6        Reviewed by Darin Adler.
     7
     8        Reduced code duplication by factoring out linkInsideExecutable and linkGlobalCode.
     9
     10        * bytecode/CodeBlock.cpp:
     11        (JSC::CodeBlock::CodeBlock): Calls linkInsideExecutable.
     12
     13        * bytecode/UnlinkedCodeBlock.cpp:
     14        (JSC::UnlinkedFunctionExecutable::linkInsideExecutable): Renamed from link. Now takes care of startOffset.
     15        This change was needed to use this function in CodeBlock::CodeBlock. Also, this function no longer takes
     16        lineOffset since this information is already stored in the source code.
     17        (JSC::UnlinkedFunctionExecutable::linkGlobalCode): Extracted from FunctionExecutable::fromGlobalCode.
     18
     19        * bytecode/UnlinkedCodeBlock.h:
     20
     21        * generate-js-builtins: Calls linkGlobalCode.
     22
     23        * runtime/Executable.cpp:
     24        (JSC::ProgramExecutable::initializeGlobalProperties): Calls linkGlobalCode.
     25        (JSC::FunctionExecutable::fromGlobalCode): Calls linkGlobalCode.
     26
    1272015-03-06  Geoffrey Garen  <ggaren@apple.com>
    228
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r180993 r181213  
    17471747        if (vm()->typeProfiler() || vm()->controlFlowProfiler())
    17481748            vm()->functionHasExecutedCache()->insertUnexecutedRange(m_ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
    1749         unsigned lineCount = unlinkedExecutable->lineCount();
    1750         unsigned firstLine = ownerExecutable->lineNo() + unlinkedExecutable->firstLineOffset();
    1751         bool startColumnIsOnOwnerStartLine = !unlinkedExecutable->firstLineOffset();
    1752         unsigned startColumn = unlinkedExecutable->unlinkedBodyStartColumn() + (startColumnIsOnOwnerStartLine ? ownerExecutable->startColumn() : 1);
    1753         bool endColumnIsOnStartLine = !lineCount;
    1754         unsigned endColumn = unlinkedExecutable->unlinkedBodyEndColumn() + (endColumnIsOnStartLine ? startColumn : 1);
    1755         unsigned startOffset = sourceOffset + unlinkedExecutable->startOffset();
    1756         unsigned sourceLength = unlinkedExecutable->sourceLength();
    1757         SourceCode code(m_source, startOffset, startOffset + sourceLength, firstLine, startColumn);
    1758         FunctionExecutable* executable = FunctionExecutable::create(*m_vm, code, unlinkedExecutable, firstLine, firstLine + lineCount, startColumn, endColumn);
    1759         m_functionDecls[i].set(*m_vm, ownerExecutable, executable);
     1749        m_functionDecls[i].set(*m_vm, ownerExecutable, unlinkedExecutable->linkInsideExecutable(*m_vm, ownerExecutable->source()));
    17601750    }
    17611751
     
    17651755        if (vm()->typeProfiler() || vm()->controlFlowProfiler())
    17661756            vm()->functionHasExecutedCache()->insertUnexecutedRange(m_ownerExecutable->sourceID(), unlinkedExecutable->typeProfilingStartOffset(), unlinkedExecutable->typeProfilingEndOffset());
    1767         unsigned lineCount = unlinkedExecutable->lineCount();
    1768         unsigned firstLine = ownerExecutable->lineNo() + unlinkedExecutable->firstLineOffset();
    1769         bool startColumnIsOnOwnerStartLine = !unlinkedExecutable->firstLineOffset();
    1770         unsigned startColumn = unlinkedExecutable->unlinkedBodyStartColumn() + (startColumnIsOnOwnerStartLine ? ownerExecutable->startColumn() : 1);
    1771         bool endColumnIsOnStartLine = !lineCount;
    1772         unsigned endColumn = unlinkedExecutable->unlinkedBodyEndColumn() + (endColumnIsOnStartLine ? startColumn : 1);
    1773         unsigned startOffset = sourceOffset + unlinkedExecutable->startOffset();
    1774         unsigned sourceLength = unlinkedExecutable->sourceLength();
    1775         SourceCode code(m_source, startOffset, startOffset + sourceLength, firstLine, startColumn);
    1776         FunctionExecutable* executable = FunctionExecutable::create(*m_vm, code, unlinkedExecutable, firstLine, firstLine + lineCount, startColumn, endColumn);
    1777         m_functionExprs[i].set(*m_vm, ownerExecutable, executable);
     1757        m_functionExprs[i].set(*m_vm, ownerExecutable, unlinkedExecutable->linkInsideExecutable(*m_vm, ownerExecutable->source()));
    17781758    }
    17791759
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp

    r181208 r181213  
    119119}
    120120
    121 FunctionExecutable* UnlinkedFunctionExecutable::link(VM& vm, const SourceCode& source, size_t lineOffset)
    122 {
    123     unsigned firstLine = lineOffset + m_firstLineOffset;
     121FunctionExecutable* UnlinkedFunctionExecutable::linkInsideExecutable(VM& vm, const SourceCode& source)
     122{
     123    unsigned firstLine = source.firstLine() + m_firstLineOffset;
     124    unsigned startOffset = source.startOffset() + m_startOffset;
     125
    124126    bool startColumnIsOnFirstSourceLine = !m_firstLineOffset;
    125127    unsigned startColumn = m_unlinkedBodyStartColumn + (startColumnIsOnFirstSourceLine ? source.startColumn() : 1);
    126128    bool endColumnIsOnStartLine = !m_lineCount;
    127129    unsigned endColumn = m_unlinkedBodyEndColumn + (endColumnIsOnStartLine ? startColumn : 1);
    128     SourceCode code(source.provider(), m_startOffset, m_startOffset + m_sourceLength, firstLine, startColumn);
     130
     131    SourceCode code(source.provider(), startOffset, startOffset + m_sourceLength, firstLine, startColumn);
    129132    return FunctionExecutable::create(vm, code, this, firstLine, firstLine + m_lineCount, startColumn, endColumn);
     133}
     134
     135FunctionExecutable* UnlinkedFunctionExecutable::linkGlobalCode(VM& vm, const SourceCode& source)
     136{
     137    unsigned firstLine = source.firstLine() + m_firstLineOffset;
     138    unsigned startOffset = source.startOffset() + m_startOffset;
     139
     140    // We don't have any owner executable. The source string is effectively like a global
     141    // string (like in the handling of eval). Hence, the startColumn is always 1.
     142    unsigned startColumn = 1;
     143    bool endColumnIsOnStartLine = !m_lineCount;
     144    // The unlinkedBodyEndColumn is 0-based. Hence, we need to add 1 to it. But if the
     145    // endColumn is on the startLine, then we need to subtract back the adjustment for
     146    // the open brace resulting in an adjustment of 0.
     147    unsigned endColumnExcludingBraces = m_unlinkedBodyEndColumn + (endColumnIsOnStartLine ? 0 : 1);
     148    unsigned startOffsetExcludingOpenBrace = startOffset + 1;
     149    unsigned endOffsetExcludingCloseBrace = startOffset + m_sourceLength - 1;
     150    SourceCode code(source.provider(), startOffsetExcludingOpenBrace, endOffsetExcludingCloseBrace, firstLine, startColumn);
     151
     152    return FunctionExecutable::create(vm, code, this, firstLine, firstLine + m_lineCount, startColumn, endColumnExcludingBraces, false);
    130153}
    131154
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h

    r181208 r181213  
    118118    }
    119119
    120     unsigned firstLineOffset() const { return m_firstLineOffset; }
    121     unsigned lineCount() const { return m_lineCount; }
    122120    unsigned unlinkedFunctionNameStart() const { return m_unlinkedFunctionNameStart; }
    123121    unsigned unlinkedBodyStartColumn() const { return m_unlinkedBodyStartColumn; }
     
    134132    static UnlinkedFunctionExecutable* fromGlobalCode(const Identifier&, ExecState&, const SourceCode&, JSObject*& exception);
    135133
    136     FunctionExecutable* link(VM&, const SourceCode&, size_t lineOffset);
     134    FunctionExecutable* linkInsideExecutable(VM&, const SourceCode&);
     135    FunctionExecutable* linkGlobalCode(VM&, const SourceCode&);
    137136
    138137    void clearCodeForRecompilation()
  • trunk/Source/JavaScriptCore/generate-js-builtins

    r163960 r181213  
    265265
    266266builtinsImplementation.write("""
    267 FunctionExecutable* createBuiltinExecutable(VM& vm, UnlinkedFunctionExecutable* unlinkedExecutable, const SourceCode& source)
    268 {
    269     unsigned lineCount = unlinkedExecutable->lineCount();
    270     unsigned startColumn = 1;
    271     unsigned sourceLength = unlinkedExecutable->sourceLength();
    272     bool endColumnIsOnStartLine = !lineCount;
    273     unsigned endColumnExcludingBraces = unlinkedExecutable->unlinkedBodyEndColumn() + (endColumnIsOnStartLine ? 0 : 1);
    274     unsigned startOffset = unlinkedExecutable->startOffset();
    275     unsigned startOffsetExcludingOpenBrace = startOffset + 1;
    276     unsigned endOffsetExcludingCloseBrace = startOffset + sourceLength - 1;
    277     SourceCode bodySource(source.provider(), startOffsetExcludingOpenBrace, endOffsetExcludingCloseBrace, 0, startColumn);
    278     return FunctionExecutable::create(vm, bodySource, unlinkedExecutable, 0, lineCount, startColumn, endColumnExcludingBraces, false);
    279 }
    280 
    281267#define JSC_DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\
    282268FunctionExecutable* codeName##Generator(VM& vm) \\
    283269{ \\
    284     return createBuiltinExecutable(vm, vm.builtinExecutables()->codeName##Executable(), vm.builtinExecutables()->codeName##Source()); \\
     270    return vm.builtinExecutables()->codeName##Executable()->linkGlobalCode(vm, vm.builtinExecutables()->codeName##Source()); \\
    285271}
    286272
  • trunk/Source/JavaScriptCore/runtime/Executable.cpp

    r181208 r181213  
    504504    for (size_t i = 0; i < functionDeclarations.size(); ++i) {
    505505        UnlinkedFunctionExecutable* unlinkedFunctionExecutable = functionDeclarations[i].second.get();
    506         JSValue value = JSFunction::create(vm, unlinkedFunctionExecutable->link(vm, m_source, lineNo()), scope);
     506        JSValue value = JSFunction::create(vm, unlinkedFunctionExecutable->linkInsideExecutable(vm, m_source), scope);
    507507        globalObject->addFunction(callFrame, functionDeclarations[i].first, value);
    508508        if (vm.typeProfiler() || vm.controlFlowProfiler()) {
     
    609609    UnlinkedFunctionExecutable* unlinkedExecutable = UnlinkedFunctionExecutable::fromGlobalCode(name, exec, source, exception);
    610610    if (!unlinkedExecutable)
    611         return 0;
    612     unsigned lineCount = unlinkedExecutable->lineCount();
    613     unsigned firstLine = source.firstLine() + unlinkedExecutable->firstLineOffset();
    614     unsigned startOffset = source.startOffset() + unlinkedExecutable->startOffset();
    615 
    616     // We don't have any owner executable. The source string is effectively like a global
    617     // string (like in the handling of eval). Hence, the startColumn is always 1.
    618     unsigned startColumn = 1;
    619     unsigned sourceLength = unlinkedExecutable->sourceLength();
    620     bool endColumnIsOnStartLine = !lineCount;
    621     // The unlinkedBodyEndColumn is based-0. Hence, we need to add 1 to it. But if the
    622     // endColumn is on the startLine, then we need to subtract back the adjustment for
    623     // the open brace resulting in an adjustment of 0.
    624     unsigned endColumnExcludingBraces = unlinkedExecutable->unlinkedBodyEndColumn() + (endColumnIsOnStartLine ? 0 : 1);
    625     unsigned startOffsetExcludingOpenBrace = startOffset + 1;
    626     unsigned endOffsetExcludingCloseBrace = startOffset + sourceLength - 1;
    627     SourceCode bodySource(source.provider(), startOffsetExcludingOpenBrace, endOffsetExcludingCloseBrace, firstLine, startColumn);
    628 
    629     return FunctionExecutable::create(exec.vm(), bodySource, unlinkedExecutable, firstLine, firstLine + lineCount, startColumn, endColumnExcludingBraces, false);
     611        return nullptr;
     612    return unlinkedExecutable->linkGlobalCode(exec.vm(), source);
    630613}
    631614
Note: See TracChangeset for help on using the changeset viewer.