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

Side by Side Diff: src/parser.cc

Issue 6598023: Strict mode - allow function only in SourceElements. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR Feedback. Created 9 years, 9 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 | « src/messages.js ('k') | test/mjsunit/strict-mode.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 InitializationBlockFinder block_finder; 1099 InitializationBlockFinder block_finder;
1100 ThisNamedPropertyAssigmentFinder this_property_assignment_finder; 1100 ThisNamedPropertyAssigmentFinder this_property_assignment_finder;
1101 bool directive_prologue = true; // Parsing directive prologue. 1101 bool directive_prologue = true; // Parsing directive prologue.
1102 1102
1103 while (peek() != end_token) { 1103 while (peek() != end_token) {
1104 if (directive_prologue && peek() != Token::STRING) { 1104 if (directive_prologue && peek() != Token::STRING) {
1105 directive_prologue = false; 1105 directive_prologue = false;
1106 } 1106 }
1107 1107
1108 Scanner::Location token_loc = scanner().peek_location(); 1108 Scanner::Location token_loc = scanner().peek_location();
1109 Statement* stat = ParseStatement(NULL, CHECK_OK); 1109
1110 Statement* stat;
1111 if (peek() == Token::FUNCTION) {
1112 // FunctionDeclaration is only allowed in the context of SourceElements
1113 // (Ecma 262 5th Edition, clause 14):
1114 // SourceElement:
1115 // Statement
1116 // FunctionDeclaration
1117 // Common language extension is to allow function declaration in place
1118 // of any statement. This language extension is disabled in strict mode.
1119 stat = ParseFunctionDeclaration(CHECK_OK);
1120 } else {
1121 stat = ParseStatement(NULL, CHECK_OK);
1122 }
1110 1123
1111 if (stat == NULL || stat->IsEmpty()) { 1124 if (stat == NULL || stat->IsEmpty()) {
1112 directive_prologue = false; // End of directive prologue. 1125 directive_prologue = false; // End of directive prologue.
1113 continue; 1126 continue;
1114 } 1127 }
1115 1128
1116 if (directive_prologue) { 1129 if (directive_prologue) {
1117 // A shot at a directive. 1130 // A shot at a directive.
1118 ExpressionStatement *e_stat; 1131 ExpressionStatement *e_stat;
1119 Literal *literal; 1132 Literal *literal;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 Block* result = new Block(labels, 1, false); 1269 Block* result = new Block(labels, 1, false);
1257 Target target(&this->target_stack_, result); 1270 Target target(&this->target_stack_, result);
1258 TryStatement* statement = ParseTryStatement(CHECK_OK); 1271 TryStatement* statement = ParseTryStatement(CHECK_OK);
1259 if (statement) { 1272 if (statement) {
1260 statement->set_statement_pos(statement_pos); 1273 statement->set_statement_pos(statement_pos);
1261 } 1274 }
1262 if (result) result->AddStatement(statement); 1275 if (result) result->AddStatement(statement);
1263 return result; 1276 return result;
1264 } 1277 }
1265 1278
1266 case Token::FUNCTION: 1279 case Token::FUNCTION: {
1280 // In strict mode, FunctionDeclaration is only allowed in the context
1281 // of SourceElements.
1282 if (temp_scope_->StrictMode()) {
1283 ReportMessageAt(scanner().peek_location(), "strict_function",
1284 Vector<const char*>::empty());
1285 *ok = false;
1286 return NULL;
1287 }
1267 return ParseFunctionDeclaration(ok); 1288 return ParseFunctionDeclaration(ok);
1289 }
1268 1290
1269 case Token::NATIVE: 1291 case Token::NATIVE:
1270 return ParseNativeDeclaration(ok); 1292 return ParseNativeDeclaration(ok);
1271 1293
1272 case Token::DEBUGGER: 1294 case Token::DEBUGGER:
1273 stmt = ParseDebuggerStatement(ok); 1295 stmt = ParseDebuggerStatement(ok);
1274 break; 1296 break;
1275 1297
1276 default: 1298 default:
1277 stmt = ParseExpressionOrLabelledStatement(labels, ok); 1299 stmt = ParseExpressionOrLabelledStatement(labels, ok);
(...skipping 3836 matching lines...) Expand 10 before | Expand all | Expand 10 after
5114 info->is_global(), 5136 info->is_global(),
5115 info->StrictMode()); 5137 info->StrictMode());
5116 } 5138 }
5117 } 5139 }
5118 5140
5119 info->SetFunction(result); 5141 info->SetFunction(result);
5120 return (result != NULL); 5142 return (result != NULL);
5121 } 5143 }
5122 5144
5123 } } // namespace v8::internal 5145 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/messages.js ('k') | test/mjsunit/strict-mode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698