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

Parser fix: check allow_harmony_scoping() instead of FLAG_harmony_scoping.

Without this fix, ParserBase::set_allow_harmony_scoping() and the
kAllowHarmonyScoping in test-parsing.cc don't have any effect, and we end up not
running the tests with harmony scoping allowed.

R=rossberg@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20200 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5fd9ddbc
...@@ -893,7 +893,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, ...@@ -893,7 +893,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
} }
if (ok && FLAG_harmony_scoping && strict_mode() == STRICT) { if (ok && allow_harmony_scoping() && strict_mode() == STRICT) {
CheckConflictingVarDeclarations(scope_, &ok); CheckConflictingVarDeclarations(scope_, &ok);
} }
...@@ -1698,7 +1698,7 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { ...@@ -1698,7 +1698,7 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
// because the var declaration is hoisted to the function scope where 'x' // because the var declaration is hoisted to the function scope where 'x'
// is already bound. // is already bound.
ASSERT(IsDeclaredVariableMode(var->mode())); ASSERT(IsDeclaredVariableMode(var->mode()));
if (FLAG_harmony_scoping && strict_mode() == STRICT) { if (allow_harmony_scoping() && strict_mode() == STRICT) {
// In harmony we treat re-declarations as early errors. See // In harmony we treat re-declarations as early errors. See
// ES5 16 for a definition of early errors. // ES5 16 for a definition of early errors.
SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS);
...@@ -1876,7 +1876,7 @@ Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { ...@@ -1876,7 +1876,7 @@ Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) {
// In extended mode, a function behaves as a lexical binding, except in the // In extended mode, a function behaves as a lexical binding, except in the
// global scope. // global scope.
VariableMode mode = VariableMode mode =
FLAG_harmony_scoping && allow_harmony_scoping() &&
strict_mode() == STRICT && !scope_->is_global_scope() ? LET : VAR; strict_mode() == STRICT && !scope_->is_global_scope() ? LET : VAR;
VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue());
Declaration* declaration = Declaration* declaration =
...@@ -1888,7 +1888,7 @@ Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { ...@@ -1888,7 +1888,7 @@ Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) {
Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) {
if (FLAG_harmony_scoping && strict_mode() == STRICT) { if (allow_harmony_scoping() && strict_mode() == STRICT) {
return ParseScopedBlock(labels, ok); return ParseScopedBlock(labels, ok);
} }
...@@ -2016,7 +2016,7 @@ Block* Parser::ParseVariableDeclarations( ...@@ -2016,7 +2016,7 @@ Block* Parser::ParseVariableDeclarations(
init_op = Token::INIT_CONST_LEGACY; init_op = Token::INIT_CONST_LEGACY;
break; break;
case STRICT: case STRICT:
if (FLAG_harmony_scoping) { if (allow_harmony_scoping()) {
if (var_context == kStatement) { if (var_context == kStatement) {
// In strict mode 'const' declarations are only allowed in source // In strict mode 'const' declarations are only allowed in source
// element positions. // element positions.
...@@ -2043,7 +2043,7 @@ Block* Parser::ParseVariableDeclarations( ...@@ -2043,7 +2043,7 @@ Block* Parser::ParseVariableDeclarations(
// contained in extended code. // contained in extended code.
// //
// TODO(rossberg): make 'let' a legal identifier in sloppy mode. // TODO(rossberg): make 'let' a legal identifier in sloppy mode.
if (!FLAG_harmony_scoping || strict_mode() == SLOPPY) { if (!allow_harmony_scoping() || strict_mode() == SLOPPY) {
ReportMessage("illegal_let", Vector<const char*>::empty()); ReportMessage("illegal_let", Vector<const char*>::empty());
*ok = false; *ok = false;
return NULL; return NULL;
...@@ -2670,7 +2670,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { ...@@ -2670,7 +2670,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
Target target(&this->target_stack_, &catch_collector); Target target(&this->target_stack_, &catch_collector);
VariableMode mode = VariableMode mode =
FLAG_harmony_scoping && strict_mode() == STRICT ? LET : VAR; allow_harmony_scoping() && strict_mode() == STRICT ? LET : VAR;
catch_variable = catch_variable =
catch_scope->DeclareLocal(name, mode, kCreatedInitialized); catch_scope->DeclareLocal(name, mode, kCreatedInitialized);
...@@ -3181,7 +3181,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -3181,7 +3181,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
Scope* original_declaration_scope = original_scope_->DeclarationScope(); Scope* original_declaration_scope = original_scope_->DeclarationScope();
Scope* scope = Scope* scope =
function_type == FunctionLiteral::DECLARATION && function_type == FunctionLiteral::DECLARATION &&
(!FLAG_harmony_scoping || strict_mode() == SLOPPY) && (!allow_harmony_scoping() || strict_mode() == SLOPPY) &&
(original_scope_ == original_declaration_scope || (original_scope_ == original_declaration_scope ||
declaration_scope != original_declaration_scope) declaration_scope != original_declaration_scope)
? NewScope(declaration_scope, FUNCTION_SCOPE) ? NewScope(declaration_scope, FUNCTION_SCOPE)
...@@ -3272,11 +3272,12 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -3272,11 +3272,12 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
Variable* fvar = NULL; Variable* fvar = NULL;
Token::Value fvar_init_op = Token::INIT_CONST_LEGACY; Token::Value fvar_init_op = Token::INIT_CONST_LEGACY;
if (function_type == FunctionLiteral::NAMED_EXPRESSION) { if (function_type == FunctionLiteral::NAMED_EXPRESSION) {
if (FLAG_harmony_scoping && strict_mode() == STRICT) { if (allow_harmony_scoping() && strict_mode() == STRICT) {
fvar_init_op = Token::INIT_CONST; fvar_init_op = Token::INIT_CONST;
} }
VariableMode fvar_mode = FLAG_harmony_scoping && strict_mode() == STRICT VariableMode fvar_mode =
? CONST : CONST_LEGACY; allow_harmony_scoping() && strict_mode() == STRICT ? CONST
: CONST_LEGACY;
fvar = new(zone()) Variable(scope_, fvar = new(zone()) Variable(scope_,
function_name, fvar_mode, true /* is valid LHS */, function_name, fvar_mode, true /* is valid LHS */,
Variable::NORMAL, kCreatedInitialized, Interface::NewConst()); Variable::NORMAL, kCreatedInitialized, Interface::NewConst());
...@@ -3498,7 +3499,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -3498,7 +3499,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); dont_optimize_reason = factory()->visitor()->dont_optimize_reason();
} }
if (FLAG_harmony_scoping && strict_mode() == STRICT) { if (allow_harmony_scoping() && strict_mode() == STRICT) {
CheckConflictingVarDeclarations(scope, CHECK_OK); CheckConflictingVarDeclarations(scope, CHECK_OK);
} }
......
...@@ -379,7 +379,7 @@ PreParser::Statement PreParser::ParseBlock(bool* ok) { ...@@ -379,7 +379,7 @@ PreParser::Statement PreParser::ParseBlock(bool* ok) {
// //
Expect(Token::LBRACE, CHECK_OK); Expect(Token::LBRACE, CHECK_OK);
while (peek() != Token::RBRACE) { while (peek() != Token::RBRACE) {
if (FLAG_harmony_scoping && strict_mode() == STRICT) { if (allow_harmony_scoping() && strict_mode() == STRICT) {
ParseSourceElement(CHECK_OK); ParseSourceElement(CHECK_OK);
} else { } else {
ParseStatement(CHECK_OK); ParseStatement(CHECK_OK);
...@@ -444,7 +444,7 @@ PreParser::Statement PreParser::ParseVariableDeclarations( ...@@ -444,7 +444,7 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
// non-harmony semantics in sloppy mode. // non-harmony semantics in sloppy mode.
Consume(Token::CONST); Consume(Token::CONST);
if (strict_mode() == STRICT) { if (strict_mode() == STRICT) {
if (FLAG_harmony_scoping) { if (allow_harmony_scoping()) {
if (var_context != kSourceElement && var_context != kForStatement) { if (var_context != kSourceElement && var_context != kForStatement) {
ReportMessageAt(scanner()->peek_location(), "unprotected_const"); ReportMessageAt(scanner()->peek_location(), "unprotected_const");
*ok = false; *ok = false;
...@@ -467,7 +467,7 @@ PreParser::Statement PreParser::ParseVariableDeclarations( ...@@ -467,7 +467,7 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
// contained in extended code. // contained in extended code.
// //
// TODO(rossberg): make 'let' a legal identifier in sloppy mode. // TODO(rossberg): make 'let' a legal identifier in sloppy mode.
if (!FLAG_harmony_scoping || strict_mode() == SLOPPY) { if (!allow_harmony_scoping() || strict_mode() == SLOPPY) {
ReportMessageAt(scanner()->peek_location(), "illegal_let"); ReportMessageAt(scanner()->peek_location(), "illegal_let");
*ok = false; *ok = false;
return Statement::Default(); return Statement::Default();
......
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