Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: src/parser.cc

Issue 7983006: Fix pre-parsing function declarations. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/preparser.cc » ('j') | src/preparser.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 Isolate* isolate_; 1096 Isolate* isolate_;
1097 bool only_simple_this_property_assignments_; 1097 bool only_simple_this_property_assignments_;
1098 ZoneStringList* names_; 1098 ZoneStringList* names_;
1099 ZoneList<int>* assigned_arguments_; 1099 ZoneList<int>* assigned_arguments_;
1100 ZoneObjectList* assigned_constants_; 1100 ZoneObjectList* assigned_constants_;
1101 }; 1101 };
1102 1102
1103 1103
1104 Statement* Parser::ParseSourceElement(ZoneStringList* labels, 1104 Statement* Parser::ParseSourceElement(ZoneStringList* labels,
1105 bool* ok) { 1105 bool* ok) {
1106 // (Ecma 262 5th Edition, clause 14):
1107 // SourceElement:
1108 // Statement
1109 // FunctionDeclaration
1110 //
1111 // In harmony mode we allow additionally the following productions
1112 // SourceElement:
1113 // LetDeclaration
1114
1106 if (peek() == Token::FUNCTION) { 1115 if (peek() == Token::FUNCTION) {
1107 // FunctionDeclaration is only allowed in the context of SourceElements
1108 // (Ecma 262 5th Edition, clause 14):
1109 // SourceElement:
1110 // Statement
1111 // FunctionDeclaration
1112 // Common language extension is to allow function declaration in place
1113 // of any statement. This language extension is disabled in strict mode.
1114 return ParseFunctionDeclaration(ok); 1116 return ParseFunctionDeclaration(ok);
1115 } else if (peek() == Token::LET) { 1117 } else if (peek() == Token::LET) {
1116 return ParseVariableStatement(kSourceElement, ok); 1118 return ParseVariableStatement(kSourceElement, ok);
1117 } else { 1119 } else {
1118 return ParseStatement(labels, ok); 1120 return ParseStatement(labels, ok);
1119 } 1121 }
1120 } 1122 }
1121 1123
1122 1124
1123 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, 1125 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
1124 int end_token, 1126 int end_token,
1125 bool* ok) { 1127 bool* ok) {
1126 // SourceElements :: 1128 // SourceElements ::
1127 // (Statement)* <end_token> 1129 // (SourceElement)* <end_token>
1128 1130
1129 // Allocate a target stack to use for this set of source 1131 // Allocate a target stack to use for this set of source
1130 // elements. This way, all scripts and functions get their own 1132 // elements. This way, all scripts and functions get their own
1131 // target stack thus avoiding illegal breaks and continues across 1133 // target stack thus avoiding illegal breaks and continues across
1132 // functions. 1134 // functions.
1133 TargetScope scope(&this->target_stack_); 1135 TargetScope scope(&this->target_stack_);
1134 1136
1135 ASSERT(processor != NULL); 1137 ASSERT(processor != NULL);
1136 InitializationBlockFinder block_finder(top_scope_, target_stack_); 1138 InitializationBlockFinder block_finder(top_scope_, target_stack_);
1137 ThisNamedPropertyAssigmentFinder this_property_assignment_finder(isolate()); 1139 ThisNamedPropertyAssigmentFinder this_property_assignment_finder(isolate());
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 Target target(&this->target_stack_, result); 1290 Target target(&this->target_stack_, result);
1289 TryStatement* statement = ParseTryStatement(CHECK_OK); 1291 TryStatement* statement = ParseTryStatement(CHECK_OK);
1290 if (statement) { 1292 if (statement) {
1291 statement->set_statement_pos(statement_pos); 1293 statement->set_statement_pos(statement_pos);
1292 } 1294 }
1293 if (result) result->AddStatement(statement); 1295 if (result) result->AddStatement(statement);
1294 return result; 1296 return result;
1295 } 1297 }
1296 1298
1297 case Token::FUNCTION: { 1299 case Token::FUNCTION: {
1298 // In strict mode, FunctionDeclaration is only allowed in the context 1300 // FunctionDeclaration is only allowed in the context of SourceElements
1299 // of SourceElements. 1301 // (Ecma 262 5th Edition, clause 14):
1302 // SourceElement:
1303 // Statement
1304 // FunctionDeclaration
1305 // Common language extension is to allow function declaration in place
1306 // of any statement. This language extension is disabled in strict mode.
1300 if (top_scope_->is_strict_mode()) { 1307 if (top_scope_->is_strict_mode()) {
1301 ReportMessageAt(scanner().peek_location(), "strict_function", 1308 ReportMessageAt(scanner().peek_location(), "strict_function",
1302 Vector<const char*>::empty()); 1309 Vector<const char*>::empty());
1303 *ok = false; 1310 *ok = false;
1304 return NULL; 1311 return NULL;
1305 } 1312 }
1306 return ParseFunctionDeclaration(ok); 1313 return ParseFunctionDeclaration(ok);
1307 } 1314 }
1308 1315
1309 case Token::DEBUGGER: 1316 case Token::DEBUGGER:
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 result->AddStatement(stat); 1555 result->AddStatement(stat);
1549 block_finder.Update(stat); 1556 block_finder.Update(stat);
1550 } 1557 }
1551 } 1558 }
1552 Expect(Token::RBRACE, CHECK_OK); 1559 Expect(Token::RBRACE, CHECK_OK);
1553 return result; 1560 return result;
1554 } 1561 }
1555 1562
1556 1563
1557 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { 1564 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) {
1565 // The harmony mode uses source elements instead of statements.
1566 //
1567 // Block ::
1568 // '{' SourceElement* '}'
1569
1558 // Construct block expecting 16 statements. 1570 // Construct block expecting 16 statements.
1559 Block* body = new(zone()) Block(isolate(), labels, 16, false); 1571 Block* body = new(zone()) Block(isolate(), labels, 16, false);
1560 Scope* saved_scope = top_scope_; 1572 Scope* saved_scope = top_scope_;
1561 Scope* block_scope = NewScope(top_scope_, 1573 Scope* block_scope = NewScope(top_scope_,
1562 Scope::BLOCK_SCOPE, 1574 Scope::BLOCK_SCOPE,
1563 inside_with()); 1575 inside_with());
1564 if (top_scope_->is_strict_mode()) { 1576 if (top_scope_->is_strict_mode()) {
1565 block_scope->EnableStrictMode(); 1577 block_scope->EnableStrictMode();
1566 } 1578 }
1567 top_scope_ = block_scope; 1579 top_scope_ = block_scope;
(...skipping 3634 matching lines...) Expand 10 before | Expand all | Expand 10 after
5202 result = parser.ParseProgram(source, 5214 result = parser.ParseProgram(source,
5203 info->is_global(), 5215 info->is_global(),
5204 info->StrictMode()); 5216 info->StrictMode());
5205 } 5217 }
5206 } 5218 }
5207 info->SetFunction(result); 5219 info->SetFunction(result);
5208 return (result != NULL); 5220 return (result != NULL);
5209 } 5221 }
5210 5222
5211 } } // namespace v8::internal 5223 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/preparser.cc » ('j') | src/preparser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698