Ignore:
Timestamp:
Jul 2, 2010, 3:31:40 PM (15 years ago)
Author:
[email protected]
Message:

2010-07-02 Oliver Hunt <[email protected]>

Reviewed by Geoffrey Garen.

Move BOM handling out of the lexer and parser
https://bugs.webkit.org/show_bug.cgi?id=41539

Doing the BOM stripping in the lexer meant that we could
end up having to strip the BOMs from a source multiple times.
To deal with this we now require all strings provided by
a SourceProvider to already have had the BOMs stripped.
This also simplifies some of the lexer logic.

  • parser/Lexer.cpp: (JSC::Lexer::setCode): (JSC::Lexer::sourceCode):
  • parser/SourceProvider.h: (JSC::SourceProvider::SourceProvider): (JSC::UStringSourceProvider::create): (JSC::UStringSourceProvider::getRange): (JSC::UStringSourceProvider::UStringSourceProvider):
  • wtf/text/StringImpl.h: (WebCore::StringImpl::copyStringWithoutBOMs):

2010-07-02 Oliver Hunt <[email protected]>

Reviewed by Geoffrey Garen.

Move BOM handling out of the lexer and parser
https://bugs.webkit.org/show_bug.cgi?id=41539

Update WebCore to ensure that SourceProviders don't
produce strings with BOMs in them.

  • bindings/js/ScriptSourceProvider.h: (WebCore::ScriptSourceProvider::ScriptSourceProvider):
  • bindings/js/StringSourceProvider.h: (WebCore::StringSourceProvider::StringSourceProvider):
  • loader/CachedScript.cpp: (WebCore::CachedScript::CachedScript): (WebCore::CachedScript::script):
  • loader/CachedScript.h: (WebCore::CachedScript::): CachedScript now stores decoded data with the BOMs stripped, and caches the presence of BOMs across memory purges.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/parser/SourceProvider.h

    r44224 r62410  
    3535namespace JSC {
    3636
    37     enum SourceBOMPresence { SourceHasNoBOMs, SourceCouldHaveBOMs };
    38 
    3937    class SourceProvider : public RefCounted<SourceProvider> {
    4038    public:
    41         SourceProvider(const UString& url, SourceBOMPresence hasBOMs = SourceCouldHaveBOMs)
     39        SourceProvider(const UString& url)
    4240            : m_url(url)
    43             , m_hasBOMs(hasBOMs)
    4441        {
    4542        }
     
    5350        intptr_t asID() { return reinterpret_cast<intptr_t>(this); }
    5451
    55         SourceBOMPresence hasBOMs() const { return m_hasBOMs; }
    56 
    5752    private:
    5853        UString m_url;
    59         SourceBOMPresence m_hasBOMs;
    6054    };
    6155
    6256    class UStringSourceProvider : public SourceProvider {
    6357    public:
    64         static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url)
     58        static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url, bool hasBOMs = true)
    6559        {
    66             return adoptRef(new UStringSourceProvider(source, url));
     60            return adoptRef(new UStringSourceProvider(source, url, hasBOMs));
    6761        }
    6862
    69         UString getRange(int start, int end) const { return m_source.substr(start, end - start); }
     63        UString getRange(int start, int end) const
     64        {
     65            return m_source.substr(start, end - start);
     66        }
    7067        const UChar* data() const { return m_source.data(); }
    7168        int length() const { return m_source.size(); }
    7269
    7370    private:
    74         UStringSourceProvider(const UString& source, const UString& url)
     71        UStringSourceProvider(const UString& source, const UString& url, bool hasBOMs)
    7572            : SourceProvider(url)
    7673            , m_source(source)
    7774        {
     75            if (hasBOMs && m_source.size()) {
     76                bool scratch = false;
     77                m_source = UString(m_source.rep()->copyStringWithoutBOMs(false, scratch));
     78            }
    7879        }
    7980
Note: See TracChangeset for help on using the changeset viewer.