Commit 77099a66 authored by oliver@apple.com's avatar oliver@apple.com

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:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@88094 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 47e3ada3
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:
2011-06-03 Gavin Barraclough <barraclough@apple.com>
Reviewed by Sam Weinig.
......
......@@ -127,6 +127,8 @@ class Trie:
if self.value != None:
print(str + "if (!isIdentPart(code[%d])) {" % (len(self.fullPrefix)))
print(str + " internalShift<%d, DoNotBoundsCheck>();" % len(self.fullPrefix))
print(str + " if (shouldCreateIdentifier)")
print(str + (" data->ident = &m_globalData->propertyNames->%sKeyword;" % self.fullPrefix))
print(str + " return " + self.value + ";")
print(str + "}")
rootIndex = len(self.fullPrefix)
......@@ -166,7 +168,7 @@ class Trie:
print("static ALWAYS_INLINE bool isIdentPart(int c);")
# max length + 1 so we don't need to do any bounds checking at all
print("static const int maxTokenLength = %d;" % (self.maxLength() + 1))
print("ALWAYS_INLINE JSTokenType Lexer::parseKeyword() {")
print("template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer::parseKeyword(JSTokenData* data) {")
print(" ASSERT(m_codeEnd - m_code >= maxTokenLength);")
print(" const UChar* code = m_code;")
self.printSubTreeAsC(4)
......
......@@ -414,9 +414,11 @@ template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType Lexer::parseIde
{
const ptrdiff_t remaining = m_codeEnd - m_code;
if ((remaining >= maxTokenLength) && !(lexType & IgnoreReservedWords)) {
JSTokenType keyword = parseKeyword();
if (keyword != IDENT)
JSTokenType keyword = parseKeyword<shouldCreateIdentifier>(lvalp);
if (keyword != IDENT) {
ASSERT((!shouldCreateIdentifier) || lvalp->ident);
return keyword;
}
}
const UChar* identifierStart = currentCharacter();
bool bufferRequired = false;
......
......@@ -115,7 +115,7 @@ namespace JSC {
enum ShiftType { DoBoundsCheck, DoNotBoundsCheck };
template <int shiftAmount, ShiftType shouldBoundsCheck> void internalShift();
ALWAYS_INLINE JSTokenType parseKeyword();
template <bool shouldCreateIdentifier> ALWAYS_INLINE JSTokenType parseKeyword(JSTokenData*);
template <bool shouldBuildIdentifiers> ALWAYS_INLINE JSTokenType parseIdentifier(JSTokenData*, unsigned);
template <bool shouldBuildStrings> ALWAYS_INLINE bool parseString(JSTokenData* lvalp, bool strictMode);
ALWAYS_INLINE void parseHex(double& returnValue);
......
......@@ -26,6 +26,7 @@ namespace JSC {
static const char* const nullCString = 0;
#define INITIALIZE_PROPERTY_NAME(name) , name(globalData, #name)
#define INITIALIZE_KEYWORD(name) , name##Keyword(globalData, #name)
CommonIdentifiers::CommonIdentifiers(JSGlobalData* globalData)
: nullIdentifier(globalData, nullCString)
......@@ -33,6 +34,7 @@ CommonIdentifiers::CommonIdentifiers(JSGlobalData* globalData)
, underscoreProto(globalData, "__proto__")
, thisIdentifier(globalData, "this")
, useStrictIdentifier(globalData, "use strict")
JSC_COMMON_IDENTIFIERS_EACH_KEYWORD(INITIALIZE_KEYWORD)
JSC_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(INITIALIZE_PROPERTY_NAME)
{
}
......
......@@ -75,6 +75,44 @@
macro(writable) \
macro(displayName)
#define JSC_COMMON_IDENTIFIERS_EACH_KEYWORD(macro) \
macro(null) \
macro(true) \
macro(false) \
macro(break) \
macro(case) \
macro(catch) \
macro(const) \
macro(default) \
macro(finally) \
macro(for) \
macro(instanceof) \
macro(new) \
macro(var) \
macro(continue) \
macro(function) \
macro(return) \
macro(void) \
macro(delete) \
macro(if) \
macro(this) \
macro(do) \
macro(while) \
macro(else) \
macro(in) \
macro(switch) \
macro(throw) \
macro(try) \
macro(typeof) \
macro(with) \
macro(debugger) \
macro(class) \
macro(enum) \
macro(export) \
macro(extends) \
macro(import) \
macro(super)
namespace JSC {
class CommonIdentifiers {
......@@ -90,6 +128,11 @@ namespace JSC {
const Identifier thisIdentifier;
const Identifier useStrictIdentifier;
#define JSC_IDENTIFIER_DECLARE_KEYWORD_NAME_GLOBAL(name) const Identifier name##Keyword;
JSC_COMMON_IDENTIFIERS_EACH_KEYWORD(JSC_IDENTIFIER_DECLARE_KEYWORD_NAME_GLOBAL)
#undef JSC_IDENTIFIER_DECLARE_KEYWORD_NAME_GLOBAL
#define JSC_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL(name) const Identifier name;
JSC_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(JSC_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL)
#undef JSC_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment