Commit d8b8628f authored by marja@chromium.org's avatar marja@chromium.org

Revert "Traitify ParserBase and move functions there."

This reverts commit r19230.

Reason: Build failures on NaCl.

BUG=
TBR=marja@chromium.org,mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/158873006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19234 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 44d61f3c
...@@ -533,78 +533,8 @@ Parser::FunctionState::~FunctionState() { ...@@ -533,78 +533,8 @@ Parser::FunctionState::~FunctionState() {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Implementation of Parser // Implementation of Parser
bool ParserTraits::is_classic_mode() const {
return parser_->top_scope_->is_classic_mode();
}
bool ParserTraits::is_generator() const {
return parser_->current_function_state_->is_generator();
}
bool ParserTraits::IsEvalOrArguments(Handle<String> identifier) const {
return identifier.is_identical_to(
parser_->isolate()->factory()->eval_string()) ||
identifier.is_identical_to(
parser_->isolate()->factory()->arguments_string());
}
void ParserTraits::ReportMessageAt(Scanner::Location source_location,
const char* message,
Vector<const char*> args) {
MessageLocation location(parser_->script_,
source_location.beg_pos,
source_location.end_pos);
Factory* factory = parser_->isolate()->factory();
Handle<FixedArray> elements = factory->NewFixedArray(args.length());
for (int i = 0; i < args.length(); i++) {
Handle<String> arg_string = factory->NewStringFromUtf8(CStrVector(args[i]));
elements->set(i, *arg_string);
}
Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
Handle<Object> result = factory->NewSyntaxError(message, array);
parser_->isolate()->Throw(*result, &location);
}
void ParserTraits::ReportMessage(const char* message,
Vector<Handle<String> > args) {
Scanner::Location source_location = parser_->scanner().location();
ReportMessageAt(source_location, message, args);
}
void ParserTraits::ReportMessageAt(Scanner::Location source_location,
const char* message,
Vector<Handle<String> > args) {
MessageLocation location(parser_->script_,
source_location.beg_pos,
source_location.end_pos);
Factory* factory = parser_->isolate()->factory();
Handle<FixedArray> elements = factory->NewFixedArray(args.length());
for (int i = 0; i < args.length(); i++) {
elements->set(i, *args[i]);
}
Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
Handle<Object> result = factory->NewSyntaxError(message, array);
parser_->isolate()->Throw(*result, &location);
}
Handle<String> ParserTraits::GetSymbol() {
int symbol_id = -1;
if (parser_->pre_parse_data() != NULL) {
symbol_id = parser_->pre_parse_data()->GetSymbolIdentifier();
}
return parser_->LookupSymbol(symbol_id);
}
Parser::Parser(CompilationInfo* info) Parser::Parser(CompilationInfo* info)
: ParserBase(&scanner_, : ParserBase(&scanner_, info->isolate()->stack_guard()->real_climit()),
info->isolate()->stack_guard()->real_climit(),
this),
isolate_(info->isolate()), isolate_(info->isolate()),
symbol_cache_(0, info->zone()), symbol_cache_(0, info->zone()),
script_(info->script()), script_(info->script()),
...@@ -863,6 +793,62 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { ...@@ -863,6 +793,62 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
} }
Handle<String> Parser::GetSymbol() {
int symbol_id = -1;
if (pre_parse_data() != NULL) {
symbol_id = pre_parse_data()->GetSymbolIdentifier();
}
return LookupSymbol(symbol_id);
}
void Parser::ReportMessage(const char* message, Vector<const char*> args) {
Scanner::Location source_location = scanner().location();
ReportMessageAt(source_location, message, args);
}
void Parser::ReportMessage(const char* message, Vector<Handle<String> > args) {
Scanner::Location source_location = scanner().location();
ReportMessageAt(source_location, message, args);
}
void Parser::ReportMessageAt(Scanner::Location source_location,
const char* message,
Vector<const char*> args) {
MessageLocation location(script_,
source_location.beg_pos,
source_location.end_pos);
Factory* factory = isolate()->factory();
Handle<FixedArray> elements = factory->NewFixedArray(args.length());
for (int i = 0; i < args.length(); i++) {
Handle<String> arg_string = factory->NewStringFromUtf8(CStrVector(args[i]));
elements->set(i, *arg_string);
}
Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
Handle<Object> result = factory->NewSyntaxError(message, array);
isolate()->Throw(*result, &location);
}
void Parser::ReportMessageAt(Scanner::Location source_location,
const char* message,
Vector<Handle<String> > args) {
MessageLocation location(script_,
source_location.beg_pos,
source_location.end_pos);
Factory* factory = isolate()->factory();
Handle<FixedArray> elements = factory->NewFixedArray(args.length());
for (int i = 0; i < args.length(); i++) {
elements->set(i, *args[i]);
}
Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
Handle<Object> result = factory->NewSyntaxError(message, array);
isolate()->Throw(*result, &location);
}
void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
int end_token, int end_token,
bool is_eval, bool is_eval,
...@@ -1095,7 +1081,7 @@ Module* Parser::ParseModuleLiteral(bool* ok) { ...@@ -1095,7 +1081,7 @@ Module* Parser::ParseModuleLiteral(bool* ok) {
!it.done(); it.Advance()) { !it.done(); it.Advance()) {
if (scope->LocalLookup(it.name()) == NULL) { if (scope->LocalLookup(it.name()) == NULL) {
Handle<String> name(it.name()); Handle<String> name(it.name());
ParserTraits::ReportMessage("module_export_undefined", ReportMessage("module_export_undefined",
Vector<Handle<String> >(&name, 1)); Vector<Handle<String> >(&name, 1));
*ok = false; *ok = false;
return NULL; return NULL;
...@@ -1135,8 +1121,7 @@ Module* Parser::ParseModulePath(bool* ok) { ...@@ -1135,8 +1121,7 @@ Module* Parser::ParseModulePath(bool* ok) {
member->interface()->Print(); member->interface()->Print();
} }
#endif #endif
ParserTraits::ReportMessage("invalid_module_path", ReportMessage("invalid_module_path", Vector<Handle<String> >(&name, 1));
Vector<Handle<String> >(&name, 1));
return NULL; return NULL;
} }
result = member; result = member;
...@@ -1246,8 +1231,7 @@ Block* Parser::ParseImportDeclaration(bool* ok) { ...@@ -1246,8 +1231,7 @@ Block* Parser::ParseImportDeclaration(bool* ok) {
module->interface()->Print(); module->interface()->Print();
} }
#endif #endif
ParserTraits::ReportMessage("invalid_module_path", ReportMessage("invalid_module_path", Vector<Handle<String> >(&name, 1));
Vector<Handle<String> >(&name, 1));
return NULL; return NULL;
} }
VariableProxy* proxy = NewUnresolved(names[i], LET, interface); VariableProxy* proxy = NewUnresolved(names[i], LET, interface);
...@@ -1455,7 +1439,8 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) { ...@@ -1455,7 +1439,8 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) {
// Statement: // Statement:
// GeneratorDeclaration // GeneratorDeclaration
if (!top_scope_->is_classic_mode()) { if (!top_scope_->is_classic_mode()) {
ReportMessageAt(scanner().peek_location(), "strict_function"); ReportMessageAt(scanner().peek_location(), "strict_function",
Vector<const char*>::empty());
*ok = false; *ok = false;
return NULL; return NULL;
} }
...@@ -1634,8 +1619,7 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { ...@@ -1634,8 +1619,7 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
var->interface()->Print(); var->interface()->Print();
} }
#endif #endif
ParserTraits::ReportMessage("module_type_error", ReportMessage("module_type_error", Vector<Handle<String> >(&name, 1));
Vector<Handle<String> >(&name, 1));
} }
} }
} }
...@@ -1793,6 +1777,12 @@ Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, ...@@ -1793,6 +1777,12 @@ Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context,
} }
bool Parser::IsEvalOrArguments(Handle<String> string) {
return string.is_identical_to(isolate()->factory()->eval_string()) ||
string.is_identical_to(isolate()->factory()->arguments_string());
}
// If the variable declaration declares exactly one non-const // If the variable declaration declares exactly one non-const
// variable, then *out is set to that variable. In all other cases, // variable, then *out is set to that variable. In all other cases,
// *out is untouched; in particular, it is the caller's responsibility // *out is untouched; in particular, it is the caller's responsibility
...@@ -1938,7 +1928,8 @@ Block* Parser::ParseVariableDeclarations( ...@@ -1938,7 +1928,8 @@ Block* Parser::ParseVariableDeclarations(
Declare(declaration, mode != VAR, CHECK_OK); Declare(declaration, mode != VAR, CHECK_OK);
nvars++; nvars++;
if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) {
ReportMessageAt(scanner().location(), "too_many_variables"); ReportMessageAt(scanner().location(), "too_many_variables",
Vector<const char*>::empty());
*ok = false; *ok = false;
return NULL; return NULL;
} }
...@@ -2241,7 +2232,7 @@ Statement* Parser::ParseContinueStatement(bool* ok) { ...@@ -2241,7 +2232,7 @@ Statement* Parser::ParseContinueStatement(bool* ok) {
message = "unknown_label"; message = "unknown_label";
args = Vector<Handle<String> >(&label, 1); args = Vector<Handle<String> >(&label, 1);
} }
ParserTraits::ReportMessageAt(scanner().location(), message, args); ReportMessageAt(scanner().location(), message, args);
*ok = false; *ok = false;
return NULL; return NULL;
} }
...@@ -2279,7 +2270,7 @@ Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { ...@@ -2279,7 +2270,7 @@ Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) {
message = "unknown_label"; message = "unknown_label";
args = Vector<Handle<String> >(&label, 1); args = Vector<Handle<String> >(&label, 1);
} }
ParserTraits::ReportMessageAt(scanner().location(), message, args); ReportMessageAt(scanner().location(), message, args);
*ok = false; *ok = false;
return NULL; return NULL;
} }
...@@ -3022,6 +3013,14 @@ Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { ...@@ -3022,6 +3013,14 @@ Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
} }
int ParserBase::Precedence(Token::Value tok, bool accept_IN) {
if (tok == Token::IN && !accept_IN)
return 0; // 0 precedence will terminate binary expression parsing
return Token::Precedence(tok);
}
// Precedence >= 4 // Precedence >= 4
Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
ASSERT(prec >= 4); ASSERT(prec >= 4);
...@@ -3864,7 +3863,8 @@ ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { ...@@ -3864,7 +3863,8 @@ ZoneList<Expression*>* Parser::ParseArguments(bool* ok) {
Expression* argument = ParseAssignmentExpression(true, CHECK_OK); Expression* argument = ParseAssignmentExpression(true, CHECK_OK);
result->Add(argument, zone()); result->Add(argument, zone());
if (result->length() > Code::kMaxArguments) { if (result->length() > Code::kMaxArguments) {
ReportMessageAt(scanner().location(), "too_many_arguments"); ReportMessageAt(scanner().location(), "too_many_arguments",
Vector<const char*>::empty());
*ok = false; *ok = false;
return NULL; return NULL;
} }
...@@ -4095,7 +4095,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4095,7 +4095,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
top_scope_->DeclareParameter(param_name, VAR); top_scope_->DeclareParameter(param_name, VAR);
num_parameters++; num_parameters++;
if (num_parameters > Code::kMaxArguments) { if (num_parameters > Code::kMaxArguments) {
ReportMessageAt(scanner().location(), "too_many_parameters"); ReportMessageAt(scanner().location(), "too_many_parameters",
Vector<const char*>::empty());
*ok = false; *ok = false;
return NULL; return NULL;
} }
...@@ -4186,10 +4187,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4186,10 +4187,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
if (arg != NULL) { if (arg != NULL) {
args = Vector<const char*>(&arg, 1); args = Vector<const char*>(&arg, 1);
} }
ParserTraits::ReportMessageAt( ReportMessageAt(Scanner::Location(logger.start(), logger.end()),
Scanner::Location(logger.start(), logger.end()), logger.message(), args);
logger.message(),
args);
*ok = false; *ok = false;
return NULL; return NULL;
} }
...@@ -4263,27 +4262,33 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4263,27 +4262,33 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// since the function can declare itself strict. // since the function can declare itself strict.
if (!top_scope_->is_classic_mode()) { if (!top_scope_->is_classic_mode()) {
if (IsEvalOrArguments(function_name)) { if (IsEvalOrArguments(function_name)) {
ReportMessageAt(function_name_location, "strict_eval_arguments"); ReportMessageAt(function_name_location,
"strict_eval_arguments",
Vector<const char*>::empty());
*ok = false; *ok = false;
return NULL; return NULL;
} }
if (name_is_strict_reserved) { if (name_is_strict_reserved) {
ReportMessageAt(function_name_location, "unexpected_strict_reserved"); ReportMessageAt(function_name_location, "unexpected_strict_reserved",
Vector<const char*>::empty());
*ok = false; *ok = false;
return NULL; return NULL;
} }
if (eval_args_error_log.IsValid()) { if (eval_args_error_log.IsValid()) {
ReportMessageAt(eval_args_error_log, "strict_eval_arguments"); ReportMessageAt(eval_args_error_log, "strict_eval_arguments",
Vector<const char*>::empty());
*ok = false; *ok = false;
return NULL; return NULL;
} }
if (dupe_error_loc.IsValid()) { if (dupe_error_loc.IsValid()) {
ReportMessageAt(dupe_error_loc, "strict_param_dupe"); ReportMessageAt(dupe_error_loc, "strict_param_dupe",
Vector<const char*>::empty());
*ok = false; *ok = false;
return NULL; return NULL;
} }
if (reserved_loc.IsValid()) { if (reserved_loc.IsValid()) {
ReportMessageAt(reserved_loc, "unexpected_strict_reserved"); ReportMessageAt(reserved_loc, "unexpected_strict_reserved",
Vector<const char*>::empty());
*ok = false; *ok = false;
return NULL; return NULL;
} }
...@@ -4392,8 +4397,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { ...@@ -4392,8 +4397,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
// Check that the function is defined if it's an inline runtime call. // Check that the function is defined if it's an inline runtime call.
if (function == NULL && name->Get(0) == '_') { if (function == NULL && name->Get(0) == '_') {
ParserTraits::ReportMessage("not_defined", ReportMessage("not_defined", Vector<Handle<String> >(&name, 1));
Vector<Handle<String> >(&name, 1));
*ok = false; *ok = false;
return NULL; return NULL;
} }
...@@ -4403,6 +4407,88 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { ...@@ -4403,6 +4407,88 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
} }
bool ParserBase::peek_any_identifier() {
Token::Value next = peek();
return next == Token::IDENTIFIER ||
next == Token::FUTURE_RESERVED_WORD ||
next == Token::FUTURE_STRICT_RESERVED_WORD ||
next == Token::YIELD;
}
bool ParserBase::CheckContextualKeyword(Vector<const char> keyword) {
if (peek() == Token::IDENTIFIER &&
scanner()->is_next_contextual_keyword(keyword)) {
Consume(Token::IDENTIFIER);
return true;
}
return false;
}
void ParserBase::ExpectSemicolon(bool* ok) {
// Check for automatic semicolon insertion according to
// the rules given in ECMA-262, section 7.9, page 21.
Token::Value tok = peek();
if (tok == Token::SEMICOLON) {
Next();
return;
}
if (scanner()->HasAnyLineTerminatorBeforeNext() ||
tok == Token::RBRACE ||
tok == Token::EOS) {
return;
}
Expect(Token::SEMICOLON, ok);
}
void ParserBase::ExpectContextualKeyword(Vector<const char> keyword, bool* ok) {
Expect(Token::IDENTIFIER, ok);
if (!*ok) return;
if (!scanner()->is_literal_contextual_keyword(keyword)) {
ReportUnexpectedToken(scanner()->current_token());
*ok = false;
}
}
void ParserBase::ReportUnexpectedToken(Token::Value token) {
// We don't report stack overflows here, to avoid increasing the
// stack depth even further. Instead we report it after parsing is
// over, in ParseProgram.
if (token == Token::ILLEGAL && stack_overflow()) {
return;
}
Scanner::Location source_location = scanner()->location();
// Four of the tokens are treated specially
switch (token) {
case Token::EOS:
return ReportMessageAt(source_location, "unexpected_eos");
case Token::NUMBER:
return ReportMessageAt(source_location, "unexpected_token_number");
case Token::STRING:
return ReportMessageAt(source_location, "unexpected_token_string");
case Token::IDENTIFIER:
return ReportMessageAt(source_location,
"unexpected_token_identifier");
case Token::FUTURE_RESERVED_WORD:
return ReportMessageAt(source_location, "unexpected_reserved");
case Token::YIELD:
case Token::FUTURE_STRICT_RESERVED_WORD:
return ReportMessageAt(source_location,
is_classic_mode() ? "unexpected_token_identifier"
: "unexpected_strict_reserved");
default:
const char* name = Token::String(token);
ASSERT(name != NULL);
ReportMessageAt(
source_location, "unexpected_token", Vector<const char*>(&name, 1));
}
}
Literal* Parser::GetLiteralUndefined(int position) { Literal* Parser::GetLiteralUndefined(int position) {
return factory()->NewLiteral( return factory()->NewLiteral(
isolate()->factory()->undefined_value(), position); isolate()->factory()->undefined_value(), position);
...@@ -4415,6 +4501,68 @@ Literal* Parser::GetLiteralTheHole(int position) { ...@@ -4415,6 +4501,68 @@ Literal* Parser::GetLiteralTheHole(int position) {
} }
// Parses an identifier that is valid for the current scope, in particular it
// fails on strict mode future reserved keywords in a strict scope. If
// allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or
// "arguments" as identifier even in strict mode (this is needed in cases like
// "var foo = eval;").
Handle<String> Parser::ParseIdentifier(
AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments,
bool* ok) {
Token::Value next = Next();
if (next == Token::IDENTIFIER) {
Handle<String> name = GetSymbol();
if (allow_eval_or_arguments == kDontAllowEvalOrArguments &&
!top_scope_->is_classic_mode() && IsEvalOrArguments(name)) {
ReportMessage("strict_eval_arguments", Vector<const char*>::empty());
*ok = false;
}
return name;
} else if (top_scope_->is_classic_mode() &&
(next == Token::FUTURE_STRICT_RESERVED_WORD ||
(next == Token::YIELD && !is_generator()))) {
return GetSymbol();
} else {
ReportUnexpectedToken(next);
*ok = false;
return Handle<String>();
}
}
// Parses and identifier or a strict mode future reserved word, and indicate
// whether it is strict mode future reserved.
Handle<String> Parser::ParseIdentifierOrStrictReservedWord(
bool* is_strict_reserved, bool* ok) {
Token::Value next = Next();
if (next == Token::IDENTIFIER) {
*is_strict_reserved = false;
} else if (next == Token::FUTURE_STRICT_RESERVED_WORD ||
(next == Token::YIELD && !is_generator())) {
*is_strict_reserved = true;
} else {
ReportUnexpectedToken(next);
*ok = false;
return Handle<String>();
}
return GetSymbol();
}
Handle<String> Parser::ParseIdentifierName(bool* ok) {
Token::Value next = Next();
if (next != Token::IDENTIFIER &&
next != Token::FUTURE_RESERVED_WORD &&
next != Token::FUTURE_STRICT_RESERVED_WORD &&
!Token::IsKeyword(next)) {
ReportUnexpectedToken(next);
*ok = false;
return Handle<String>();
}
return GetSymbol();
}
void Parser::MarkAsLValue(Expression* expression) { void Parser::MarkAsLValue(Expression* expression) {
VariableProxy* proxy = expression != NULL VariableProxy* proxy = expression != NULL
? expression->AsVariableProxy() ? expression->AsVariableProxy()
...@@ -4440,6 +4588,18 @@ void Parser::CheckStrictModeLValue(Expression* expression, ...@@ -4440,6 +4588,18 @@ void Parser::CheckStrictModeLValue(Expression* expression,
} }
// Checks whether an octal literal was last seen between beg_pos and end_pos.
// If so, reports an error. Only called for strict mode.
void ParserBase::CheckOctalLiteral(int beg_pos, int end_pos, bool* ok) {
Scanner::Location octal = scanner()->octal_position();
if (octal.IsValid() && beg_pos <= octal.beg_pos && octal.end_pos <= end_pos) {
ReportMessageAt(octal, "strict_octal_literal");
scanner()->clear_octal_position();
*ok = false;
}
}
void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
Declaration* decl = scope->CheckConflictingVarDeclarations(); Declaration* decl = scope->CheckConflictingVarDeclarations();
if (decl != NULL) { if (decl != NULL) {
...@@ -4453,12 +4613,28 @@ void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { ...@@ -4453,12 +4613,28 @@ void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) {
Scanner::Location location = position == RelocInfo::kNoPosition Scanner::Location location = position == RelocInfo::kNoPosition
? Scanner::Location::invalid() ? Scanner::Location::invalid()
: Scanner::Location(position, position + 1); : Scanner::Location(position, position + 1);
ParserTraits::ReportMessageAt(location, "redeclaration", args); ReportMessageAt(location, "redeclaration", args);
*ok = false; *ok = false;
} }
} }
// This function reads an identifier name and determines whether or not it
// is 'get' or 'set'.
Handle<String> Parser::ParseIdentifierNameOrGetOrSet(bool* is_get,
bool* is_set,
bool* ok) {
Handle<String> result = ParseIdentifierName(ok);
if (!*ok) return Handle<String>();
if (scanner().is_literal_ascii() && scanner().literal_length() == 3) {
const char* token = scanner().literal_ascii_string().start();
*is_get = strncmp(token, "get", 3) == 0;
*is_set = !*is_get && strncmp(token, "set", 3) == 0;
}
return result;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Parser support // Parser support
...@@ -5507,7 +5683,7 @@ bool Parser::Parse() { ...@@ -5507,7 +5683,7 @@ bool Parser::Parse() {
Scanner::Location loc = pre_parse_data->MessageLocation(); Scanner::Location loc = pre_parse_data->MessageLocation();
const char* message = pre_parse_data->BuildMessage(); const char* message = pre_parse_data->BuildMessage();
Vector<const char*> args = pre_parse_data->BuildArgs(); Vector<const char*> args = pre_parse_data->BuildArgs();
ParserTraits::ReportMessageAt(loc, message, args); ReportMessageAt(loc, message, args);
DeleteArray(message); DeleteArray(message);
for (int i = 0; i < args.length(); i++) { for (int i = 0; i < args.length(); i++) {
DeleteArray(args[i]); DeleteArray(args[i]);
......
...@@ -404,44 +404,10 @@ class RegExpParser BASE_EMBEDDED { ...@@ -404,44 +404,10 @@ class RegExpParser BASE_EMBEDDED {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// JAVASCRIPT PARSING // JAVASCRIPT PARSING
class Parser; // Forward declaration.
class SingletonLogger; class SingletonLogger;
class ParserTraits { class Parser : public ParserBase {
public:
typedef Parser* ParserType;
// Return types for traversing functions.
typedef Handle<String> IdentifierType;
explicit ParserTraits(Parser* parser) : parser_(parser) {}
// Helper functions for recursive descent.
bool is_classic_mode() const;
bool is_generator() const;
bool IsEvalOrArguments(Handle<String> identifier) const;
// Reporting errors.
void ReportMessageAt(Scanner::Location source_location,
const char* message,
Vector<const char*> args);
void ReportMessage(const char* message, Vector<Handle<String> > args);
void ReportMessageAt(Scanner::Location source_location,
const char* message,
Vector<Handle<String> > args);
// Identifiers:
static IdentifierType EmptyIdentifier() {
return Handle<String>();
}
IdentifierType GetSymbol();
private:
Parser* parser_;
};
class Parser : public ParserBase<ParserTraits> {
public: public:
explicit Parser(CompilationInfo* info); explicit Parser(CompilationInfo* info);
~Parser() { ~Parser() {
...@@ -461,8 +427,6 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -461,8 +427,6 @@ class Parser : public ParserBase<ParserTraits> {
bool Parse(); bool Parse();
private: private:
friend class ParserTraits;
static const int kMaxNumFunctionLocals = 131071; // 2^17-1 static const int kMaxNumFunctionLocals = 131071; // 2^17-1
enum Mode { enum Mode {
...@@ -557,6 +521,10 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -557,6 +521,10 @@ class Parser : public ParserBase<ParserTraits> {
Mode old_mode_; Mode old_mode_;
}; };
virtual bool is_classic_mode() {
return top_scope_->is_classic_mode();
}
// Returns NULL if parsing failed. // Returns NULL if parsing failed.
FunctionLiteral* ParseProgram(); FunctionLiteral* ParseProgram();
...@@ -573,6 +541,17 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -573,6 +541,17 @@ class Parser : public ParserBase<ParserTraits> {
// Report syntax error // Report syntax error
void ReportInvalidPreparseData(Handle<String> name, bool* ok); void ReportInvalidPreparseData(Handle<String> name, bool* ok);
void ReportMessage(const char* message, Vector<const char*> args);
void ReportMessage(const char* message, Vector<Handle<String> > args);
void ReportMessageAt(Scanner::Location location, const char* type) {
ReportMessageAt(location, type, Vector<const char*>::empty());
}
void ReportMessageAt(Scanner::Location loc,
const char* message,
Vector<const char*> args);
void ReportMessageAt(Scanner::Location loc,
const char* message,
Vector<Handle<String> > args);
void set_pre_parse_data(ScriptDataImpl *data) { void set_pre_parse_data(ScriptDataImpl *data) {
pre_parse_data_ = data; pre_parse_data_ = data;
...@@ -592,6 +571,9 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -592,6 +571,9 @@ class Parser : public ParserBase<ParserTraits> {
? top_scope_ : top_scope_->DeclarationScope(); ? top_scope_ : top_scope_->DeclarationScope();
} }
// Check if the given string is 'eval' or 'arguments'.
bool IsEvalOrArguments(Handle<String> string);
// All ParseXXX functions take as the last argument an *ok parameter // All ParseXXX functions take as the last argument an *ok parameter
// which is set to false if parsing failed; it is unchanged otherwise. // which is set to false if parsing failed; it is unchanged otherwise.
// By making the 'exception handling' explicit, we are forced to check // By making the 'exception handling' explicit, we are forced to check
...@@ -678,6 +660,8 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -678,6 +660,8 @@ class Parser : public ParserBase<ParserTraits> {
// Magical syntax support. // Magical syntax support.
Expression* ParseV8Intrinsic(bool* ok); Expression* ParseV8Intrinsic(bool* ok);
bool is_generator() const { return current_function_state_->is_generator(); }
bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode);
Handle<String> LiteralString(PretenureFlag tenured) { Handle<String> LiteralString(PretenureFlag tenured) {
...@@ -700,10 +684,20 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -700,10 +684,20 @@ class Parser : public ParserBase<ParserTraits> {
} }
} }
Handle<String> GetSymbol();
// Get odd-ball literals. // Get odd-ball literals.
Literal* GetLiteralUndefined(int position); Literal* GetLiteralUndefined(int position);
Literal* GetLiteralTheHole(int position); Literal* GetLiteralTheHole(int position);
Handle<String> ParseIdentifier(AllowEvalOrArgumentsAsIdentifier, bool* ok);
Handle<String> ParseIdentifierOrStrictReservedWord(
bool* is_strict_reserved, bool* ok);
Handle<String> ParseIdentifierName(bool* ok);
Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get,
bool* is_set,
bool* ok);
// Determine if the expression is a variable proxy and mark it as being used // Determine if the expression is a variable proxy and mark it as being used
// in an assignment or with a increment/decrement operator. This is currently // in an assignment or with a increment/decrement operator. This is currently
// used on for the statically checking assignments to harmony const bindings. // used on for the statically checking assignments to harmony const bindings.
......
...@@ -55,68 +55,6 @@ int isfinite(double value); ...@@ -55,68 +55,6 @@ int isfinite(double value);
namespace v8 { namespace v8 {
namespace internal { namespace internal {
bool PreParserTraits::is_classic_mode() const {
return pre_parser_->scope_->language_mode() == CLASSIC_MODE;
}
bool PreParserTraits::is_generator() const {
return pre_parser_->scope_->is_generator();
}
void PreParserTraits::ReportMessageAt(Scanner::Location location,
const char* message,
Vector<const char*> args) {
ReportMessageAt(location.beg_pos,
location.end_pos,
message,
args.length() > 0 ? args[0] : NULL);
}
void PreParserTraits::ReportMessageAt(Scanner::Location location,
const char* type,
const char* name_opt) {
pre_parser_->log_
->LogMessage(location.beg_pos, location.end_pos, type, name_opt);
}
void PreParserTraits::ReportMessageAt(int start_pos,
int end_pos,
const char* type,
const char* name_opt) {
pre_parser_->log_->LogMessage(start_pos, end_pos, type, name_opt);
}
PreParserIdentifier PreParserTraits::GetSymbol() {
Scanner* scanner = pre_parser_->scanner();
pre_parser_->LogSymbol();
if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) {
return PreParserIdentifier::FutureReserved();
} else if (scanner->current_token() ==
Token::FUTURE_STRICT_RESERVED_WORD) {
return PreParserIdentifier::FutureStrictReserved();
} else if (scanner->current_token() == Token::YIELD) {
return PreParserIdentifier::Yield();
}
if (scanner->is_literal_ascii()) {
// Detect strict-mode poison words.
if (scanner->literal_length() == 4 &&
!strncmp(scanner->literal_ascii_string().start(), "eval", 4)) {
return PreParserIdentifier::Eval();
}
if (scanner->literal_length() == 9 &&
!strncmp(scanner->literal_ascii_string().start(), "arguments", 9)) {
return PreParserIdentifier::Arguments();
}
}
return PreParserIdentifier::Default();
}
PreParser::PreParseResult PreParser::PreParseLazyFunction( PreParser::PreParseResult PreParser::PreParseLazyFunction(
LanguageMode mode, bool is_generator, ParserRecorder* log) { LanguageMode mode, bool is_generator, ParserRecorder* log) {
log_ = log; log_ = log;
...@@ -297,10 +235,8 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) { ...@@ -297,10 +235,8 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) {
Statement statement = ParseFunctionDeclaration(CHECK_OK); Statement statement = ParseFunctionDeclaration(CHECK_OK);
Scanner::Location end_location = scanner()->location(); Scanner::Location end_location = scanner()->location();
if (!scope_->is_classic_mode()) { if (!scope_->is_classic_mode()) {
PreParserTraits::ReportMessageAt(start_location.beg_pos, ReportMessageAt(start_location.beg_pos, end_location.end_pos,
end_location.end_pos, "strict_function", NULL);
"strict_function",
NULL);
*ok = false; *ok = false;
return Statement::Default(); return Statement::Default();
} else { } else {
...@@ -416,14 +352,16 @@ PreParser::Statement PreParser::ParseVariableDeclarations( ...@@ -416,14 +352,16 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
break; break;
case STRICT_MODE: { case STRICT_MODE: {
Scanner::Location location = scanner()->peek_location(); Scanner::Location location = scanner()->peek_location();
ReportMessageAt(location, "strict_const"); ReportMessageAt(location, "strict_const", NULL);
*ok = false; *ok = false;
return Statement::Default(); return Statement::Default();
} }
case EXTENDED_MODE: case EXTENDED_MODE:
if (var_context != kSourceElement && if (var_context != kSourceElement &&
var_context != kForStatement) { var_context != kForStatement) {
ReportMessageAt(scanner()->peek_location(), "unprotected_const"); Scanner::Location location = scanner()->peek_location();
ReportMessageAt(location.beg_pos, location.end_pos,
"unprotected_const", NULL);
*ok = false; *ok = false;
return Statement::Default(); return Statement::Default();
} }
...@@ -438,14 +376,18 @@ PreParser::Statement PreParser::ParseVariableDeclarations( ...@@ -438,14 +376,18 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
// * It is a Syntax Error if the code that matches this production is not // * It is a Syntax Error if the code that matches this production is not
// contained in extended code. // contained in extended code.
if (!is_extended_mode()) { if (!is_extended_mode()) {
ReportMessageAt(scanner()->peek_location(), "illegal_let"); Scanner::Location location = scanner()->peek_location();
ReportMessageAt(location.beg_pos, location.end_pos,
"illegal_let", NULL);
*ok = false; *ok = false;
return Statement::Default(); return Statement::Default();
} }
Consume(Token::LET); Consume(Token::LET);
if (var_context != kSourceElement && if (var_context != kSourceElement &&
var_context != kForStatement) { var_context != kForStatement) {
ReportMessageAt(scanner()->peek_location(), "unprotected_let"); Scanner::Location location = scanner()->peek_location();
ReportMessageAt(location.beg_pos, location.end_pos,
"unprotected_let", NULL);
*ok = false; *ok = false;
return Statement::Default(); return Statement::Default();
} }
...@@ -589,7 +531,8 @@ PreParser::Statement PreParser::ParseWithStatement(bool* ok) { ...@@ -589,7 +531,8 @@ PreParser::Statement PreParser::ParseWithStatement(bool* ok) {
// 'with' '(' Expression ')' Statement // 'with' '(' Expression ')' Statement
Expect(Token::WITH, CHECK_OK); Expect(Token::WITH, CHECK_OK);
if (!scope_->is_classic_mode()) { if (!scope_->is_classic_mode()) {
ReportMessageAt(scanner()->location(), "strict_mode_with"); Scanner::Location location = scanner()->location();
ReportMessageAt(location, "strict_mode_with", NULL);
*ok = false; *ok = false;
return Statement::Default(); return Statement::Default();
} }
...@@ -733,7 +676,8 @@ PreParser::Statement PreParser::ParseThrowStatement(bool* ok) { ...@@ -733,7 +676,8 @@ PreParser::Statement PreParser::ParseThrowStatement(bool* ok) {
Expect(Token::THROW, CHECK_OK); Expect(Token::THROW, CHECK_OK);
if (scanner()->HasAnyLineTerminatorBeforeNext()) { if (scanner()->HasAnyLineTerminatorBeforeNext()) {
ReportMessageAt(scanner()->location(), "newline_after_throw"); Scanner::Location pos = scanner()->location();
ReportMessageAt(pos, "newline_after_throw", NULL);
*ok = false; *ok = false;
return Statement::Default(); return Statement::Default();
} }
...@@ -761,7 +705,7 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) { ...@@ -761,7 +705,7 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
Token::Value tok = peek(); Token::Value tok = peek();
if (tok != Token::CATCH && tok != Token::FINALLY) { if (tok != Token::CATCH && tok != Token::FINALLY) {
ReportMessageAt(scanner()->location(), "no_catch_or_finally"); ReportMessageAt(scanner()->location(), "no_catch_or_finally", NULL);
*ok = false; *ok = false;
return Statement::Default(); return Statement::Default();
} }
...@@ -844,7 +788,7 @@ PreParser::Expression PreParser::ParseAssignmentExpression(bool accept_IN, ...@@ -844,7 +788,7 @@ PreParser::Expression PreParser::ParseAssignmentExpression(bool accept_IN,
expression.IsIdentifier() && expression.IsIdentifier() &&
expression.AsIdentifier().IsEvalOrArguments()) { expression.AsIdentifier().IsEvalOrArguments()) {
Scanner::Location after = scanner()->location(); Scanner::Location after = scanner()->location();
PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, ReportMessageAt(before.beg_pos, after.end_pos,
"strict_eval_arguments", NULL); "strict_eval_arguments", NULL);
*ok = false; *ok = false;
return Expression::Default(); return Expression::Default();
...@@ -938,7 +882,7 @@ PreParser::Expression PreParser::ParseUnaryExpression(bool* ok) { ...@@ -938,7 +882,7 @@ PreParser::Expression PreParser::ParseUnaryExpression(bool* ok) {
expression.IsIdentifier() && expression.IsIdentifier() &&
expression.AsIdentifier().IsEvalOrArguments()) { expression.AsIdentifier().IsEvalOrArguments()) {
Scanner::Location after = scanner()->location(); Scanner::Location after = scanner()->location();
PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, ReportMessageAt(before.beg_pos, after.end_pos,
"strict_eval_arguments", NULL); "strict_eval_arguments", NULL);
*ok = false; *ok = false;
} }
...@@ -961,7 +905,7 @@ PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { ...@@ -961,7 +905,7 @@ PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) {
expression.IsIdentifier() && expression.IsIdentifier() &&
expression.AsIdentifier().IsEvalOrArguments()) { expression.AsIdentifier().IsEvalOrArguments()) {
Scanner::Location after = scanner()->location(); Scanner::Location after = scanner()->location();
PreParserTraits::ReportMessageAt(before.beg_pos, after.end_pos, ReportMessageAt(before.beg_pos, after.end_pos,
"strict_eval_arguments", NULL); "strict_eval_arguments", NULL);
*ok = false; *ok = false;
return Expression::Default(); return Expression::Default();
...@@ -1305,7 +1249,7 @@ PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal, ...@@ -1305,7 +1249,7 @@ PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal,
bool* ok) { bool* ok) {
if (!scanner()->ScanRegExpPattern(seen_equal)) { if (!scanner()->ScanRegExpPattern(seen_equal)) {
Next(); Next();
ReportMessageAt(scanner()->location(), "unterminated_regexp"); ReportMessageAt(scanner()->location(), "unterminated_regexp", NULL);
*ok = false; *ok = false;
return Expression::Default(); return Expression::Default();
} }
...@@ -1314,7 +1258,7 @@ PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal, ...@@ -1314,7 +1258,7 @@ PreParser::Expression PreParser::ParseRegExpLiteral(bool seen_equal,
if (!scanner()->ScanRegExpFlags()) { if (!scanner()->ScanRegExpFlags()) {
Next(); Next();
ReportMessageAt(scanner()->location(), "invalid_regexp_flags"); ReportMessageAt(scanner()->location(), "invalid_regexp_flags", NULL);
*ok = false; *ok = false;
return Expression::Default(); return Expression::Default();
} }
...@@ -1422,27 +1366,31 @@ PreParser::Expression PreParser::ParseFunctionLiteral( ...@@ -1422,27 +1366,31 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
// since the function can declare itself strict. // since the function can declare itself strict.
if (!scope_->is_classic_mode()) { if (!scope_->is_classic_mode()) {
if (function_name.IsEvalOrArguments()) { if (function_name.IsEvalOrArguments()) {
ReportMessageAt(function_name_location, "strict_eval_arguments"); ReportMessageAt(function_name_location, "strict_eval_arguments", NULL);
*ok = false; *ok = false;
return Expression::Default(); return Expression::Default();
} }
if (name_is_strict_reserved) { if (name_is_strict_reserved) {
ReportMessageAt(function_name_location, "unexpected_strict_reserved"); ReportMessageAt(
function_name_location, "unexpected_strict_reserved", NULL);
*ok = false; *ok = false;
return Expression::Default(); return Expression::Default();
} }
if (eval_args_error_loc.IsValid()) { if (eval_args_error_loc.IsValid()) {
ReportMessageAt(eval_args_error_loc, "strict_eval_arguments"); ReportMessageAt(eval_args_error_loc, "strict_eval_arguments",
Vector<const char*>::empty());
*ok = false; *ok = false;
return Expression::Default(); return Expression::Default();
} }
if (dupe_error_loc.IsValid()) { if (dupe_error_loc.IsValid()) {
ReportMessageAt(dupe_error_loc, "strict_param_dupe"); ReportMessageAt(dupe_error_loc, "strict_param_dupe",
Vector<const char*>::empty());
*ok = false; *ok = false;
return Expression::Default(); return Expression::Default();
} }
if (reserved_error_loc.IsValid()) { if (reserved_error_loc.IsValid()) {
ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved"); ReportMessageAt(reserved_error_loc, "unexpected_strict_reserved",
Vector<const char*>::empty());
*ok = false; *ok = false;
return Expression::Default(); return Expression::Default();
} }
...@@ -1516,4 +1464,142 @@ PreParser::Expression PreParser::GetStringSymbol() { ...@@ -1516,4 +1464,142 @@ PreParser::Expression PreParser::GetStringSymbol() {
} }
PreParser::Identifier PreParser::GetIdentifierSymbol() {
LogSymbol();
if (scanner()->current_token() == Token::FUTURE_RESERVED_WORD) {
return Identifier::FutureReserved();
} else if (scanner()->current_token() ==
Token::FUTURE_STRICT_RESERVED_WORD) {
return Identifier::FutureStrictReserved();
} else if (scanner()->current_token() == Token::YIELD) {
return Identifier::Yield();
}
if (scanner()->is_literal_ascii()) {
// Detect strict-mode poison words.
if (scanner()->literal_length() == 4 &&
!strncmp(scanner()->literal_ascii_string().start(), "eval", 4)) {
return Identifier::Eval();
}
if (scanner()->literal_length() == 9 &&
!strncmp(scanner()->literal_ascii_string().start(), "arguments", 9)) {
return Identifier::Arguments();
}
}
return Identifier::Default();
}
// Parses an identifier that is valid for the current scope, in particular it
// fails on strict mode future reserved keywords in a strict scope. If
// allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or
// "arguments" as identifier even in strict mode (this is needed in cases like
// "var foo = eval;").
PreParser::Identifier PreParser::ParseIdentifier(
AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments,
bool* ok) {
Token::Value next = Next();
if (next == Token::IDENTIFIER) {
PreParser::Identifier name = GetIdentifierSymbol();
if (allow_eval_or_arguments == kDontAllowEvalOrArguments &&
!scope_->is_classic_mode() && name.IsEvalOrArguments()) {
ReportMessageAt(scanner()->location(), "strict_eval_arguments", NULL);
*ok = false;
}
return name;
} else if (scope_->is_classic_mode() &&
(next == Token::FUTURE_STRICT_RESERVED_WORD ||
(next == Token::YIELD && !scope_->is_generator()))) {
return GetIdentifierSymbol();
} else {
ReportUnexpectedToken(next);
*ok = false;
return Identifier::Default();
}
}
// Parses and identifier or a strict mode future reserved word, and indicate
// whether it is strict mode future reserved.
PreParser::Identifier PreParser::ParseIdentifierOrStrictReservedWord(
bool* is_strict_reserved, bool* ok) {
Token::Value next = Next();
if (next == Token::IDENTIFIER) {
*is_strict_reserved = false;
} else if (next == Token::FUTURE_STRICT_RESERVED_WORD ||
(next == Token::YIELD && !scope_->is_generator())) {
*is_strict_reserved = true;
} else {
ReportUnexpectedToken(next);
*ok = false;
return Identifier::Default();
}
return GetIdentifierSymbol();
}
PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) {
Token::Value next = Next();
if (next != Token::IDENTIFIER &&
next != Token::FUTURE_RESERVED_WORD &&
next != Token::FUTURE_STRICT_RESERVED_WORD &&
!Token::IsKeyword(next)) {
ReportUnexpectedToken(next);
*ok = false;
return Identifier::Default();
}
return GetIdentifierSymbol();
}
#undef CHECK_OK
// This function reads an identifier and determines whether or not it
// is 'get' or 'set'.
PreParser::Identifier PreParser::ParseIdentifierNameOrGetOrSet(bool* is_get,
bool* is_set,
bool* ok) {
Identifier result = ParseIdentifierName(ok);
if (!*ok) return Identifier::Default();
if (scanner()->is_literal_ascii() &&
scanner()->literal_length() == 3) {
const char* token = scanner()->literal_ascii_string().start();
*is_get = strncmp(token, "get", 3) == 0;
*is_set = !*is_get && strncmp(token, "set", 3) == 0;
}
return result;
}
void PreParser::ObjectLiteralChecker::CheckProperty(Token::Value property,
PropertyKind type,
bool* ok) {
int old;
if (property == Token::NUMBER) {
old = finder_.AddNumber(scanner()->literal_ascii_string(), type);
} else if (scanner()->is_literal_ascii()) {
old = finder_.AddAsciiSymbol(scanner()->literal_ascii_string(), type);
} else {
old = finder_.AddUtf16Symbol(scanner()->literal_utf16_string(), type);
}
PropertyKind old_type = static_cast<PropertyKind>(old);
if (HasConflict(old_type, type)) {
if (IsDataDataConflict(old_type, type)) {
// Both are data properties.
if (language_mode_ == CLASSIC_MODE) return;
parser()->ReportMessageAt(scanner()->location(),
"strict_duplicate_property");
} else if (IsDataAccessorConflict(old_type, type)) {
// Both a data and an accessor property with the same name.
parser()->ReportMessageAt(scanner()->location(),
"accessor_data_property");
} else {
ASSERT(IsAccessorAccessorConflict(old_type, type));
// Both accessors of the same type.
parser()->ReportMessageAt(scanner()->location(),
"accessor_get_set");
}
*ok = false;
}
}
} } // v8::internal } } // v8::internal
...@@ -36,19 +36,18 @@ namespace v8 { ...@@ -36,19 +36,18 @@ namespace v8 {
namespace internal { namespace internal {
// Common base class shared between parser and pre-parser. // Common base class shared between parser and pre-parser.
template <typename Traits> class ParserBase {
class ParserBase : public Traits {
public: public:
ParserBase(Scanner* scanner, uintptr_t stack_limit, ParserBase(Scanner* scanner, uintptr_t stack_limit)
typename Traits::ParserType this_object) : scanner_(scanner),
: Traits(this_object),
scanner_(scanner),
stack_limit_(stack_limit), stack_limit_(stack_limit),
stack_overflow_(false), stack_overflow_(false),
allow_lazy_(false), allow_lazy_(false),
allow_natives_syntax_(false), allow_natives_syntax_(false),
allow_generators_(false), allow_generators_(false),
allow_for_of_(false) { } allow_for_of_(false) { }
// TODO(mstarzinger): Only virtual until message reporting has been unified.
virtual ~ParserBase() { }
// Getters that indicate whether certain syntactical constructs are // Getters that indicate whether certain syntactical constructs are
// allowed to be parsed by this instance of the parser. // allowed to be parsed by this instance of the parser.
...@@ -88,6 +87,8 @@ class ParserBase : public Traits { ...@@ -88,6 +87,8 @@ class ParserBase : public Traits {
bool stack_overflow() const { return stack_overflow_; } bool stack_overflow() const { return stack_overflow_; }
void set_stack_overflow() { stack_overflow_ = true; } void set_stack_overflow() { stack_overflow_ = true; }
virtual bool is_classic_mode() = 0;
INLINE(Token::Value peek()) { INLINE(Token::Value peek()) {
if (stack_overflow_) return Token::ILLEGAL; if (stack_overflow_) return Token::ILLEGAL;
return scanner()->peek(); return scanner()->peek();
...@@ -131,99 +132,25 @@ class ParserBase : public Traits { ...@@ -131,99 +132,25 @@ class ParserBase : public Traits {
} }
} }
void ExpectSemicolon(bool* ok) { bool peek_any_identifier();
// Check for automatic semicolon insertion according to void ExpectSemicolon(bool* ok);
// the rules given in ECMA-262, section 7.9, page 21. bool CheckContextualKeyword(Vector<const char> keyword);
Token::Value tok = peek(); void ExpectContextualKeyword(Vector<const char> keyword, bool* ok);
if (tok == Token::SEMICOLON) {
Next();
return;
}
if (scanner()->HasAnyLineTerminatorBeforeNext() ||
tok == Token::RBRACE ||
tok == Token::EOS) {
return;
}
Expect(Token::SEMICOLON, ok);
}
bool peek_any_identifier() {
Token::Value next = peek();
return next == Token::IDENTIFIER ||
next == Token::FUTURE_RESERVED_WORD ||
next == Token::FUTURE_STRICT_RESERVED_WORD ||
next == Token::YIELD;
}
bool CheckContextualKeyword(Vector<const char> keyword) {
if (peek() == Token::IDENTIFIER &&
scanner()->is_next_contextual_keyword(keyword)) {
Consume(Token::IDENTIFIER);
return true;
}
return false;
}
void ExpectContextualKeyword(Vector<const char> keyword, bool* ok) {
Expect(Token::IDENTIFIER, ok);
if (!*ok) return;
if (!scanner()->is_literal_contextual_keyword(keyword)) {
ReportUnexpectedToken(scanner()->current_token());
*ok = false;
}
}
// Checks whether an octal literal was last seen between beg_pos and end_pos. // Strict mode octal literal validation.
// If so, reports an error. Only called for strict mode. void CheckOctalLiteral(int beg_pos, int end_pos, bool* ok);
void CheckOctalLiteral(int beg_pos, int end_pos, bool* ok) {
Scanner::Location octal = scanner()->octal_position();
if (octal.IsValid() && beg_pos <= octal.beg_pos &&
octal.end_pos <= end_pos) {
ReportMessageAt(octal, "strict_octal_literal");
scanner()->clear_octal_position();
*ok = false;
}
}
// Determine precedence of given token. // Determine precedence of given token.
static int Precedence(Token::Value token, bool accept_IN) { static int Precedence(Token::Value token, bool accept_IN);
if (token == Token::IN && !accept_IN)
return 0; // 0 precedence will terminate binary expression parsing
return Token::Precedence(token);
}
// Report syntax errors. // Report syntax errors.
void ReportMessage(const char* message, Vector<const char*> args) {
Scanner::Location source_location = scanner()->location();
Traits::ReportMessageAt(source_location, message, args);
}
void ReportMessageAt(Scanner::Location location, const char* message) {
Traits::ReportMessageAt(location, message, Vector<const char*>::empty());
}
void ReportUnexpectedToken(Token::Value token); void ReportUnexpectedToken(Token::Value token);
void ReportMessageAt(Scanner::Location location, const char* type) {
// Recursive descent functions: ReportMessageAt(location, type, Vector<const char*>::empty());
}
// Parses an identifier that is valid for the current scope, in particular it virtual void ReportMessageAt(Scanner::Location source_location,
// fails on strict mode future reserved keywords in a strict scope. If const char* message,
// allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or Vector<const char*> args) = 0;
// "arguments" as identifier even in strict mode (this is needed in cases like
// "var foo = eval;").
typename Traits::IdentifierType ParseIdentifier(
AllowEvalOrArgumentsAsIdentifier,
bool* ok);
// Parses an identifier or a strict mode future reserved word, and indicate
// whether it is strict mode future reserved.
typename Traits::IdentifierType ParseIdentifierOrStrictReservedWord(
bool* is_strict_reserved,
bool* ok);
typename Traits::IdentifierType ParseIdentifierName(bool* ok);
// Parses an identifier and determines whether or not it is 'get' or 'set'.
typename Traits::IdentifierType ParseIdentifierNameOrGetOrSet(bool* is_get,
bool* is_set,
bool* ok);
// Used to detect duplicates in object literals. Each of the values // Used to detect duplicates in object literals. Each of the values
// kGetterProperty, kSetterProperty and kValueProperty represents // kGetterProperty, kSetterProperty and kValueProperty represents
...@@ -291,25 +218,109 @@ class ParserBase : public Traits { ...@@ -291,25 +218,109 @@ class ParserBase : public Traits {
}; };
class PreParserIdentifier { // Preparsing checks a JavaScript program and emits preparse-data that helps
// a later parsing to be faster.
// See preparse-data-format.h for the data format.
// The PreParser checks that the syntax follows the grammar for JavaScript,
// and collects some information about the program along the way.
// The grammar check is only performed in order to understand the program
// sufficiently to deduce some information about it, that can be used
// to speed up later parsing. Finding errors is not the goal of pre-parsing,
// rather it is to speed up properly written and correct programs.
// That means that contextual checks (like a label being declared where
// it is used) are generally omitted.
class PreParser : public ParserBase {
public:
enum PreParseResult {
kPreParseStackOverflow,
kPreParseSuccess
};
PreParser(Scanner* scanner,
ParserRecorder* log,
uintptr_t stack_limit)
: ParserBase(scanner, stack_limit),
log_(log),
scope_(NULL),
parenthesized_function_(false) { }
~PreParser() {}
// Pre-parse the program from the character stream; returns true on
// success (even if parsing failed, the pre-parse data successfully
// captured the syntax error), and false if a stack-overflow happened
// during parsing.
PreParseResult PreParseProgram() {
Scope top_scope(&scope_, kTopLevelScope);
bool ok = true;
int start_position = scanner()->peek_location().beg_pos;
ParseSourceElements(Token::EOS, &ok);
if (stack_overflow()) return kPreParseStackOverflow;
if (!ok) {
ReportUnexpectedToken(scanner()->current_token());
} else if (!scope_->is_classic_mode()) {
CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok);
}
return kPreParseSuccess;
}
// Parses a single function literal, from the opening parentheses before
// parameters to the closing brace after the body.
// Returns a FunctionEntry describing the body of the function in enough
// detail that it can be lazily compiled.
// The scanner is expected to have matched the "function" or "function*"
// keyword and parameters, and have consumed the initial '{'.
// At return, unless an error occurred, the scanner is positioned before the
// the final '}'.
PreParseResult PreParseLazyFunction(LanguageMode mode,
bool is_generator,
ParserRecorder* log);
private:
// These types form an algebra over syntactic categories that is just
// rich enough to let us recognize and propagate the constructs that
// are either being counted in the preparser data, or is important
// to throw the correct syntax error exceptions.
enum ScopeType {
kTopLevelScope,
kFunctionScope
};
enum VariableDeclarationContext {
kSourceElement,
kStatement,
kForStatement
};
// If a list of variable declarations includes any initializers.
enum VariableDeclarationProperties {
kHasInitializers,
kHasNoInitializers
};
class Expression;
class Identifier {
public: public:
static PreParserIdentifier Default() { static Identifier Default() {
return PreParserIdentifier(kUnknownIdentifier); return Identifier(kUnknownIdentifier);
} }
static PreParserIdentifier Eval() { static Identifier Eval() {
return PreParserIdentifier(kEvalIdentifier); return Identifier(kEvalIdentifier);
} }
static PreParserIdentifier Arguments() { static Identifier Arguments() {
return PreParserIdentifier(kArgumentsIdentifier); return Identifier(kArgumentsIdentifier);
} }
static PreParserIdentifier FutureReserved() { static Identifier FutureReserved() {
return PreParserIdentifier(kFutureReservedIdentifier); return Identifier(kFutureReservedIdentifier);
} }
static PreParserIdentifier FutureStrictReserved() { static Identifier FutureStrictReserved() {
return PreParserIdentifier(kFutureStrictReservedIdentifier); return Identifier(kFutureStrictReservedIdentifier);
} }
static PreParserIdentifier Yield() { static Identifier Yield() {
return PreParserIdentifier(kYieldIdentifier); return Identifier(kYieldIdentifier);
} }
bool IsEval() { return type_ == kEvalIdentifier; } bool IsEval() { return type_ == kEvalIdentifier; }
bool IsArguments() { return type_ == kArgumentsIdentifier; } bool IsArguments() { return type_ == kArgumentsIdentifier; }
...@@ -330,55 +341,55 @@ class PreParserIdentifier { ...@@ -330,55 +341,55 @@ class PreParserIdentifier {
kEvalIdentifier, kEvalIdentifier,
kArgumentsIdentifier kArgumentsIdentifier
}; };
explicit PreParserIdentifier(Type type) : type_(type) {} explicit Identifier(Type type) : type_(type) { }
Type type_; Type type_;
friend class PreParserExpression; friend class Expression;
}; };
// Bits 0 and 1 are used to identify the type of expression: // Bits 0 and 1 are used to identify the type of expression:
// If bit 0 is set, it's an identifier. // If bit 0 is set, it's an identifier.
// if bit 1 is set, it's a string literal. // if bit 1 is set, it's a string literal.
// If neither is set, it's no particular type, and both set isn't // If neither is set, it's no particular type, and both set isn't
// use yet. // use yet.
class PreParserExpression { class Expression {
public: public:
static PreParserExpression Default() { static Expression Default() {
return PreParserExpression(kUnknownExpression); return Expression(kUnknownExpression);
} }
static PreParserExpression FromIdentifier(PreParserIdentifier id) { static Expression FromIdentifier(Identifier id) {
return PreParserExpression(kIdentifierFlag | return Expression(kIdentifierFlag | (id.type_ << kIdentifierShift));
(id.type_ << kIdentifierShift));
} }
static PreParserExpression StringLiteral() { static Expression StringLiteral() {
return PreParserExpression(kUnknownStringLiteral); return Expression(kUnknownStringLiteral);
} }
static PreParserExpression UseStrictStringLiteral() { static Expression UseStrictStringLiteral() {
return PreParserExpression(kUseStrictString); return Expression(kUseStrictString);
} }
static PreParserExpression This() { static Expression This() {
return PreParserExpression(kThisExpression); return Expression(kThisExpression);
} }
static PreParserExpression ThisProperty() { static Expression ThisProperty() {
return PreParserExpression(kThisPropertyExpression); return Expression(kThisPropertyExpression);
} }
static PreParserExpression StrictFunction() { static Expression StrictFunction() {
return PreParserExpression(kStrictFunctionExpression); return Expression(kStrictFunctionExpression);
} }
bool IsIdentifier() { return (code_ & kIdentifierFlag) != 0; } bool IsIdentifier() {
return (code_ & kIdentifierFlag) != 0;
}
// Only works corretly if it is actually an identifier expression. // Only works corretly if it is actually an identifier expression.
PreParserIdentifier AsIdentifier() { PreParser::Identifier AsIdentifier() {
return PreParserIdentifier( return PreParser::Identifier(
static_cast<PreParserIdentifier::Type>(code_ >> kIdentifierShift)); static_cast<PreParser::Identifier::Type>(code_ >> kIdentifierShift));
} }
bool IsStringLiteral() { return (code_ & kStringLiteralFlag) != 0; } bool IsStringLiteral() { return (code_ & kStringLiteralFlag) != 0; }
...@@ -387,11 +398,17 @@ class PreParserExpression { ...@@ -387,11 +398,17 @@ class PreParserExpression {
return (code_ & kStringLiteralMask) == kUseStrictString; return (code_ & kStringLiteralMask) == kUseStrictString;
} }
bool IsThis() { return code_ == kThisExpression; } bool IsThis() {
return code_ == kThisExpression;
}
bool IsThisProperty() { return code_ == kThisPropertyExpression; } bool IsThisProperty() {
return code_ == kThisPropertyExpression;
}
bool IsStrictFunction() { return code_ == kStrictFunctionExpression; } bool IsStrictFunction() {
return code_ == kStrictFunctionExpression;
}
private: private:
// First two/three bits are used as flags. // First two/three bits are used as flags.
...@@ -414,138 +431,9 @@ class PreParserExpression { ...@@ -414,138 +431,9 @@ class PreParserExpression {
kStrictFunctionExpression = 12 kStrictFunctionExpression = 12
}; };
explicit PreParserExpression(int expression_code) : code_(expression_code) {} explicit Expression(int expression_code) : code_(expression_code) { }
int code_; int code_;
};
class PreParser;
class PreParserTraits {
public:
typedef PreParser* ParserType;
// Return types for traversing functions.
typedef PreParserIdentifier IdentifierType;
explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
// Helper functions for recursive descent.
bool is_classic_mode() const;
bool is_generator() const;
static bool IsEvalOrArguments(IdentifierType identifier) {
return identifier.IsEvalOrArguments();
}
// Reporting errors.
void ReportMessageAt(Scanner::Location location,
const char* message,
Vector<const char*> args);
void ReportMessageAt(Scanner::Location location,
const char* type,
const char* name_opt);
void ReportMessageAt(int start_pos,
int end_pos,
const char* type,
const char* name_opt);
// Identifiers:
static IdentifierType EmptyIdentifier() {
return PreParserIdentifier::Default();
}
IdentifierType GetSymbol();
private:
PreParser* pre_parser_;
};
// Preparsing checks a JavaScript program and emits preparse-data that helps
// a later parsing to be faster.
// See preparse-data-format.h for the data format.
// The PreParser checks that the syntax follows the grammar for JavaScript,
// and collects some information about the program along the way.
// The grammar check is only performed in order to understand the program
// sufficiently to deduce some information about it, that can be used
// to speed up later parsing. Finding errors is not the goal of pre-parsing,
// rather it is to speed up properly written and correct programs.
// That means that contextual checks (like a label being declared where
// it is used) are generally omitted.
class PreParser : public ParserBase<PreParserTraits> {
public:
typedef PreParserIdentifier Identifier;
typedef PreParserExpression Expression;
enum PreParseResult {
kPreParseStackOverflow,
kPreParseSuccess
};
PreParser(Scanner* scanner,
ParserRecorder* log,
uintptr_t stack_limit)
: ParserBase(scanner, stack_limit, this),
log_(log),
scope_(NULL),
parenthesized_function_(false) { }
~PreParser() {}
// Pre-parse the program from the character stream; returns true on
// success (even if parsing failed, the pre-parse data successfully
// captured the syntax error), and false if a stack-overflow happened
// during parsing.
PreParseResult PreParseProgram() {
Scope top_scope(&scope_, kTopLevelScope);
bool ok = true;
int start_position = scanner()->peek_location().beg_pos;
ParseSourceElements(Token::EOS, &ok);
if (stack_overflow()) return kPreParseStackOverflow;
if (!ok) {
ReportUnexpectedToken(scanner()->current_token());
} else if (!scope_->is_classic_mode()) {
CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok);
}
return kPreParseSuccess;
}
// Parses a single function literal, from the opening parentheses before
// parameters to the closing brace after the body.
// Returns a FunctionEntry describing the body of the function in enough
// detail that it can be lazily compiled.
// The scanner is expected to have matched the "function" or "function*"
// keyword and parameters, and have consumed the initial '{'.
// At return, unless an error occurred, the scanner is positioned before the
// the final '}'.
PreParseResult PreParseLazyFunction(LanguageMode mode,
bool is_generator,
ParserRecorder* log);
private:
friend class PreParserTraits;
// These types form an algebra over syntactic categories that is just
// rich enough to let us recognize and propagate the constructs that
// are either being counted in the preparser data, or is important
// to throw the correct syntax error exceptions.
enum ScopeType {
kTopLevelScope,
kFunctionScope
};
enum VariableDeclarationContext {
kSourceElement,
kStatement,
kForStatement
};
// If a list of variable declarations includes any initializers.
enum VariableDeclarationProperties {
kHasInitializers,
kHasNoInitializers
}; };
class Statement { class Statement {
...@@ -658,6 +546,27 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -658,6 +546,27 @@ class PreParser : public ParserBase<PreParserTraits> {
bool is_generator_; bool is_generator_;
}; };
// Report syntax error
void ReportMessageAt(Scanner::Location location,
const char* message,
Vector<const char*> args) {
ReportMessageAt(location.beg_pos,
location.end_pos,
message,
args.length() > 0 ? args[0] : NULL);
}
void ReportMessageAt(Scanner::Location location,
const char* type,
const char* name_opt) {
log_->LogMessage(location.beg_pos, location.end_pos, type, name_opt);
}
void ReportMessageAt(int start_pos,
int end_pos,
const char* type,
const char* name_opt) {
log_->LogMessage(start_pos, end_pos, type, name_opt);
}
// All ParseXXX functions take as the last argument an *ok parameter // All ParseXXX functions take as the last argument an *ok parameter
// which is set to false if parsing failed; it is unchanged otherwise. // which is set to false if parsing failed; it is unchanged otherwise.
// By making the 'exception handling' explicit, we are forced to check // By making the 'exception handling' explicit, we are forced to check
...@@ -713,8 +622,18 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -713,8 +622,18 @@ class PreParser : public ParserBase<PreParserTraits> {
bool* ok); bool* ok);
void ParseLazyFunctionLiteralBody(bool* ok); void ParseLazyFunctionLiteralBody(bool* ok);
Identifier ParseIdentifier(AllowEvalOrArgumentsAsIdentifier, bool* ok);
Identifier ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved,
bool* ok);
Identifier ParseIdentifierName(bool* ok);
Identifier ParseIdentifierNameOrGetOrSet(bool* is_get,
bool* is_set,
bool* ok);
// Logs the currently parsed literal as a symbol in the preparser data. // Logs the currently parsed literal as a symbol in the preparser data.
void LogSymbol(); void LogSymbol();
// Log the currently parsed identifier.
Identifier GetIdentifierSymbol();
// Log the currently parsed string literal. // Log the currently parsed string literal.
Expression GetStringSymbol(); Expression GetStringSymbol();
...@@ -722,6 +641,10 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -722,6 +641,10 @@ class PreParser : public ParserBase<PreParserTraits> {
scope_->set_language_mode(language_mode); scope_->set_language_mode(language_mode);
} }
virtual bool is_classic_mode() {
return scope_->language_mode() == CLASSIC_MODE;
}
bool is_extended_mode() { bool is_extended_mode() {
return scope_->language_mode() == EXTENDED_MODE; return scope_->language_mode() == EXTENDED_MODE;
} }
...@@ -735,154 +658,6 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -735,154 +658,6 @@ class PreParser : public ParserBase<PreParserTraits> {
bool parenthesized_function_; bool parenthesized_function_;
}; };
template<class Traits>
void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
// We don't report stack overflows here, to avoid increasing the
// stack depth even further. Instead we report it after parsing is
// over, in ParseProgram.
if (token == Token::ILLEGAL && stack_overflow()) {
return;
}
Scanner::Location source_location = scanner()->location();
// Four of the tokens are treated specially
switch (token) {
case Token::EOS:
return ReportMessageAt(source_location, "unexpected_eos");
case Token::NUMBER:
return ReportMessageAt(source_location, "unexpected_token_number");
case Token::STRING:
return ReportMessageAt(source_location, "unexpected_token_string");
case Token::IDENTIFIER:
return ReportMessageAt(source_location, "unexpected_token_identifier");
case Token::FUTURE_RESERVED_WORD:
return ReportMessageAt(source_location, "unexpected_reserved");
case Token::YIELD:
case Token::FUTURE_STRICT_RESERVED_WORD:
return ReportMessageAt(
source_location,
this->is_classic_mode() ? "unexpected_token_identifier"
: "unexpected_strict_reserved");
default:
const char* name = Token::String(token);
ASSERT(name != NULL);
Traits::ReportMessageAt(
source_location, "unexpected_token", Vector<const char*>(&name, 1));
}
}
template<class Traits>
typename Traits::IdentifierType ParserBase<Traits>::ParseIdentifier(
AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments,
bool* ok) {
Token::Value next = Next();
if (next == Token::IDENTIFIER) {
typename Traits::IdentifierType name = this->GetSymbol();
if (allow_eval_or_arguments == kDontAllowEvalOrArguments &&
!this->is_classic_mode() && this->IsEvalOrArguments(name)) {
ReportMessageAt(scanner()->location(), "strict_eval_arguments");
*ok = false;
}
return name;
} else if (this->is_classic_mode() &&
(next == Token::FUTURE_STRICT_RESERVED_WORD ||
(next == Token::YIELD && !this->is_generator()))) {
return this->GetSymbol();
} else {
this->ReportUnexpectedToken(next);
*ok = false;
return Traits::EmptyIdentifier();
}
}
template <class Traits>
typename Traits::IdentifierType ParserBase<
Traits>::ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved,
bool* ok) {
Token::Value next = Next();
if (next == Token::IDENTIFIER) {
*is_strict_reserved = false;
} else if (next == Token::FUTURE_STRICT_RESERVED_WORD ||
(next == Token::YIELD && !this->is_generator())) {
*is_strict_reserved = true;
} else {
ReportUnexpectedToken(next);
*ok = false;
return Traits::EmptyIdentifier();
}
return this->GetSymbol();
}
template <class Traits>
typename Traits::IdentifierType ParserBase<Traits>::ParseIdentifierName(
bool* ok) {
Token::Value next = Next();
if (next != Token::IDENTIFIER && next != Token::FUTURE_RESERVED_WORD &&
next != Token::FUTURE_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) {
this->ReportUnexpectedToken(next);
*ok = false;
return Traits::EmptyIdentifier();
}
return this->GetSymbol();
}
template <class Traits>
typename Traits::IdentifierType
ParserBase<Traits>::ParseIdentifierNameOrGetOrSet(bool* is_get,
bool* is_set,
bool* ok) {
typename Traits::IdentifierType result = ParseIdentifierName(ok);
if (!*ok) return Traits::EmptyIdentifier();
if (scanner()->is_literal_ascii() &&
scanner()->literal_length() == 3) {
const char* token = scanner()->literal_ascii_string().start();
*is_get = strncmp(token, "get", 3) == 0;
*is_set = !*is_get && strncmp(token, "set", 3) == 0;
}
return result;
}
template <typename Traits>
void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty(
Token::Value property,
PropertyKind type,
bool* ok) {
int old;
if (property == Token::NUMBER) {
old = finder_.AddNumber(scanner()->literal_ascii_string(), type);
} else if (scanner()->is_literal_ascii()) {
old = finder_.AddAsciiSymbol(scanner()->literal_ascii_string(), type);
} else {
old = finder_.AddUtf16Symbol(scanner()->literal_utf16_string(), type);
}
PropertyKind old_type = static_cast<PropertyKind>(old);
if (HasConflict(old_type, type)) {
if (IsDataDataConflict(old_type, type)) {
// Both are data properties.
if (language_mode_ == CLASSIC_MODE) return;
parser()->ReportMessageAt(scanner()->location(),
"strict_duplicate_property");
} else if (IsDataAccessorConflict(old_type, type)) {
// Both a data and an accessor property with the same name.
parser()->ReportMessageAt(scanner()->location(),
"accessor_data_property");
} else {
ASSERT(IsAccessorAccessorConflict(old_type, type));
// Both accessors of the same type.
parser()->ReportMessageAt(scanner()->location(),
"accessor_get_set");
}
*ok = false;
}
}
} } // v8::internal } } // v8::internal
#endif // V8_PREPARSER_H #endif // V8_PREPARSER_H
...@@ -1108,9 +1108,8 @@ enum ParserSyncTestResult { ...@@ -1108,9 +1108,8 @@ enum ParserSyncTestResult {
kError kError
}; };
template <typename Traits>
void SetParserFlags(i::ParserBase<Traits>* parser, void SetParserFlags(i::ParserBase* parser, i::EnumSet<ParserFlag> flags) {
i::EnumSet<ParserFlag> flags) {
parser->set_allow_lazy(flags.Contains(kAllowLazy)); parser->set_allow_lazy(flags.Contains(kAllowLazy));
parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
......
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