Commit 351f80ad authored by lrn@chromium.org's avatar lrn@chromium.org

Fix compile-problem in (currently) unused stand-alone preparser function.

Allow object initializers to define getters using string and number literals.

Review URL: http://codereview.chromium.org/5985010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6150 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4dc32825
...@@ -2995,14 +2995,22 @@ ObjectLiteral::Property* Parser::ParseObjectLiteralGetSet(bool is_getter, ...@@ -2995,14 +2995,22 @@ ObjectLiteral::Property* Parser::ParseObjectLiteralGetSet(bool is_getter,
// { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... } // { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... }
// We have already read the "get" or "set" keyword. // We have already read the "get" or "set" keyword.
Token::Value next = Next(); Token::Value next = Next();
// TODO(820): Allow NUMBER and STRING as well (and handle array indices). bool is_keyword = Token::IsKeyword(next);
if (next == Token::IDENTIFIER || Token::IsKeyword(next)) { if (next == Token::IDENTIFIER || next == Token::NUMBER ||
Handle<String> name = GetSymbol(CHECK_OK); next == Token::STRING || is_keyword) {
Handle<String> name;
if (is_keyword) {
name = Factory::LookupAsciiSymbol(Token::String(next));
} else {
name = GetSymbol(CHECK_OK);
}
FunctionLiteral* value = FunctionLiteral* value =
ParseFunctionLiteral(name, ParseFunctionLiteral(name,
RelocInfo::kNoPosition, RelocInfo::kNoPosition,
DECLARATION, DECLARATION,
CHECK_OK); CHECK_OK);
// Allow any number of parameters for compatiabilty with JSC.
// Specification only allows zero parameters for get and one for set.
ObjectLiteral::Property* property = ObjectLiteral::Property* property =
new ObjectLiteral::Property(is_getter, value); new ObjectLiteral::Property(is_getter, value);
return property; return property;
......
...@@ -155,7 +155,6 @@ class StandAloneJavaScriptScanner : public JavaScriptScanner { ...@@ -155,7 +155,6 @@ class StandAloneJavaScriptScanner : public JavaScriptScanner {
public: public:
void Initialize(UC16CharacterStream* source) { void Initialize(UC16CharacterStream* source) {
source_ = source; source_ = source;
literal_flags_ = kLiteralString | kLiteralIdentifier;
Init(); Init();
// Skip initial whitespace allowing HTML comment ends just like // Skip initial whitespace allowing HTML comment ends just like
// after a newline and scan first token. // after a newline and scan first token.
......
...@@ -950,13 +950,17 @@ PreParser::Expression PreParser::ParseObjectLiteral(bool* ok) { ...@@ -950,13 +950,17 @@ PreParser::Expression PreParser::ParseObjectLiteral(bool* ok) {
ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK); ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK);
if ((is_getter || is_setter) && peek() != i::Token::COLON) { if ((is_getter || is_setter) && peek() != i::Token::COLON) {
i::Token::Value name = Next(); i::Token::Value name = Next();
bool is_keyword = i::Token::IsKeyword(name);
if (name != i::Token::IDENTIFIER && if (name != i::Token::IDENTIFIER &&
name != i::Token::NUMBER && name != i::Token::NUMBER &&
name != i::Token::STRING && name != i::Token::STRING &&
!i::Token::IsKeyword(name)) { !is_keyword) {
*ok = false; *ok = false;
return kUnknownExpression; return kUnknownExpression;
} }
if (!is_keyword) {
LogSymbol();
}
ParseFunctionLiteral(CHECK_OK); ParseFunctionLiteral(CHECK_OK);
if (peek() != i::Token::RBRACE) { if (peek() != i::Token::RBRACE) {
Expect(i::Token::COMMA, CHECK_OK); Expect(i::Token::COMMA, CHECK_OK);
...@@ -1120,24 +1124,24 @@ void PreParser::ExpectSemicolon(bool* ok) { ...@@ -1120,24 +1124,24 @@ void PreParser::ExpectSemicolon(bool* ok) {
} }
PreParser::Identifier PreParser::GetIdentifierSymbol() { void PreParser::LogSymbol() {
int identifier_pos = scanner_->location().beg_pos; int identifier_pos = scanner_->location().beg_pos;
if (scanner_->is_literal_ascii()) { if (scanner_->is_literal_ascii()) {
log_->LogAsciiSymbol(identifier_pos, scanner_->literal_ascii_string()); log_->LogAsciiSymbol(identifier_pos, scanner_->literal_ascii_string());
} else { } else {
log_->LogUC16Symbol(identifier_pos, scanner_->literal_uc16_string()); log_->LogUC16Symbol(identifier_pos, scanner_->literal_uc16_string());
} }
}
PreParser::Identifier PreParser::GetIdentifierSymbol() {
LogSymbol();
return kUnknownIdentifier; return kUnknownIdentifier;
} }
PreParser::Expression PreParser::GetStringSymbol() { PreParser::Expression PreParser::GetStringSymbol() {
int identifier_pos = scanner_->location().beg_pos; LogSymbol();
if (scanner_->is_literal_ascii()) {
log_->LogAsciiSymbol(identifier_pos, scanner_->literal_ascii_string());
} else {
log_->LogUC16Symbol(identifier_pos, scanner_->literal_uc16_string());
}
return kUnknownExpression; return kUnknownExpression;
} }
......
...@@ -216,8 +216,11 @@ class PreParser { ...@@ -216,8 +216,11 @@ class PreParser {
Identifier ParseIdentifierName(bool* ok); Identifier ParseIdentifierName(bool* ok);
Identifier ParseIdentifierOrGetOrSet(bool* is_get, bool* is_set, 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(); Identifier GetIdentifierSymbol();
unsigned int HexDigitValue(char digit); // Log the currently parsed string literal.
Expression GetStringSymbol(); Expression GetStringSymbol();
i::Token::Value peek() { i::Token::Value peek() {
......
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