Changeset 88094 in webkit


Ignore:
Timestamp:
Jun 3, 2011 11:15:43 PM (13 years ago)
Author:
oliver@apple.com
Message:

2011-06-03 Oliver Hunt <oliver@apple.com>

Reviewed by Maciej Stachowiak.

Lexer needs to provide Identifier for reserved words
https://bugs.webkit.org/show_bug.cgi?id=62086

Alas it is necessary to provide an Identifier reference for keywords
so that we can do the right thing when they're used in object literals.
We now keep Identifiers for all reserved words in the CommonIdentifiers
structure so that we can access them without a hash lookup.

  • KeywordLookupGenerator.py:
  • parser/Lexer.cpp: (JSC::Lexer::parseIdentifier):
  • parser/Lexer.h:
  • runtime/CommonIdentifiers.cpp: (JSC::CommonIdentifiers::CommonIdentifiers):
  • runtime/CommonIdentifiers.h:
Location:
trunk/Source/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r88093 r88094  
     12011-06-03  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Lexer needs to provide Identifier for reserved words
     6        https://bugs.webkit.org/show_bug.cgi?id=62086
     7
     8        Alas it is necessary to provide an Identifier reference for keywords
     9        so that we can do the right thing when they're used in object literals.
     10        We now keep Identifiers for all reserved words in the CommonIdentifiers
     11        structure so that we can access them without a hash lookup.
     12
     13        * KeywordLookupGenerator.py:
     14        * parser/Lexer.cpp:
     15        (JSC::Lexer::parseIdentifier):
     16        * parser/Lexer.h:
     17        * runtime/CommonIdentifiers.cpp:
     18        (JSC::CommonIdentifiers::CommonIdentifiers):
     19        * runtime/CommonIdentifiers.h:
     20
    1212011-06-03  Gavin Barraclough  <barraclough@apple.com>
    222
  • trunk/Source/JavaScriptCore/KeywordLookupGenerator.py

    r88083 r88094  
    128128            print(str + "if (!isIdentPart(code[%d])) {" % (len(self.fullPrefix)))
    129129            print(str + "    internalShift<%d, DoNotBoundsCheck>();" % len(self.fullPrefix))
     130            print(str + "    if (shouldCreateIdentifier)")
     131            print(str + ("        data->ident = &m_globalData->propertyNames->%sKeyword;" % self.fullPrefix))
    130132            print(str + "    return " + self.value + ";")
    131133            print(str + "}")
     
    167169        # max length + 1 so we don't need to do any bounds checking at all
    168170        print("static const int maxTokenLength = %d;" % (self.maxLength() + 1))
    169         print("ALWAYS_INLINE JSTokenType Lexer::parseKeyword() {")
     171        print("template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer::parseKeyword(JSTokenData* data) {")
    170172        print("    ASSERT(m_codeEnd - m_code >= maxTokenLength);")
    171173        print("    const UChar* code = m_code;")
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r88083 r88094  
    415415    const ptrdiff_t remaining = m_codeEnd - m_code;
    416416    if ((remaining >= maxTokenLength) && !(lexType & IgnoreReservedWords)) {
    417         JSTokenType keyword = parseKeyword();
    418         if (keyword != IDENT)
     417        JSTokenType keyword = parseKeyword<shouldCreateIdentifier>(lvalp);
     418        if (keyword != IDENT) {
     419            ASSERT((!shouldCreateIdentifier) || lvalp->ident);
    419420            return keyword;
     421        }
    420422    }
    421423    const UChar* identifierStart = currentCharacter();
  • trunk/Source/JavaScriptCore/parser/Lexer.h

    r88084 r88094  
    116116        enum ShiftType { DoBoundsCheck, DoNotBoundsCheck };
    117117        template <int shiftAmount, ShiftType shouldBoundsCheck> void internalShift();
    118         ALWAYS_INLINE JSTokenType parseKeyword();
     118        template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType parseKeyword(JSTokenData*);
    119119        template <bool shouldBuildIdentifiers> ALWAYS_INLINE JSTokenType parseIdentifier(JSTokenData*, unsigned);
    120120        template <bool shouldBuildStrings> ALWAYS_INLINE bool parseString(JSTokenData* lvalp, bool strictMode);
  • trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.cpp

    r69516 r88094  
    2727
    2828#define INITIALIZE_PROPERTY_NAME(name) , name(globalData, #name)
     29#define INITIALIZE_KEYWORD(name) , name##Keyword(globalData, #name)
    2930
    3031CommonIdentifiers::CommonIdentifiers(JSGlobalData* globalData)
     
    3435    , thisIdentifier(globalData, "this")
    3536    , useStrictIdentifier(globalData, "use strict")
     37    JSC_COMMON_IDENTIFIERS_EACH_KEYWORD(INITIALIZE_KEYWORD)
    3638    JSC_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(INITIALIZE_PROPERTY_NAME)
    3739{
  • trunk/Source/JavaScriptCore/runtime/CommonIdentifiers.h

    r80378 r88094  
    7676    macro(displayName)
    7777
     78#define JSC_COMMON_IDENTIFIERS_EACH_KEYWORD(macro) \
     79    macro(null) \
     80    macro(true) \
     81    macro(false) \
     82    macro(break) \
     83    macro(case) \
     84    macro(catch) \
     85    macro(const) \
     86    macro(default) \
     87    macro(finally) \
     88    macro(for) \
     89    macro(instanceof) \
     90    macro(new) \
     91    macro(var) \
     92    macro(continue) \
     93    macro(function) \
     94    macro(return) \
     95    macro(void) \
     96    macro(delete) \
     97    macro(if) \
     98    macro(this) \
     99    macro(do) \
     100    macro(while) \
     101    macro(else) \
     102    macro(in) \
     103    macro(switch) \
     104    macro(throw) \
     105    macro(try) \
     106    macro(typeof) \
     107    macro(with) \
     108    macro(debugger) \
     109    macro(class) \
     110    macro(enum) \
     111    macro(export) \
     112    macro(extends) \
     113    macro(import) \
     114    macro(super)
     115
    78116namespace JSC {
    79117
     
    91129        const Identifier useStrictIdentifier;
    92130
     131       
     132#define JSC_IDENTIFIER_DECLARE_KEYWORD_NAME_GLOBAL(name) const Identifier name##Keyword;
     133        JSC_COMMON_IDENTIFIERS_EACH_KEYWORD(JSC_IDENTIFIER_DECLARE_KEYWORD_NAME_GLOBAL)
     134#undef JSC_IDENTIFIER_DECLARE_KEYWORD_NAME_GLOBAL
     135       
    93136#define JSC_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL(name) const Identifier name;
    94137        JSC_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(JSC_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL)
Note: See TracChangeset for help on using the changeset viewer.