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,
// { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... }
// 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,
DECLARATION,
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 =
new ObjectLiteral::Property(is_getter, value);
return property;
......
......@@ -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.
......
......@@ -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;
}
......
......@@ -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() {
......
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