Changeset 89109 in webkit


Ignore:
Timestamp:
Jun 16, 2011 8:17:11 PM (13 years ago)
Author:
barraclough@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=53014
ES5 strict mode keyword restrictions aren't implemented

Reviewed by Oliver Hunt.

The following are future restricted words is strict mode code:

implements, interface, let, package, private, protected, public, static, yield

Source/JavaScriptCore:

  • parser/JSParser.h:
    • Add RESERVED_IF_STRICT token.
  • parser/Keywords.table:
    • Add new future restricted words.
  • parser/Lexer.cpp:

(JSC::Lexer::parseIdentifier):

  • Check for RESERVED_IF_STRICT; in nonstrict code this is converted to IDENT.

(JSC::Lexer::lex):

  • Pass strictMode flag to parseIdentifier.
  • parser/Lexer.h:
    • parseIdentifier needs a strictMode flag.
  • runtime/CommonIdentifiers.h:
    • Add identifiers for new reserved words.

LayoutTests:

  • fast/js/keywords-and-reserved_words-expected.txt: Added.
  • fast/js/keywords-and-reserved_words.html: Added.
  • fast/js/script-tests/keywords-and-reserved_words.js: Added.

(isKeyword):
(isStrictKeyword):
(classifyIdentifier):

Location:
trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r89108 r89109  
     12011-06-16  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=53014
     6        ES5 strict mode keyword restrictions aren't implemented
     7
     8        The following are future restricted words is strict mode code:
     9            implements, interface, let, package, private, protected, public, static, yield
     10
     11        * fast/js/keywords-and-reserved_words-expected.txt: Added.
     12        * fast/js/keywords-and-reserved_words.html: Added.
     13        * fast/js/script-tests/keywords-and-reserved_words.js: Added.
     14        (isKeyword):
     15        (isStrictKeyword):
     16        (classifyIdentifier):
     17
    1182011-06-16  Yuta Kitamura  <yutak@chromium.org>
    219
  • trunk/Source/JavaScriptCore/ChangeLog

    r89100 r89109  
     12011-06-16  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=53014
     6        ES5 strict mode keyword restrictions aren't implemented
     7
     8        The following are future restricted words is strict mode code:
     9            implements, interface, let, package, private, protected, public, static, yield
     10
     11        * parser/JSParser.h:
     12            - Add RESERVED_IF_STRICT token.
     13        * parser/Keywords.table:
     14            - Add new future restricted words.
     15        * parser/Lexer.cpp:
     16        (JSC::Lexer::parseIdentifier):
     17            - Check for RESERVED_IF_STRICT; in nonstrict code this is converted to IDENT.
     18        (JSC::Lexer::lex):
     19            - Pass strictMode flag to parseIdentifier.
     20        * parser/Lexer.h:
     21            - parseIdentifier needs a strictMode flag.
     22        * runtime/CommonIdentifiers.h:
     23            - Add identifiers for new reserved words.
     24
    1252011-06-16  Gavin Barraclough  <barraclough@apple.com>
    226
  • trunk/Source/JavaScriptCore/parser/JSParser.h

    r75408 r89109  
    6767    WITH,
    6868    RESERVED,
     69    RESERVED_IF_STRICT,
    6970    THROW,
    7071    TRY,
  • trunk/Source/JavaScriptCore/parser/Keywords.table

    r44224 r89109  
    11# main keywords
    2 @begin mainTable 41
     2@begin mainTable 47
    33
    44# types
     
    4444super           RESERVED
    4545
    46 # these words are reserved for future use in the ECMA spec, but not in WinIE
    47 # (see http://bugs.webkit.org/show_bug.cgi?id=6179)
    48 # abstract      RESERVED
    49 # boolean       RESERVED
    50 # byte          RESERVED
    51 # char          RESERVED
    52 # double        RESERVED
    53 # final         RESERVED
    54 # float         RESERVED
    55 # goto          RESERVED
    56 # implements    RESERVED
    57 # int           RESERVED
    58 # interface     RESERVED
    59 # long          RESERVED
    60 # native        RESERVED
    61 # package       RESERVED
    62 # private       RESERVED
    63 # protected     RESERVED
    64 # public        RESERVED
    65 # short         RESERVED
    66 # static        RESERVED
    67 # synchronized  RESERVED
    68 # throws        RESERVED
    69 # transient     RESERVED
    70 # volatile      RESERVED
     46# reserved for future use in strict code
     47implements      RESERVED_IF_STRICT
     48interface       RESERVED_IF_STRICT
     49let             RESERVED_IF_STRICT
     50package         RESERVED_IF_STRICT
     51private         RESERVED_IF_STRICT
     52protected       RESERVED_IF_STRICT
     53public          RESERVED_IF_STRICT
     54static          RESERVED_IF_STRICT
     55yield           RESERVED_IF_STRICT
     56
    7157@end
    7258
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r89100 r89109  
    406406}
    407407
    408 template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer::parseIdentifier(JSTokenData* tokenData, unsigned lexType)
     408template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer::parseIdentifier(JSTokenData* tokenData, unsigned lexType, bool strictMode)
    409409{
    410410    const ptrdiff_t remaining = m_codeEnd - m_code;
    411411    if ((remaining >= maxTokenLength) && !(lexType & IgnoreReservedWords)) {
    412412        JSTokenType keyword = parseKeyword<shouldCreateIdentifier>(tokenData);
    413         if (keyword != IDENT) {
     413        if (keyword != IDENT && (keyword != RESERVED_IF_STRICT || strictMode)) {
    414414            ASSERT((!shouldCreateIdentifier) || tokenData->ident);
    415415            return keyword;
     
    470470            const HashEntry* entry = m_keywordTable.entry(m_globalData, *ident);
    471471            ASSERT((remaining < maxTokenLength) || !entry);
    472             return entry ? static_cast<JSTokenType>(entry->lexerValue()) : IDENT;
     472            if (!entry)
     473                return IDENT;
     474            JSTokenType token = static_cast<JSTokenType>(entry->lexerValue());
     475            return (token != RESERVED_IF_STRICT) || strictMode ? token : IDENT;
    473476        }
    474477        return IDENT;
     
    10831086    case CharacterBackSlash:
    10841087        if (lexType & DontBuildKeywords)
    1085             token = parseIdentifier<false>(tokenData, lexType);
     1088            token = parseIdentifier<false>(tokenData, lexType, strictMode);
    10861089        else
    1087             token = parseIdentifier<true>(tokenData, lexType);
     1090            token = parseIdentifier<true>(tokenData, lexType, strictMode);
    10881091        break;
    10891092    case CharacterLineTerminator:
  • trunk/Source/JavaScriptCore/parser/Lexer.h

    r88974 r89109  
    119119        template <int shiftAmount, ShiftType shouldBoundsCheck> void internalShift();
    120120        template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType parseKeyword(JSTokenData*);
    121         template <bool shouldBuildIdentifiers> ALWAYS_INLINE JSTokenType parseIdentifier(JSTokenData*, unsigned);
     121        template <bool shouldBuildIdentifiers> ALWAYS_INLINE JSTokenType parseIdentifier(JSTokenData*, unsigned, bool strictMode);
    122122        template <bool shouldBuildStrings> ALWAYS_INLINE bool parseString(JSTokenData*, bool strictMode);
    123123        ALWAYS_INLINE void parseHex(double& returnValue);
  • trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h

    r88094 r89109  
    112112    macro(extends) \
    113113    macro(import) \
    114     macro(super)
     114    macro(super) \
     115    macro(implements) \
     116    macro(interface) \
     117    macro(let) \
     118    macro(package) \
     119    macro(private) \
     120    macro(protected) \
     121    macro(public) \
     122    macro(static) \
     123    macro(yield)
    115124
    116125namespace JSC {
Note: See TracChangeset for help on using the changeset viewer.