Changeset 181213 in webkit
- Timestamp:
- Mar 7, 2015 2:10:10 PM (9 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r181210 r181213 1 2015-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 1 27 2015-03-06 Geoffrey Garen <ggaren@apple.com> 2 28 -
trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp
r180993 r181213 1747 1747 if (vm()->typeProfiler() || vm()->controlFlowProfiler()) 1748 1748 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())); 1760 1750 } 1761 1751 … … 1765 1755 if (vm()->typeProfiler() || vm()->controlFlowProfiler()) 1766 1756 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())); 1778 1758 } 1779 1759 -
trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp
r181208 r181213 119 119 } 120 120 121 FunctionExecutable* UnlinkedFunctionExecutable::link(VM& vm, const SourceCode& source, size_t lineOffset) 122 { 123 unsigned firstLine = lineOffset + m_firstLineOffset; 121 FunctionExecutable* UnlinkedFunctionExecutable::linkInsideExecutable(VM& vm, const SourceCode& source) 122 { 123 unsigned firstLine = source.firstLine() + m_firstLineOffset; 124 unsigned startOffset = source.startOffset() + m_startOffset; 125 124 126 bool startColumnIsOnFirstSourceLine = !m_firstLineOffset; 125 127 unsigned startColumn = m_unlinkedBodyStartColumn + (startColumnIsOnFirstSourceLine ? source.startColumn() : 1); 126 128 bool endColumnIsOnStartLine = !m_lineCount; 127 129 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); 129 132 return FunctionExecutable::create(vm, code, this, firstLine, firstLine + m_lineCount, startColumn, endColumn); 133 } 134 135 FunctionExecutable* 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); 130 153 } 131 154 -
trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h
r181208 r181213 118 118 } 119 119 120 unsigned firstLineOffset() const { return m_firstLineOffset; }121 unsigned lineCount() const { return m_lineCount; }122 120 unsigned unlinkedFunctionNameStart() const { return m_unlinkedFunctionNameStart; } 123 121 unsigned unlinkedBodyStartColumn() const { return m_unlinkedBodyStartColumn; } … … 134 132 static UnlinkedFunctionExecutable* fromGlobalCode(const Identifier&, ExecState&, const SourceCode&, JSObject*& exception); 135 133 136 FunctionExecutable* link(VM&, const SourceCode&, size_t lineOffset); 134 FunctionExecutable* linkInsideExecutable(VM&, const SourceCode&); 135 FunctionExecutable* linkGlobalCode(VM&, const SourceCode&); 137 136 138 137 void clearCodeForRecompilation() -
trunk/Source/JavaScriptCore/generate-js-builtins
r163960 r181213 265 265 266 266 builtinsImplementation.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 281 267 #define JSC_DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\ 282 268 FunctionExecutable* codeName##Generator(VM& vm) \\ 283 269 { \\ 284 return createBuiltinExecutable(vm, vm.builtinExecutables()->codeName##Executable(), vm.builtinExecutables()->codeName##Source()); \\270 return vm.builtinExecutables()->codeName##Executable()->linkGlobalCode(vm, vm.builtinExecutables()->codeName##Source()); \\ 285 271 } 286 272 -
trunk/Source/JavaScriptCore/runtime/Executable.cpp
r181208 r181213 504 504 for (size_t i = 0; i < functionDeclarations.size(); ++i) { 505 505 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); 507 507 globalObject->addFunction(callFrame, functionDeclarations[i].first, value); 508 508 if (vm.typeProfiler() || vm.controlFlowProfiler()) { … … 609 609 UnlinkedFunctionExecutable* unlinkedExecutable = UnlinkedFunctionExecutable::fromGlobalCode(name, exec, source, exception); 610 610 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); 630 613 } 631 614
Note: See TracChangeset
for help on using the changeset viewer.