Changeset 209632 in webkit
- Timestamp:
- Dec 9, 2016, 2:59:52 PM (9 years ago)
- Location:
- trunk/Source
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r209630 r209632 1 2016-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 1 36 2016-12-09 Saam Barati <sbarati@apple.com> 2 37 -
trunk/Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.cpp
r209501 r209632 78 78 UnlinkedFunctionExecutable::UnlinkedFunctionExecutable(VM* vm, Structure* structure, const SourceCode& parentSource, SourceCode&& parentSourceOverride, FunctionMetadataNode* node, UnlinkedFunctionKind kind, ConstructAbility constructAbility, JSParserScriptMode scriptMode, VariableEnvironment& parentScopeTDZVariables, DerivedContextType derivedContextType) 79 79 : Base(*vm, structure) 80 , m_firstLineOffset(node->firstLine() - parentSource.firstLine() )80 , m_firstLineOffset(node->firstLine() - parentSource.firstLine().oneBasedInt()) 81 81 , m_lineCount(node->lastLine() - node->firstLine()) 82 82 , m_unlinkedFunctionNameStart(node->functionNameStart() - parentSource.startOffset()) … … 135 135 { 136 136 const SourceCode& parentSource = m_parentSourceOverride.isNull() ? passedParentSource : m_parentSourceOverride; 137 unsigned firstLine = parentSource.firstLine() + m_firstLineOffset;137 unsigned firstLine = parentSource.firstLine().oneBasedInt() + m_firstLineOffset; 138 138 unsigned startOffset = parentSource.startOffset() + m_startOffset; 139 139 unsigned lineCount = m_lineCount; 140 140 141 unsigned startColumn = linkedStartColumn(parentSource.startColumn() );141 unsigned startColumn = linkedStartColumn(parentSource.startColumn().oneBasedInt()); 142 142 unsigned endColumn = linkedEndColumn(startColumn); 143 143 -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r208985 r209632 446 446 447 447 int sourceOffset = m_scopeNode->source().startOffset(); 448 unsigned firstLine = m_scopeNode->source().firstLine() ;448 unsigned firstLine = m_scopeNode->source().firstLine().oneBasedInt(); 449 449 450 450 int divotOffset = divot.offset - sourceOffset; -
trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
r208923 r209632 216 216 217 217 // 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(); 219 219 if (lineNumber) 220 220 lineNumber -= 1; 221 int columnNumber = sourceCode->startColumn() ;221 int columnNumber = sourceCode->startColumn().oneBasedInt(); 222 222 if (columnNumber) 223 223 columnNumber -= 1; -
trunk/Source/JavaScriptCore/parser/Lexer.cpp
r207798 r209632 542 542 m_arena = &arena->identifierArena(); 543 543 544 m_lineNumber = source.firstLine() ;544 m_lineNumber = source.firstLine().oneBasedInt(); 545 545 m_lastToken = -1; 546 546 -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r209350 r209632 208 208 m_lexer = std::make_unique<LexerType>(vm, builtinMode, scriptMode); 209 209 m_lexer->setCode(source, &m_parserArena); 210 m_token.m_location.line = source.firstLine() ;210 m_token.m_location.line = source.firstLine().oneBasedInt(); 211 211 m_token.m_location.startOffset = source.startOffset(); 212 212 m_token.m_location.endOffset = source.startOffset(); -
trunk/Source/JavaScriptCore/parser/Parser.h
r208933 r209632 1791 1791 1792 1792 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(); 1795 1795 1796 1796 String parseError = parseInner(calleeName, parseMode); … … 1831 1831 m_numConstants, 1832 1832 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()); 1834 1834 result->setEndOffset(m_lexer->currentOffset()); 1835 1835 -
trunk/Source/JavaScriptCore/parser/SourceCode.h
r209627 r209632 37 37 SourceCode() 38 38 : UnlinkedSourceCode() 39 , m_firstLine( 0)40 , m_startColumn( 0)39 , m_firstLine(OrdinalNumber::beforeFirst()) 40 , m_startColumn(OrdinalNumber::beforeFirst()) 41 41 { 42 42 } … … 44 44 SourceCode(PassRefPtr<SourceProvider> provider) 45 45 : UnlinkedSourceCode(provider) 46 , m_firstLine(1)47 , m_startColumn(1)48 46 { 49 47 } … … 51 49 SourceCode(PassRefPtr<SourceProvider> provider, int firstLine, int startColumn) 52 50 : 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))) 55 53 { 56 54 } … … 58 56 SourceCode(PassRefPtr<SourceProvider> provider, int startOffset, int endOffset, int firstLine, int startColumn) 59 57 : 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))) 62 60 { 63 61 } 64 62 65 intfirstLine() const { return m_firstLine; }66 intstartColumn() const { return m_startColumn; }63 OrdinalNumber firstLine() const { return m_firstLine; } 64 OrdinalNumber startColumn() const { return m_startColumn; } 67 65 68 66 intptr_t providerID() const … … 78 76 79 77 private: 80 intm_firstLine;81 intm_startColumn;78 OrdinalNumber m_firstLine; 79 OrdinalNumber m_startColumn; 82 80 }; 83 81 -
trunk/Source/JavaScriptCore/runtime/CodeCache.cpp
r209353 r209632 63 63 UnlinkedCodeBlockType* unlinkedCodeBlock = jsCast<UnlinkedCodeBlockType*>(cache->cell.get()); 64 64 unsigned lineCount = unlinkedCodeBlock->lineCount(); 65 unsigned startColumn = unlinkedCodeBlock->startColumn() + source.startColumn() ;65 unsigned startColumn = unlinkedCodeBlock->startColumn() + source.startColumn().oneBasedInt(); 66 66 bool endColumnIsOnStartLine = !lineCount; 67 67 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); 69 69 source.provider()->setSourceURLDirective(unlinkedCodeBlock->sourceURLDirective()); 70 70 source.provider()->setSourceMappingURLDirective(unlinkedCodeBlock->sourceMappingURLDirective()); -
trunk/Source/JavaScriptCore/runtime/ScriptExecutable.h
r209353 r209632 42 42 intptr_t sourceID() const { return m_source.providerID(); } 43 43 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(); } 45 45 void setOverrideLineNumber(int overrideLineNumber) { m_overrideLineNumber = overrideLineNumber; } 46 46 bool hasOverrideLineNumber() const { return m_overrideLineNumber != -1; } 47 47 int overrideLineNumber() const { return m_overrideLineNumber; } 48 48 int lastLine() const { return m_lastLine; } 49 unsigned startColumn() const { return m_source.startColumn() ; }49 unsigned startColumn() const { return m_source.startColumn().oneBasedInt(); } 50 50 unsigned endColumn() const { return m_endColumn; } 51 51 unsigned typeProfilingStartOffset() const { return m_typeProfilingStartOffset; } -
trunk/Source/JavaScriptCore/tools/CodeProfile.h
r206525 r209632 37 37 CodeProfile(const SourceCode& source, CodeProfile* parent) 38 38 : m_file(source.provider()->url().utf8()) 39 , m_lineNumber(source.firstLine() )39 , m_lineNumber(source.firstLine().oneBasedInt()) 40 40 , m_parent(parent) 41 41 { -
trunk/Source/WTF/ChangeLog
r209627 r209632 1 2016-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 1 11 2016-12-09 Geoffrey Garen <ggaren@apple.com> 2 12 -
trunk/Source/WTF/wtf/text/OrdinalNumber.h
r209627 r209632 32 32 class OrdinalNumber { 33 33 public: 34 static OrdinalNumber beforeFirst() { return OrdinalNumber(-1); } 34 35 static OrdinalNumber fromZeroBasedInt(int zeroBasedInt) { return OrdinalNumber(zeroBasedInt); } 35 36 static OrdinalNumber fromOneBasedInt(int oneBasedInt) { return OrdinalNumber(oneBasedInt - 1); } … … 42 43 bool operator==(OrdinalNumber other) { return m_zeroBasedValue == other.m_zeroBasedValue; } 43 44 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; } 46 46 47 47 private: -
trunk/Source/WebCore/ChangeLog
r209629 r209632 1 2016-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 1 15 2016-12-09 Joseph Pecoraro <pecoraro@apple.com> 2 16 -
trunk/Source/WebCore/bindings/js/ScriptController.cpp
r209627 r209632 257 257 Ref<Frame> protector(m_frame); 258 258 259 auto cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, jsSourceCode.firstLine() );259 auto cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, jsSourceCode.firstLine().oneBasedInt()); 260 260 261 261 auto returnValue = moduleRecord.evaluate(&state); -
trunk/Source/WebCore/bindings/js/ScriptSourceCode.h
r209627 r209632 63 63 StringView source() const { return m_provider->source(); } 64 64 65 int startLine() const { return m_code.firstLine() ; }65 int startLine() const { return m_code.firstLine().oneBasedInt(); } 66 66 67 67 CachedScript* cachedScript() const { return m_cachedScript.get(); }
Note:
See TracChangeset
for help on using the changeset viewer.