Changeset 191135 in webkit
- Timestamp:
- Oct 15, 2015, 1:50:02 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r191132 r191135 1 2015-10-15 Joseph Pecoraro <[email protected]> 2 3 Web Inspector: JavaScriptCore should parse sourceURL and sourceMappingURL directives 4 https://bugs.webkit.org/show_bug.cgi?id=150096 5 6 Reviewed by Geoffrey Garen. 7 8 * inspector/debugger/sourceURLs-expected.txt: Added. 9 * inspector/debugger/sourceURLs.html: Added. 10 sourceURL and sourceMappingURL detection. 11 1 12 2015-10-15 Dean Jackson <[email protected]> 2 13 -
trunk/Source/JavaScriptCore/ChangeLog
r191134 r191135 1 2015-10-15 Joseph Pecoraro <[email protected]> 2 3 Web Inspector: JavaScriptCore should parse sourceURL and sourceMappingURL directives 4 https://bugs.webkit.org/show_bug.cgi?id=150096 5 6 Reviewed by Geoffrey Garen. 7 8 * inspector/ContentSearchUtilities.cpp: 9 (Inspector::ContentSearchUtilities::scriptCommentPattern): Deleted. 10 (Inspector::ContentSearchUtilities::findScriptSourceURL): Deleted. 11 (Inspector::ContentSearchUtilities::findScriptSourceMapURL): Deleted. 12 * inspector/ContentSearchUtilities.h: 13 No longer need to search script content. 14 15 * inspector/ScriptDebugServer.cpp: 16 (Inspector::ScriptDebugServer::dispatchDidParseSource): 17 Carry over the sourceURL and sourceMappingURL from the SourceProvider. 18 19 * inspector/agents/InspectorDebuggerAgent.cpp: 20 (Inspector::InspectorDebuggerAgent::sourceMapURLForScript): 21 (Inspector::InspectorDebuggerAgent::didParseSource): 22 No longer do content searching. 23 24 * parser/Lexer.cpp: 25 (JSC::Lexer<T>::setCode): 26 (JSC::Lexer<T>::skipWhitespace): 27 (JSC::Lexer<T>::parseCommentDirective): 28 (JSC::Lexer<T>::parseCommentDirectiveValue): 29 (JSC::Lexer<T>::consume): 30 (JSC::Lexer<T>::lex): 31 * parser/Lexer.h: 32 (JSC::Lexer::sourceURL): 33 (JSC::Lexer::sourceMappingURL): 34 (JSC::Lexer::sourceProvider): Deleted. 35 Give lexer the ability to detect script comment directives. 36 This just consumes characters in single line comments and 37 ultimately sets the sourceURL or sourceMappingURL found. 38 39 * parser/Parser.h: 40 (JSC::Parser<LexerType>::parse): 41 * parser/SourceProvider.h: 42 (JSC::SourceProvider::url): 43 (JSC::SourceProvider::sourceURL): 44 (JSC::SourceProvider::sourceMappingURL): 45 (JSC::SourceProvider::setSourceURL): 46 (JSC::SourceProvider::setSourceMappingURL): 47 After parsing a script, update the Source Provider with the 48 value of directives that may have been found in the script. 49 1 50 2015-10-15 Filip Pizlo <[email protected]> 2 51 -
trunk/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp
r182829 r191135 167 167 } 168 168 169 static String scriptCommentPattern(const String& name)170 {171 // "//# <name>=<value>" and deprecated "//@"172 return "//[#@][\040\t]" + name + "=[\040\t]*([^\\s\'\"]*)[\040\t]*$";173 }174 175 169 static String stylesheetCommentPattern(const String& name) 176 170 { … … 200 194 } 201 195 202 String findScriptSourceURL(const String& content)203 {204 return findMagicComment(content, scriptCommentPattern(ASCIILiteral("sourceURL")));205 }206 207 String findScriptSourceMapURL(const String& content)208 {209 return findMagicComment(content, scriptCommentPattern(ASCIILiteral("sourceMappingURL")));210 }211 212 196 String findStylesheetSourceMapURL(const String& content) 213 197 { -
trunk/Source/JavaScriptCore/inspector/ContentSearchUtilities.h
r178820 r191135 49 49 JS_EXPORT_PRIVATE std::unique_ptr<Vector<size_t>> lineEndings(const String&); 50 50 51 JS_EXPORT_PRIVATE String findScriptSourceURL(const String& content);52 JS_EXPORT_PRIVATE String findScriptSourceMapURL(const String& content);53 51 JS_EXPORT_PRIVATE String findStylesheetSourceMapURL(const String& content); 54 52 -
trunk/Source/JavaScriptCore/inspector/ScriptDebugServer.cpp
r190542 r191135 208 208 script.startColumn = sourceProvider->startPosition().m_column.zeroBasedInt(); 209 209 script.isContentScript = isContentScript; 210 script.sourceURL = sourceProvider->sourceURL(); 211 script.sourceMappingURL = sourceProvider->sourceMappingURL(); 210 212 211 213 int sourceLength = script.source.length(); -
trunk/Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp
r190542 r191135 605 605 String InspectorDebuggerAgent::sourceMapURLForScript(const Script& script) 606 606 { 607 return ContentSearchUtilities::findScriptSourceMapURL(script.source); 608 } 609 610 void InspectorDebuggerAgent::didParseSource(JSC::SourceID sourceID, const Script& inScript) 611 { 612 Script script = inScript; 613 if (script.startLine <= 0 && !script.startColumn) 614 script.sourceURL = ContentSearchUtilities::findScriptSourceURL(script.source); 615 script.sourceMappingURL = sourceMapURLForScript(script); 616 607 return script.sourceMappingURL; 608 } 609 610 void InspectorDebuggerAgent::didParseSource(JSC::SourceID sourceID, const Script& script) 611 { 617 612 bool hasSourceURL = !script.sourceURL.isEmpty(); 618 613 String scriptURL = hasSourceURL ? script.sourceURL : script.url; 619 614 bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr; 620 String* sourceMapURLParam = script.sourceMappingURL.isNull() ? nullptr : &script.sourceMappingURL; 615 String sourceMappingURL = sourceMapURLForScript(script); 616 String* sourceMapURLParam = sourceMappingURL.isNull() ? nullptr : &sourceMappingURL; 621 617 const bool* isContentScript = script.isContentScript ? &script.isContentScript : nullptr; 622 618 String scriptIDStr = String::number(sourceID); -
trunk/Source/JavaScriptCore/parser/Lexer.cpp
r189371 r191135 26 26 #include "Lexer.h" 27 27 28 #include "BuiltinNames.h" 29 #include "Identifier.h" 30 #include "JSCInlines.h" 28 31 #include "JSFunctionInlines.h" 29 30 #include "BuiltinNames.h"31 32 #include "JSGlobalObjectFunctions.h" 32 #include "Identifier.h" 33 #include "KeywordLookup.h" 34 #include "Lexer.lut.h" 33 35 #include "Nodes.h" 34 #include "JSCInlines.h" 35 #include <wtf/dtoa.h> 36 #include "Parser.h" 36 37 #include <ctype.h> 37 38 #include <limits.h> 38 39 #include <string.h> 39 40 #include <wtf/Assertions.h> 40 41 #include "KeywordLookup.h" 42 #include "Lexer.lut.h" 43 #include "Parser.h" 41 #include <wtf/dtoa.h> 44 42 45 43 namespace JSC { … … 566 564 m_lineStart = m_code; 567 565 m_lexErrorMessage = String(); 566 m_sourceURL = String(); 567 m_sourceMappingURL = String(); 568 568 569 569 m_buffer8.reserveInitialCapacity(initialReadBufferCapacity); … … 687 687 { 688 688 return m_lastToken == CONTINUE || m_lastToken == BREAK || m_lastToken == RETURN || m_lastToken == THROW; 689 } 690 691 template <typename T> 692 ALWAYS_INLINE void Lexer<T>::skipWhitespace() 693 { 694 while (isWhiteSpace(m_current)) 695 shift(); 689 696 } 690 697 … … 1706 1713 1707 1714 template <typename T> 1715 ALWAYS_INLINE void Lexer<T>::parseCommentDirective() 1716 { 1717 // sourceURL and sourceMappingURL directives. 1718 if (!consume("source")) 1719 return; 1720 1721 if (consume("URL=")) { 1722 if (!m_sourceURL.isEmpty()) 1723 return; 1724 m_sourceURL = parseCommentDirectiveValue(); 1725 return; 1726 } 1727 1728 if (consume("MappingURL=")) { 1729 if (!m_sourceMappingURL.isEmpty()) 1730 return; 1731 m_sourceMappingURL = parseCommentDirectiveValue(); 1732 return; 1733 } 1734 } 1735 1736 template <typename T> 1737 ALWAYS_INLINE String Lexer<T>::parseCommentDirectiveValue() 1738 { 1739 skipWhitespace(); 1740 const T* stringStart = currentSourcePtr(); 1741 while (!isWhiteSpace(m_current) && !isLineTerminator(m_current) && m_current != '"' && m_current != '\'' && !atEnd()) 1742 shift(); 1743 const T* stringEnd = currentSourcePtr(); 1744 skipWhitespace(); 1745 1746 if (!isLineTerminator(m_current) && !atEnd()) 1747 return String(); 1748 1749 append8(stringStart, stringEnd - stringStart); 1750 return String(m_buffer8.data(), m_buffer8.size()); 1751 } 1752 1753 template <typename T> 1754 template <unsigned length> 1755 ALWAYS_INLINE bool Lexer<T>::consume(const char (&input)[length]) 1756 { 1757 unsigned lengthToCheck = length - 1; // Ignore the ending NUL byte in the string literal. 1758 1759 unsigned i = 0; 1760 for (; i < lengthToCheck && m_current == input[i]; i++) 1761 shift(); 1762 1763 return i == lengthToCheck; 1764 } 1765 1766 template <typename T> 1708 1767 bool Lexer<T>::nextTokenIsColon() 1709 1768 { … … 1740 1799 1741 1800 start: 1742 while (isWhiteSpace(m_current)) 1743 shift(); 1801 skipWhitespace(); 1744 1802 1745 1803 if (atEnd()) … … 1899 1957 if (m_current == '/') { 1900 1958 shift(); 1901 goto inSingleLineComment ;1959 goto inSingleLineCommentCheckForDirectives; 1902 1960 } 1903 1961 if (m_current == '*') { … … 2204 2262 goto returnToken; 2205 2263 2264 inSingleLineCommentCheckForDirectives: 2265 // Script comment directives like "//# sourceURL=test.js". 2266 if (UNLIKELY((m_current == '#' || m_current == '@') && isWhiteSpace(peek(1)))) { 2267 shift(); 2268 shift(); 2269 parseCommentDirective(); 2270 } 2271 // Fall through to complete single line comment parsing. 2272 2206 2273 inSingleLineComment: 2207 2274 while (!isLineTerminator(m_current)) { -
trunk/Source/JavaScriptCore/parser/Lexer.h
r188824 r191135 89 89 bool sawError() const { return m_error; } 90 90 String getErrorMessage() const { return m_lexErrorMessage; } 91 String sourceURL() const { return m_sourceURL; } 92 String sourceMappingURL() const { return m_sourceMappingURL; } 91 93 void clear(); 92 94 void setOffset(int offset, int lineStartOffset) … … 114 116 m_terminator = terminator; 115 117 } 116 117 SourceProvider* sourceProvider() const { return m_source->provider(); }118 118 119 119 JSTokenType lexExpectIdentifier(JSToken*, unsigned, bool strictMode); … … 153 153 154 154 ALWAYS_INLINE bool lastTokenWasRestrKeyword() const; 155 156 ALWAYS_INLINE void skipWhitespace(); 155 157 156 158 template <int shiftAmount> void internalShift(); … … 178 180 ALWAYS_INLINE bool parseNumberAfterExponentIndicator(); 179 181 ALWAYS_INLINE bool parseMultilineComment(); 182 183 ALWAYS_INLINE void parseCommentDirective(); 184 ALWAYS_INLINE String parseCommentDirectiveValue(); 185 186 template <unsigned length> 187 ALWAYS_INLINE bool consume(const char (&input)[length]); 180 188 181 189 static const size_t initialReadBufferCapacity = 32; … … 204 212 String m_lexErrorMessage; 205 213 214 String m_sourceURL; 215 String m_sourceMappingURL; 216 206 217 T m_current; 207 218 -
trunk/Source/JavaScriptCore/parser/Parser.h
r190188 r191135 1330 1330 result->setLoc(m_source->firstLine(), m_lexer->lineNumber(), m_lexer->currentOffset(), m_lexer->currentLineStartOffset()); 1331 1331 result->setEndOffset(m_lexer->currentOffset()); 1332 1333 m_source->provider()->setSourceURL(m_lexer->sourceURL()); 1334 m_source->provider()->setSourceMappingURL(m_lexer->sourceMappingURL()); 1332 1335 } else { 1333 1336 // We can never see a syntax error when reparsing a function, since we should have -
trunk/Source/JavaScriptCore/parser/SourceProvider.h
r187677 r191135 50 50 } 51 51 52 const String& url() { return m_url; } 52 const String& url() const { return m_url; } 53 const String& sourceURL() const { return m_sourceURL; } 54 const String& sourceMappingURL() const { return m_sourceMappingURL; } 55 53 56 TextPosition startPosition() const { return m_startPosition; } 54 57 intptr_t asID() … … 63 66 64 67 private: 68 template <typename T> friend class Parser; 69 70 void setSourceURL(const String& sourceURL) { m_sourceURL = sourceURL; } 71 void setSourceMappingURL(const String& sourceMappingURL) { m_sourceMappingURL = sourceMappingURL; } 65 72 66 73 JS_EXPORT_PRIVATE void getID(); … … 68 75 69 76 String m_url; 77 String m_sourceURL; 78 String m_sourceMappingURL; 70 79 TextPosition m_startPosition; 71 80 bool m_validated : 1; -
trunk/Source/WebInspectorUI/ChangeLog
r191071 r191135 1 2015-10-15 Joseph Pecoraro <[email protected]> 2 3 Web Inspector: JavaScriptCore should parse sourceURL and sourceMappingURL directives 4 https://bugs.webkit.org/show_bug.cgi?id=150096 5 6 Reviewed by Geoffrey Garen. 7 8 * UserInterface/Test/InspectorProtocol.js: 9 (InspectorProtocol._sendMessage): 10 (InspectorProtocol.dispatchMessageFromBackend): 11 This is only used for tests, so avoid console.log 12 and just dump directly to the system console. 13 1 14 2015-10-13 João Oliveira <[email protected]> 2 15 -
trunk/Source/WebInspectorUI/UserInterface/Test/InspectorProtocol.js
r190191 r191135 90 90 91 91 if (ProtocolTest.dumpInspectorProtocolMessages) 92 console.log(`frontend: ${messageString}`);92 InspectorFrontendHost.unbufferedLog(`frontend: ${messageString}`); 93 93 94 94 InspectorFrontendHost.sendMessageToBackend(messageString); … … 135 135 // by InspectorProtocol. Return messages should be dumped by InspectorBackend. 136 136 if (ProtocolTest.dumpInspectorProtocolMessages) 137 console.log("backend: " + JSON.stringify(messageObject));137 InspectorFrontendHost.unbufferedLog("backend: " + JSON.stringify(messageObject)); 138 138 139 139 // If the message has an id, then it is a reply to a command.
Note:
See TracChangeset
for help on using the changeset viewer.