Reviewers: fschneider,

Description:
Fix compile-problem in (currently) unused stand-alone preparser function.
Allow object initializers to define getters using string and number literals.

Please review this at http://codereview.chromium.org/5985010/

Affected files:
  M src/parser.cc
  M src/preparser-api.cc
  M src/preparser.h
  M src/preparser.cc


Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 03819eea0192d1fa3ec207c27a5bbebd2e9e0be3..a3948f0d56692dd5a2d0a14580463bf5c89cd244 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2996,8 +2996,15 @@ ObjectLiteral::Property* Parser::ParseObjectLiteralGetSet(bool is_getter,
   // We have already read the "get" or "set" keyword.
   Token::Value next = Next();
   // TODO(820): Allow NUMBER and STRING as well (and handle array indices).
-  if (next == Token::IDENTIFIER || Token::IsKeyword(next)) {
-    Handle<String> name = GetSymbol(CHECK_OK);
+  bool is_keyword = Token::IsKeyword(next);
+  if (next == Token::IDENTIFIER || next == Token::NUMBER ||
+      next == Token::STRING || is_keyword) {
+    Handle<String> name;
+    if (is_keyword) {
+      name = Factory::LookupAsciiSymbol(Token::String(next));
+    } else {
+      name = GetSymbol(CHECK_OK);
+    }
     FunctionLiteral* value =
         ParseFunctionLiteral(name,
                              RelocInfo::kNoPosition,
Index: src/preparser-api.cc
diff --git a/src/preparser-api.cc b/src/preparser-api.cc
index cbec9b70961f87e055262d2a4118d69f3d03d917..dba30265f6aaef24b19966260c2251b8635e6583 100644
--- a/src/preparser-api.cc
+++ b/src/preparser-api.cc
@@ -155,7 +155,6 @@ class StandAloneJavaScriptScanner : public JavaScriptScanner {
  public:
   void Initialize(UC16CharacterStream* source) {
     source_ = source;
-    literal_flags_ = kLiteralString | kLiteralIdentifier;
     Init();
     // Skip initial whitespace allowing HTML comment ends just like
     // after a newline and scan first token.
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index 157fbea554728a801d5f2e879e581f5a07d7aed5..e05f903772e6147fad2da97ef808b06d80335787 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -950,13 +950,17 @@ PreParser::Expression PreParser::ParseObjectLiteral(bool* ok) {
         ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK);
         if ((is_getter || is_setter) && peek() != i::Token::COLON) {
             i::Token::Value name = Next();
+            bool is_keyword = i::Token::IsKeyword(name);
             if (name != i::Token::IDENTIFIER &&
                 name != i::Token::NUMBER &&
                 name != i::Token::STRING &&
-                !i::Token::IsKeyword(name)) {
+                !is_keyword) {
               *ok = false;
               return kUnknownExpression;
             }
+            if (!is_keyword) {
+              LogSymbol();
+            }
             ParseFunctionLiteral(CHECK_OK);
             if (peek() != i::Token::RBRACE) {
               Expect(i::Token::COMMA, CHECK_OK);
@@ -1120,24 +1124,24 @@ void PreParser::ExpectSemicolon(bool* ok) {
 }


-PreParser::Identifier PreParser::GetIdentifierSymbol() {
+void PreParser::LogSymbol() {
   int identifier_pos = scanner_->location().beg_pos;
   if (scanner_->is_literal_ascii()) {
     log_->LogAsciiSymbol(identifier_pos, scanner_->literal_ascii_string());
   } else {
     log_->LogUC16Symbol(identifier_pos, scanner_->literal_uc16_string());
   }
+}
+
+
+PreParser::Identifier PreParser::GetIdentifierSymbol() {
+  LogSymbol();
   return kUnknownIdentifier;
 }


 PreParser::Expression PreParser::GetStringSymbol() {
-  int identifier_pos = scanner_->location().beg_pos;
-  if (scanner_->is_literal_ascii()) {
-    log_->LogAsciiSymbol(identifier_pos, scanner_->literal_ascii_string());
-  } else {
-    log_->LogUC16Symbol(identifier_pos, scanner_->literal_uc16_string());
-  }
+  LogSymbol();
   return kUnknownExpression;
 }

Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 893b575198bf0cf0cdd775d458ca310d1cddae76..536e6d4f431050037970bd725126f8e9569a48eb 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -216,8 +216,11 @@ class PreParser {
   Identifier ParseIdentifierName(bool* ok);
Identifier ParseIdentifierOrGetOrSet(bool* is_get, bool* is_set, bool* ok);

+  // Logs the currently parsed literal as a symbol in the preparser data.
+  void LogSymbol();
+  // Log the currently parsed identifier.
   Identifier GetIdentifierSymbol();
-  unsigned int HexDigitValue(char digit);
+  // Log the currently parsed string literal.
   Expression GetStringSymbol();

   i::Token::Value peek() {


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to