Ignore:
Timestamp:
Jun 16, 2011, 8:17:11 PM (14 years ago)
Author:
[email protected]
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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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:
Note: See TracChangeset for help on using the changeset viewer.