Ignore:
Timestamp:
Oct 20, 2015, 1:48:49 PM (10 years ago)
Author:
Joseph Pecoraro
Message:

Web Inspector: JavaScriptCore should parse sourceURL and sourceMappingURL directives
https://bugs.webkit.org/show_bug.cgi?id=150096

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

  • inspector/ContentSearchUtilities.cpp:

(Inspector::ContentSearchUtilities::scriptCommentPattern): Deleted.
(Inspector::ContentSearchUtilities::findScriptSourceURL): Deleted.
(Inspector::ContentSearchUtilities::findScriptSourceMapURL): Deleted.

  • inspector/ContentSearchUtilities.h:

No longer need to search script content.

  • inspector/ScriptDebugServer.cpp:

(Inspector::ScriptDebugServer::dispatchDidParseSource):
Carry over the sourceURL and sourceMappingURL from the SourceProvider.

  • inspector/agents/InspectorDebuggerAgent.cpp:

(Inspector::InspectorDebuggerAgent::sourceMapURLForScript):
(Inspector::InspectorDebuggerAgent::didParseSource):
No longer do content searching.

  • parser/Lexer.cpp:

(JSC::Lexer<T>::setCode):
(JSC::Lexer<T>::skipWhitespace):
(JSC::Lexer<T>::parseCommentDirective):
(JSC::Lexer<T>::parseCommentDirectiveValue):
(JSC::Lexer<T>::consume):
(JSC::Lexer<T>::lex):

  • parser/Lexer.h:

(JSC::Lexer::sourceURL):
(JSC::Lexer::sourceMappingURL):
(JSC::Lexer::sourceProvider): Deleted.
Give lexer the ability to detect script comment directives.
This just consumes characters in single line comments and
ultimately sets the sourceURL or sourceMappingURL found.

  • parser/Parser.h:

(JSC::Parser<LexerType>::parse):

  • parser/SourceProvider.h:

(JSC::SourceProvider::url):
(JSC::SourceProvider::sourceURL):
(JSC::SourceProvider::sourceMappingURL):
(JSC::SourceProvider::setSourceURL):
(JSC::SourceProvider::setSourceMappingURL):
After parsing a script, update the Source Provider with the
value of directives that may have been found in the script.

Source/WebInspectorUI:

  • UserInterface/Test/InspectorProtocol.js:

(InspectorProtocol._sendMessage):
(InspectorProtocol.dispatchMessageFromBackend):
This is only used for tests, so avoid console.log
and just dump directly to the system console.

LayoutTests:

  • inspector/debugger/sourceURLs-expected.txt: Added.
  • inspector/debugger/sourceURLs.html: Added.

sourceURL and sourceMappingURL detection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r191145 r191355  
    2626#include "Lexer.h"
    2727
     28#include "BuiltinNames.h"
     29#include "Identifier.h"
     30#include "JSCInlines.h"
    2831#include "JSFunctionInlines.h"
    29 
    30 #include "BuiltinNames.h"
    3132#include "JSGlobalObjectFunctions.h"
    32 #include "Identifier.h"
     33#include "KeywordLookup.h"
     34#include "Lexer.lut.h"
    3335#include "Nodes.h"
    34 #include "JSCInlines.h"
    35 #include <wtf/dtoa.h>
     36#include "Parser.h"
    3637#include <ctype.h>
    3738#include <limits.h>
    3839#include <string.h>
    3940#include <wtf/Assertions.h>
    40 
    41 #include "KeywordLookup.h"
    42 #include "Lexer.lut.h"
    43 #include "Parser.h"
     41#include <wtf/dtoa.h>
    4442
    4543namespace JSC {
     
    566564    m_lineStart = m_code;
    567565    m_lexErrorMessage = String();
     566    m_sourceURLDirective = String();
     567    m_sourceMappingURLDirective = String();
    568568   
    569569    m_buffer8.reserveInitialCapacity(initialReadBufferCapacity);
     
    687687{
    688688    return m_lastToken == CONTINUE || m_lastToken == BREAK || m_lastToken == RETURN || m_lastToken == THROW;
     689}
     690
     691template <typename T>
     692ALWAYS_INLINE void Lexer<T>::skipWhitespace()
     693{
     694    while (isWhiteSpace(m_current))
     695        shift();
    689696}
    690697
     
    17061713
    17071714template <typename T>
     1715ALWAYS_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_sourceURLDirective.isEmpty())
     1723            return;
     1724        m_sourceURLDirective = parseCommentDirectiveValue();
     1725        return;
     1726    }
     1727
     1728    if (consume("MappingURL=")) {
     1729        if (!m_sourceMappingURLDirective.isEmpty())
     1730            return;
     1731        m_sourceMappingURLDirective = parseCommentDirectiveValue();
     1732        return;
     1733    }
     1734}
     1735
     1736template <typename T>
     1737ALWAYS_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    String result = String(m_buffer8.data(), m_buffer8.size());
     1751    m_buffer8.shrink(0);
     1752    return result;
     1753}
     1754
     1755template <typename T>
     1756template <unsigned length>
     1757ALWAYS_INLINE bool Lexer<T>::consume(const char (&input)[length])
     1758{
     1759    unsigned lengthToCheck = length - 1; // Ignore the ending NULL byte in the string literal.
     1760
     1761    unsigned i = 0;
     1762    for (; i < lengthToCheck && m_current == input[i]; i++)
     1763        shift();
     1764
     1765    return i == lengthToCheck;
     1766}
     1767
     1768template <typename T>
    17081769bool Lexer<T>::nextTokenIsColon()
    17091770{
     
    17401801
    17411802start:
    1742     while (isWhiteSpace(m_current))
    1743         shift();
     1803    skipWhitespace();
    17441804
    17451805    if (atEnd())
     
    18991959        if (m_current == '/') {
    19001960            shift();
    1901             goto inSingleLineComment;
     1961            goto inSingleLineCommentCheckForDirectives;
    19021962        }
    19031963        if (m_current == '*') {
     
    22042264    goto returnToken;
    22052265
     2266inSingleLineCommentCheckForDirectives:
     2267    // Script comment directives like "//# sourceURL=test.js".
     2268    if (UNLIKELY((m_current == '#' || m_current == '@') && isWhiteSpace(peek(1)))) {
     2269        shift();
     2270        shift();
     2271        parseCommentDirective();
     2272    }
     2273    // Fall through to complete single line comment parsing.
     2274
    22062275inSingleLineComment:
    22072276    while (!isLineTerminator(m_current)) {
Note: See TracChangeset for help on using the changeset viewer.