Changeset 62416 in webkit for trunk/JavaScriptCore/parser


Ignore:
Timestamp:
Jul 2, 2010, 4:49:07 PM (15 years ago)
Author:
[email protected]
Message:

2010-07-02 Sheriff Bot <[email protected]>

Unreviewed, rolling out r62410.
http://trac.webkit.org/changeset/62410
https://bugs.webkit.org/show_bug.cgi?id=41549

accursed last minute changes (Requested by olliej on #webkit).

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

2010-07-02 Sheriff Bot <[email protected]>

Unreviewed, rolling out r62410.
http://trac.webkit.org/changeset/62410
https://bugs.webkit.org/show_bug.cgi?id=41549

accursed last minute changes (Requested by olliej on #webkit).

  • 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:
Location:
trunk/JavaScriptCore/parser
Files:
2 edited

Legend:

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

    r62410 r62416  
    4646namespace JSC {
    4747
     48static const UChar byteOrderMark = 0xFEFF;
    4849
    4950enum CharacterTypes {
     
    256257    m_buffer16.reserveInitialCapacity((m_codeEnd - m_code) / 2);
    257258
     259    // ECMA-262 calls for stripping all Cf characters, but we only strip BOM characters.
     260    // See <https://bugs.webkit.org/show_bug.cgi?id=4931> for details.
     261    if (source.provider()->hasBOMs()) {
     262        for (const UChar* p = m_codeStart; p < m_codeEnd; ++p) {
     263            if (UNLIKELY(*p == byteOrderMark)) {
     264                copyCodeWithoutBOMs();
     265                break;
     266            }
     267        }
     268    }
     269
    258270    if (LIKELY(m_code < m_codeEnd))
    259271        m_current = *m_code;
     
    261273        m_current = -1;
    262274    ASSERT(currentOffset() == source.startOffset());
     275}
     276
     277void Lexer::copyCodeWithoutBOMs()
     278{
     279    // Note: In this case, the character offset data for debugging will be incorrect.
     280    // If it's important to correctly debug code with extraneous BOMs, then the caller
     281    // should strip the BOMs when creating the SourceProvider object and do its own
     282    // mapping of offsets within the stripped text to original text offset.
     283
     284    m_codeWithoutBOMs.reserveCapacity(m_codeEnd - m_code);
     285    for (const UChar* p = m_code; p < m_codeEnd; ++p) {
     286        UChar c = *p;
     287        if (c != byteOrderMark)
     288            m_codeWithoutBOMs.append(c);
     289    }
     290    ptrdiff_t startDelta = m_codeStart - m_code;
     291    m_code = m_codeWithoutBOMs.data();
     292    m_codeStart = m_code + startDelta;
     293    m_codeEnd = m_codeWithoutBOMs.data() + m_codeWithoutBOMs.size();
    263294}
    264295
     
    11501181SourceCode Lexer::sourceCode(int openBrace, int closeBrace, int firstLine)
    11511182{
     1183    if (m_codeWithoutBOMs.isEmpty())
     1184        return SourceCode(m_source->provider(), openBrace, closeBrace + 1, firstLine);
     1185
     1186    const UChar* data = m_source->provider()->data();
     1187   
     1188    ASSERT(openBrace < closeBrace);
     1189    int i;
     1190    for (i = m_source->startOffset(); i < openBrace; ++i) {
     1191        if (data[i] == byteOrderMark) {
     1192            openBrace++;
     1193            closeBrace++;
     1194        }
     1195    }
     1196    for (; i < closeBrace; ++i) {
     1197        if (data[i] == byteOrderMark)
     1198            closeBrace++;
     1199    }
     1200
     1201    ASSERT(openBrace < closeBrace);
     1202
    11521203    return SourceCode(m_source->provider(), openBrace, closeBrace + 1, firstLine);
    11531204}
  • trunk/JavaScriptCore/parser/SourceProvider.h

    r62410 r62416  
    3535namespace JSC {
    3636
     37    enum SourceBOMPresence { SourceHasNoBOMs, SourceCouldHaveBOMs };
     38
    3739    class SourceProvider : public RefCounted<SourceProvider> {
    3840    public:
    39         SourceProvider(const UString& url)
     41        SourceProvider(const UString& url, SourceBOMPresence hasBOMs = SourceCouldHaveBOMs)
    4042            : m_url(url)
     43            , m_hasBOMs(hasBOMs)
    4144        {
    4245        }
     
    5053        intptr_t asID() { return reinterpret_cast<intptr_t>(this); }
    5154
     55        SourceBOMPresence hasBOMs() const { return m_hasBOMs; }
     56
    5257    private:
    5358        UString m_url;
     59        SourceBOMPresence m_hasBOMs;
    5460    };
    5561
    5662    class UStringSourceProvider : public SourceProvider {
    5763    public:
    58         static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url, bool hasBOMs = true)
     64        static PassRefPtr<UStringSourceProvider> create(const UString& source, const UString& url)
    5965        {
    60             return adoptRef(new UStringSourceProvider(source, url, hasBOMs));
     66            return adoptRef(new UStringSourceProvider(source, url));
    6167        }
    6268
    63         UString getRange(int start, int end) const
    64         {
    65             return m_source.substr(start, end - start);
    66         }
     69        UString getRange(int start, int end) const { return m_source.substr(start, end - start); }
    6770        const UChar* data() const { return m_source.data(); }
    6871        int length() const { return m_source.size(); }
    6972
    7073    private:
    71         UStringSourceProvider(const UString& source, const UString& url, bool hasBOMs)
     74        UStringSourceProvider(const UString& source, const UString& url)
    7275            : SourceProvider(url)
    7376            , m_source(source)
    7477        {
    75             if (hasBOMs && m_source.size()) {
    76                 bool scratch = false;
    77                 m_source = UString(m_source.rep()->copyStringWithoutBOMs(false, scratch));
    78             }
    7978        }
    8079
Note: See TracChangeset for help on using the changeset viewer.