Changeset 128542 in webkit for trunk/Source/JavaScriptCore/parser


Ignore:
Timestamp:
Sep 13, 2012, 6:50:17 PM (13 years ago)
Author:
[email protected]
Message:

Improve the SourceProvider hierarchy
https://bugs.webkit.org/show_bug.cgi?id=95635

Patch by Benjamin Poulain <[email protected]> on 2012-09-13
Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

SourceProvider was designed to have subclasses magically handling the data without
decoding all of it. The virtual methods length() and getRange() were based
on these assumptions.

In practice, the magic was in our head, there is no implementation that takes
advantage of that.

SourceProvider is modified to adopt WebCore's ScriptSourceProvider::source() and base
everything on it.
The code using SourceProvider is also simplified.

  • interpreter/Interpreter.cpp:

(JSC::appendSourceToError): Keep a reference to the string instead of querying it for
each time it is used.

  • parser/Lexer.cpp:

(JSC::::setCode):
(JSC::::sourceCode):

  • parser/Parser.h:

(JSC::parse):

  • parser/SourceCode.h:

(JSC::SourceCode::SourceCode):
(JSC::SourceCode::subExpression):

  • parser/SourceProvider.h:

(SourceProvider):
(JSC::SourceProvider::getRange):

Source/WebCore:

Get rid of ScriptSourceProvider and StringSourceProvider, they have been made
useless by JavaScript updates.

On x86_64, this reduces the binary size by 6kb.

  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/CachedScriptSourceProvider.h:

(WebCore::CachedScriptSourceProvider::CachedScriptSourceProvider):

  • bindings/js/ScriptDebugServer.cpp:

(WebCore::ScriptDebugServer::updateCurrentStatementPosition):
(WebCore::ScriptDebugServer::dispatchDidParseSource):
(WebCore::ScriptDebugServer::dispatchFailedToParseSource):

  • bindings/js/ScriptSourceCode.h:

(WebCore::ScriptSourceCode::ScriptSourceCode):
(ScriptSourceCode):

  • bindings/js/ScriptSourceProvider.h: Removed.
  • bindings/js/StringSourceProvider.h: Removed.
  • bindings/js/WorkerScriptController.cpp:
  • bindings/objc/WebScriptObject.mm:
  • bridge/NP_jsobject.cpp:
  • bridge/jni/jni_jsobject.mm:

Source/WebKit/mac:

  • Plugins/Hosted/NetscapePluginInstanceProxy.mm: Fix a #include abuse.
  • WebView/WebScriptDebugger.mm:

(toNSString): We can now use the (faster) implicit conversion
from String to NSString.

Location:
trunk/Source/JavaScriptCore/parser
Files:
4 edited

Legend:

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

    r127191 r128542  
    406406    m_lastToken = -1;
    407407   
    408     const StringImpl* sourceString = source.provider()->data();
    409 
    410     if (sourceString)
    411         setCodeStart(sourceString);
     408    const String& sourceString = source.provider()->source();
     409
     410    if (!sourceString.isNull())
     411        setCodeStart(sourceString.impl());
    412412    else
    413413        m_codeStart = 0;
     
    16901690SourceCode Lexer<T>::sourceCode(int openBrace, int closeBrace, int firstLine)
    16911691{
    1692     ASSERT((*m_source->provider()->data())[openBrace] == '{');
    1693     ASSERT((*m_source->provider()->data())[closeBrace] == '}');
     1692    ASSERT(m_source->provider()->source()[openBrace] == '{');
     1693    ASSERT(m_source->provider()->source()[closeBrace] == '}');
    16941694    return SourceCode(m_source->provider(), openBrace, closeBrace + 1, firstLine);
    16951695}
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r127958 r128542  
    10301030    SamplingRegion samplingRegion("Parsing");
    10311031
    1032     ASSERT(source.provider()->data());
    1033 
    1034     if (source.provider()->data()->is8Bit()) {
     1032    ASSERT(!source.provider()->source().isNull());
     1033
     1034    if (source.provider()->source().is8Bit()) {
    10351035        Parser< Lexer<LChar> > parser(globalData, source, parameters, name, strictness, parserMode);
    10361036        return parser.parse<ParsedNode>(lexicalGlobalObject, debugger, execState, exception);
  • trunk/Source/JavaScriptCore/parser/SourceCode.h

    r127191 r128542  
    4848            : m_provider(provider)
    4949            , m_startChar(0)
    50             , m_endChar(m_provider->length())
     50            , m_endChar(m_provider->source().length())
    5151            , m_firstLine(std::max(firstLine, 1))
    5252        {
     
    9898    inline SourceCode SourceCode::subExpression(unsigned openBrace, unsigned closeBrace, int firstLine)
    9999    {
    100         ASSERT((*provider()->data())[openBrace] == '{');
    101         ASSERT((*provider()->data())[closeBrace] == '}');
     100        ASSERT(provider()->source()[openBrace] == '{');
     101        ASSERT(provider()->source()[closeBrace] == '}');
    102102        return SourceCode(provider(), openBrace, closeBrace + 1, firstLine);
    103103    }
  • trunk/Source/JavaScriptCore/parser/SourceProvider.h

    r127191 r128542  
    11/*
    2  * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008, 2009, 2012 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5757        }
    5858
    59         virtual String getRange(int start, int end) const = 0;
    60         virtual const StringImpl* data() const = 0;
    61         virtual int length() const = 0;
    62        
     59        virtual const String& source() const = 0;
     60        String getRange(int start, int end) const
     61        {
     62            return source().substringSharingImpl(start, end - start);
     63        }
     64
    6365        const String& url() { return m_url; }
    6466        TextPosition startPosition() const { return m_startPosition; }
     
    9496        }
    9597
    96         virtual String getRange(int start, int end) const OVERRIDE
     98        virtual const String& source() const OVERRIDE
    9799        {
    98             return m_source.substringSharingImpl(start, end - start);
     100            return m_source;
    99101        }
    100         const StringImpl* data() const { return m_source.impl(); }
    101         int length() const { return m_source.length(); }
    102102
    103103    private:
Note: See TracChangeset for help on using the changeset viewer.