OLD | NEW |
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 !identifier.IsValidStrictVariable()) { | 235 !identifier.IsValidStrictVariable()) { |
236 // Strict mode violation, using either reserved word or eval/arguments | 236 // Strict mode violation, using either reserved word or eval/arguments |
237 // as name of strict function. | 237 // as name of strict function. |
238 const char* type = "strict_function_name"; | 238 const char* type = "strict_function_name"; |
239 if (identifier.IsFutureReserved()) { | 239 if (identifier.IsFutureReserved()) { |
240 type = "strict_reserved_word"; | 240 type = "strict_reserved_word"; |
241 } | 241 } |
242 ReportMessageAt(location.beg_pos, location.end_pos, type, NULL); | 242 ReportMessageAt(location.beg_pos, location.end_pos, type, NULL); |
243 *ok = false; | 243 *ok = false; |
244 } | 244 } |
245 return Statement::Default(); | 245 return Statement::FunctionDeclaration(); |
246 } | 246 } |
247 | 247 |
248 | 248 |
249 // Language extension which is only enabled for source files loaded | 249 // Language extension which is only enabled for source files loaded |
250 // through the API's extension mechanism. A native function | 250 // through the API's extension mechanism. A native function |
251 // declaration is resolved by looking up the function through a | 251 // declaration is resolved by looking up the function through a |
252 // callback provided by the extension. | 252 // callback provided by the extension. |
253 PreParser::Statement PreParser::ParseNativeDeclaration(bool* ok) { | 253 PreParser::Statement PreParser::ParseNativeDeclaration(bool* ok) { |
254 Expect(i::Token::NATIVE, CHECK_OK); | 254 Expect(i::Token::NATIVE, CHECK_OK); |
255 Expect(i::Token::FUNCTION, CHECK_OK); | 255 Expect(i::Token::FUNCTION, CHECK_OK); |
(...skipping 15 matching lines...) Expand all Loading... |
271 | 271 |
272 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 272 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
273 // Block :: | 273 // Block :: |
274 // '{' Statement* '}' | 274 // '{' Statement* '}' |
275 | 275 |
276 // Note that a Block does not introduce a new execution scope! | 276 // Note that a Block does not introduce a new execution scope! |
277 // (ECMA-262, 3rd, 12.2) | 277 // (ECMA-262, 3rd, 12.2) |
278 // | 278 // |
279 Expect(i::Token::LBRACE, CHECK_OK); | 279 Expect(i::Token::LBRACE, CHECK_OK); |
280 while (peek() != i::Token::RBRACE) { | 280 while (peek() != i::Token::RBRACE) { |
281 ParseStatement(CHECK_OK); | 281 i::Scanner::Location start_location = scanner_->peek_location(); |
| 282 Statement statement = ParseStatement(CHECK_OK); |
| 283 i::Scanner::Location end_location = scanner_->location(); |
| 284 if (strict_mode() && statement.IsFunctionDeclaration()) { |
| 285 ReportMessageAt(start_location.beg_pos, end_location.end_pos, |
| 286 "strict_function", NULL); |
| 287 *ok = false; |
| 288 return Statement::Default(); |
| 289 } |
282 } | 290 } |
283 Expect(i::Token::RBRACE, ok); | 291 Expect(i::Token::RBRACE, ok); |
284 return Statement::Default(); | 292 return Statement::Default(); |
285 } | 293 } |
286 | 294 |
287 | 295 |
288 PreParser::Statement PreParser::ParseVariableStatement(bool* ok) { | 296 PreParser::Statement PreParser::ParseVariableStatement(bool* ok) { |
289 // VariableStatement :: | 297 // VariableStatement :: |
290 // VariableDeclarations ';' | 298 // VariableDeclarations ';' |
291 | 299 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 358 |
351 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { | 359 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
352 // ExpressionStatement | LabelledStatement :: | 360 // ExpressionStatement | LabelledStatement :: |
353 // Expression ';' | 361 // Expression ';' |
354 // Identifier ':' Statement | 362 // Identifier ':' Statement |
355 | 363 |
356 Expression expr = ParseExpression(true, CHECK_OK); | 364 Expression expr = ParseExpression(true, CHECK_OK); |
357 if (peek() == i::Token::COLON && expr.IsRawIdentifier()) { | 365 if (peek() == i::Token::COLON && expr.IsRawIdentifier()) { |
358 if (!strict_mode() || !expr.AsIdentifier().IsFutureReserved()) { | 366 if (!strict_mode() || !expr.AsIdentifier().IsFutureReserved()) { |
359 Consume(i::Token::COLON); | 367 Consume(i::Token::COLON); |
360 ParseStatement(ok); | 368 i::Scanner::Location start_location = scanner_->peek_location(); |
| 369 Statement statement = ParseStatement(CHECK_OK); |
| 370 if (strict_mode() && statement.IsFunctionDeclaration()) { |
| 371 i::Scanner::Location end_location = scanner_->location(); |
| 372 ReportMessageAt(start_location.beg_pos, end_location.end_pos, |
| 373 "strict_function", NULL); |
| 374 *ok = false; |
| 375 } |
361 return Statement::Default(); | 376 return Statement::Default(); |
362 } | 377 } |
363 } | 378 } |
364 // Parsed expression statement. | 379 // Parsed expression statement. |
365 ExpectSemicolon(CHECK_OK); | 380 ExpectSemicolon(CHECK_OK); |
366 return Statement::ExpressionStatement(expr); | 381 return Statement::ExpressionStatement(expr); |
367 } | 382 } |
368 | 383 |
369 | 384 |
370 PreParser::Statement PreParser::ParseIfStatement(bool* ok) { | 385 PreParser::Statement PreParser::ParseIfStatement(bool* ok) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 i::Token::Value token = peek(); | 494 i::Token::Value token = peek(); |
480 while (token != i::Token::RBRACE) { | 495 while (token != i::Token::RBRACE) { |
481 if (token == i::Token::CASE) { | 496 if (token == i::Token::CASE) { |
482 Expect(i::Token::CASE, CHECK_OK); | 497 Expect(i::Token::CASE, CHECK_OK); |
483 ParseExpression(true, CHECK_OK); | 498 ParseExpression(true, CHECK_OK); |
484 Expect(i::Token::COLON, CHECK_OK); | 499 Expect(i::Token::COLON, CHECK_OK); |
485 } else if (token == i::Token::DEFAULT) { | 500 } else if (token == i::Token::DEFAULT) { |
486 Expect(i::Token::DEFAULT, CHECK_OK); | 501 Expect(i::Token::DEFAULT, CHECK_OK); |
487 Expect(i::Token::COLON, CHECK_OK); | 502 Expect(i::Token::COLON, CHECK_OK); |
488 } else { | 503 } else { |
489 ParseStatement(CHECK_OK); | 504 i::Scanner::Location start_location = scanner_->peek_location(); |
| 505 Statement statement = ParseStatement(CHECK_OK); |
| 506 if (strict_mode() && statement.IsFunctionDeclaration()) { |
| 507 i::Scanner::Location end_location = scanner_->location(); |
| 508 ReportMessageAt(start_location.beg_pos, end_location.end_pos, |
| 509 "strict_function", NULL); |
| 510 *ok = false; |
| 511 return Statement::Default(); |
| 512 } |
490 } | 513 } |
491 token = peek(); | 514 token = peek(); |
492 } | 515 } |
493 Expect(i::Token::RBRACE, ok); | 516 Expect(i::Token::RBRACE, ok); |
494 return Statement::Default(); | 517 return Statement::Default(); |
495 } | 518 } |
496 | 519 |
497 | 520 |
498 PreParser::Statement PreParser::ParseDoWhileStatement(bool* ok) { | 521 PreParser::Statement PreParser::ParseDoWhileStatement(bool* ok) { |
499 // DoStatement :: | 522 // DoStatement :: |
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 } | 1441 } |
1419 return result; | 1442 return result; |
1420 } | 1443 } |
1421 | 1444 |
1422 bool PreParser::peek_any_identifier() { | 1445 bool PreParser::peek_any_identifier() { |
1423 i::Token::Value next = peek(); | 1446 i::Token::Value next = peek(); |
1424 return next == i::Token::IDENTIFIER || | 1447 return next == i::Token::IDENTIFIER || |
1425 next == i::Token::FUTURE_RESERVED_WORD; | 1448 next == i::Token::FUTURE_RESERVED_WORD; |
1426 } | 1449 } |
1427 } } // v8::preparser | 1450 } } // v8::preparser |
OLD | NEW |