Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (88093 => 88094)
--- trunk/Source/_javascript_Core/ChangeLog 2011-06-04 05:25:01 UTC (rev 88093)
+++ trunk/Source/_javascript_Core/ChangeLog 2011-06-04 06:15:43 UTC (rev 88094)
@@ -1,3 +1,23 @@
+2011-06-03 Oliver Hunt <[email protected]>
+
+ 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 <[email protected]>
Reviewed by Sam Weinig.
Modified: trunk/Source/_javascript_Core/KeywordLookupGenerator.py (88093 => 88094)
--- trunk/Source/_javascript_Core/KeywordLookupGenerator.py 2011-06-04 05:25:01 UTC (rev 88093)
+++ trunk/Source/_javascript_Core/KeywordLookupGenerator.py 2011-06-04 06:15:43 UTC (rev 88094)
@@ -127,6 +127,8 @@
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 @@
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)
Modified: trunk/Source/_javascript_Core/parser/Lexer.cpp (88093 => 88094)
--- trunk/Source/_javascript_Core/parser/Lexer.cpp 2011-06-04 05:25:01 UTC (rev 88093)
+++ trunk/Source/_javascript_Core/parser/Lexer.cpp 2011-06-04 06:15:43 UTC (rev 88094)
@@ -414,9 +414,11 @@
{
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;
Modified: trunk/Source/_javascript_Core/parser/Lexer.h (88093 => 88094)
--- trunk/Source/_javascript_Core/parser/Lexer.h 2011-06-04 05:25:01 UTC (rev 88093)
+++ trunk/Source/_javascript_Core/parser/Lexer.h 2011-06-04 06:15:43 UTC (rev 88094)
@@ -115,7 +115,7 @@
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);
Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.cpp (88093 => 88094)
--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.cpp 2011-06-04 05:25:01 UTC (rev 88093)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.cpp 2011-06-04 06:15:43 UTC (rev 88094)
@@ -26,6 +26,7 @@
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 @@
, 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)
{
}
Modified: trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h (88093 => 88094)
--- trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2011-06-04 05:25:01 UTC (rev 88093)
+++ trunk/Source/_javascript_Core/runtime/CommonIdentifiers.h 2011-06-04 06:15:43 UTC (rev 88094)
@@ -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 @@
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