Ignore:
Timestamp:
Nov 7, 2011, 9:54:15 AM (14 years ago)
Author:
[email protected]
Message:

Towards 8 Bit Strings: Templatize JSC::Lexer class by character type
https://bugs.webkit.org/show_bug.cgi?id=71331

Source/JavaScriptCore:

Change the Lexer class to be a template class based on the character
type of the source. In the process updated the parseIdentifier()
and parseString() methods to create 8 bit strings where possible.
Also added some helper methods for accumulating temporary string
data in the 8 and 16 bit vectors.

Changed the SourceProvider::data() virtual method to return a
StringImpl* instead of a UChar*.

Updated the KeywordLookup generator to create code to match keywords
for both 8 and 16 bit source strings.

Due to a compiler bug (<rdar://problem/10194295>) moved enum
definition outside of Lexer class declaration. Remove second enum
no longer needed.

Reviewed by Darin Adler.

  • KeywordLookupGenerator.py:
  • interpreter/Interpreter.cpp:

(JSC::Interpreter::callEval):

  • parser/Lexer.cpp:

(JSC::::Lexer):
(JSC::::~Lexer):
(JSC::::getInvalidCharMessage):
(JSC::::currentCharacter):
(JSC::::setCode):
(JSC::::internalShift):
(JSC::::shift):
(JSC::::peek):
(JSC::::getUnicodeCharacter):
(JSC::::shiftLineTerminator):
(JSC::::lastTokenWasRestrKeyword):
(JSC::::record8):
(JSC::::append8):
(JSC::::append16):
(JSC::::record16):
(JSC::::parseIdentifier):
(JSC::::parseIdentifierSlowCase):
(JSC::::parseString):
(JSC::::parseStringSlowCase):
(JSC::::parseHex):
(JSC::::parseOctal):
(JSC::::parseDecimal):
(JSC::::parseNumberAfterDecimalPoint):
(JSC::::parseNumberAfterExponentIndicator):
(JSC::::parseMultilineComment):
(JSC::::nextTokenIsColon):
(JSC::::lex):
(JSC::::scanRegExp):
(JSC::::skipRegExp):
(JSC::::clear):
(JSC::::sourceCode):

  • parser/Lexer.h:

(JSC::Lexer::append16):
(JSC::Lexer::currentOffset):
(JSC::Lexer::setOffsetFromCharOffset):
(JSC::::isWhiteSpace):
(JSC::::isLineTerminator):
(JSC::::convertHex):
(JSC::::convertUnicode):
(JSC::::makeIdentifier):
(JSC::::setCodeStart):
(JSC::::makeIdentifierLCharFromUChar):
(JSC::::lexExpectIdentifier):

  • parser/Parser.cpp:

(JSC::Parser::Parser):
(JSC::Parser::parseProperty):
(JSC::Parser::parseMemberExpression):

  • parser/Parser.h:

(JSC::Parser::next):
(JSC::Parser::nextExpectIdentifier):

  • parser/ParserArena.h:

(JSC::IdentifierArena::makeIdentifier):
(JSC::IdentifierArena::makeIdentifierLCharFromUChar):

  • parser/SourceCode.h:

(JSC::SourceCode::subExpression):

  • parser/SourceProvider.h:

(JSC::UStringSourceProvider::stringData):

  • parser/SourceProviderCache.h:
  • parser/SyntaxChecker.h:
  • runtime/FunctionPrototype.cpp:

(JSC::insertSemicolonIfNeeded):

  • runtime/Identifier.cpp:

(JSC::IdentifierTable::add):
(JSC::IdentifierLCharFromUCharTranslator::hash):
(JSC::IdentifierLCharFromUCharTranslator::equal):
(JSC::IdentifierLCharFromUCharTranslator::translate):
(JSC::Identifier::add8):

  • runtime/Identifier.h:

(JSC::Identifier::Identifier):
(JSC::Identifier::createLCharFromUChar):
(JSC::Identifier::canUseSingleCharacterString):
(JSC::IdentifierCharBufferTranslator::hash):
(JSC::IdentifierCharBufferTranslator::equal):
(JSC::IdentifierCharBufferTranslator::translate):
(JSC::Identifier::add):
(JSC::Identifier::equal):
(JSC::IdentifierTable::add):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::decode):
(JSC::parseIntOverflow):
(JSC::globalFuncUnescape):

  • runtime/JSGlobalObjectFunctions.h:

(JSC::parseIntOverflow):

  • runtime/LiteralParser.cpp:

(JSC::LiteralParser::tryJSONPParse):
(JSC::LiteralParser::Lexer::lexString):

  • wtf/text/StringImpl.h:

Source/WebCore:

Changed the SourceProvider::data() virtual method to return a
StringImpl* instead of a UChar*.
Changed Identifier() constructor to use JSGlobalData*.

Reviewed by Darin Adler.

No new tests - refactored SourceProvider class and sub-classes.

  • bindings/js/CachedScriptSourceProvider.h:

(WebCore::CachedScriptSourceProvider::stringData):

  • bindings/js/StringSourceProvider.h:

(WebCore::StringSourceProvider::stringData):

  • bridge/qt/qt_runtime.cpp:

(JSC::Bindings::convertQVariantToValue):

Source/WebKit/qt:

Changed Identifier() constructor to use JSGlobalData*.

Reviewed by Darin Adler.

  • Api/qwebframe.cpp:

(QWebFrame::addToJavaScriptWindowObject):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

    r97905 r99436  
    8686            int charLen = 0;
    8787            if (k <= len - 3 && isASCIIHexDigit(p[1]) && isASCIIHexDigit(p[2])) {
    88                 const char b0 = Lexer::convertHex(p[1], p[2]);
     88                const char b0 = Lexer<UChar>::convertHex(p[1], p[2]);
    8989                const int sequenceLen = UTF8SequenceLength(b0);
    9090                if (sequenceLen != 0 && k <= len - sequenceLen * 3) {
     
    9595                        const UChar* q = p + i * 3;
    9696                        if (q[0] == '%' && isASCIIHexDigit(q[1]) && isASCIIHexDigit(q[2]))
    97                             sequence[i] = Lexer::convertHex(q[1], q[2]);
     97                            sequence[i] = Lexer<UChar>::convertHex(q[1], q[2]);
    9898                        else {
    9999                            charLen = 0;
     
    124124                        && isASCIIHexDigit(p[4]) && isASCIIHexDigit(p[5])) {
    125125                    charLen = 6;
    126                     u = Lexer::convertUnicode(p[2], p[3], p[4], p[5]);
     126                    u = Lexer<UChar>::convertUnicode(p[2], p[3], p[4], p[5]);
    127127                }
    128128            }
     
    174174}
    175175
    176 double parseIntOverflow(const char* s, int length, int radix)
     176double parseIntOverflow(const LChar* s, int length, int radix)
    177177{
    178178    double number = 0.0;
    179179    double radixMultiplier = 1.0;
    180180
    181     for (const char* p = s + length - 1; p >= s; p--) {
     181    for (const LChar* p = s + length - 1; p >= s; p--) {
    182182        if (radixMultiplier == std::numeric_limits<double>::infinity()) {
    183183            if (*p != '0') {
     
    579579        if (c[0] == '%' && k <= len - 6 && c[1] == 'u') {
    580580            if (isASCIIHexDigit(c[2]) && isASCIIHexDigit(c[3]) && isASCIIHexDigit(c[4]) && isASCIIHexDigit(c[5])) {
    581                 u = Lexer::convertUnicode(c[2], c[3], c[4], c[5]);
     581                u = Lexer<UChar>::convertUnicode(c[2], c[3], c[4], c[5]);
    582582                c = &u;
    583583                k += 5;
    584584            }
    585585        } else if (c[0] == '%' && k <= len - 3 && isASCIIHexDigit(c[1]) && isASCIIHexDigit(c[2])) {
    586             u = UChar(Lexer::convertHex(c[1], c[2]));
     586            u = UChar(Lexer<UChar>::convertHex(c[1], c[2]));
    587587            c = &u;
    588588            k += 2;
Note: See TracChangeset for help on using the changeset viewer.