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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, | 142 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, |
143 bool* ok) { | 143 bool* ok) { |
144 // SourceElements :: | 144 // SourceElements :: |
145 // (Statement)* <end_token> | 145 // (Statement)* <end_token> |
146 | 146 |
147 bool allow_directive_prologue = true; | 147 bool allow_directive_prologue = true; |
148 while (peek() != end_token) { | 148 while (peek() != end_token) { |
149 Statement statement = ParseSourceElement(CHECK_OK); | 149 Statement statement = ParseSourceElement(CHECK_OK); |
150 if (allow_directive_prologue) { | 150 if (allow_directive_prologue) { |
151 if (statement.IsUseStrictLiteral()) { | 151 if (statement.IsUseStrictLiteral()) { |
152 set_strict_mode(); | 152 set_language_mode(harmony_scoping_ ? |
| 153 i::EXTENDED_MODE : i::STRICT_MODE); |
153 } else if (!statement.IsStringLiteral()) { | 154 } else if (!statement.IsStringLiteral()) { |
154 allow_directive_prologue = false; | 155 allow_directive_prologue = false; |
155 } | 156 } |
156 } | 157 } |
157 } | 158 } |
158 return kUnknownSourceElements; | 159 return kUnknownSourceElements; |
159 } | 160 } |
160 | 161 |
161 | 162 |
162 #undef CHECK_OK | 163 #undef CHECK_OK |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 case i::Token::THROW: | 236 case i::Token::THROW: |
236 return ParseThrowStatement(ok); | 237 return ParseThrowStatement(ok); |
237 | 238 |
238 case i::Token::TRY: | 239 case i::Token::TRY: |
239 return ParseTryStatement(ok); | 240 return ParseTryStatement(ok); |
240 | 241 |
241 case i::Token::FUNCTION: { | 242 case i::Token::FUNCTION: { |
242 i::Scanner::Location start_location = scanner_->peek_location(); | 243 i::Scanner::Location start_location = scanner_->peek_location(); |
243 Statement statement = ParseFunctionDeclaration(CHECK_OK); | 244 Statement statement = ParseFunctionDeclaration(CHECK_OK); |
244 i::Scanner::Location end_location = scanner_->location(); | 245 i::Scanner::Location end_location = scanner_->location(); |
245 if (strict_mode() || harmony_scoping_) { | 246 if (is_strict_or_extended_mode()) { |
246 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | 247 ReportMessageAt(start_location.beg_pos, end_location.end_pos, |
247 "strict_function", NULL); | 248 "strict_function", NULL); |
248 *ok = false; | 249 *ok = false; |
249 return Statement::Default(); | 250 return Statement::Default(); |
250 } else { | 251 } else { |
251 return statement; | 252 return statement; |
252 } | 253 } |
253 } | 254 } |
254 | 255 |
255 case i::Token::DEBUGGER: | 256 case i::Token::DEBUGGER: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 289 |
289 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 290 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
290 // Block :: | 291 // Block :: |
291 // '{' Statement* '}' | 292 // '{' Statement* '}' |
292 | 293 |
293 // Note that a Block does not introduce a new execution scope! | 294 // Note that a Block does not introduce a new execution scope! |
294 // (ECMA-262, 3rd, 12.2) | 295 // (ECMA-262, 3rd, 12.2) |
295 // | 296 // |
296 Expect(i::Token::LBRACE, CHECK_OK); | 297 Expect(i::Token::LBRACE, CHECK_OK); |
297 while (peek() != i::Token::RBRACE) { | 298 while (peek() != i::Token::RBRACE) { |
298 if (harmony_scoping_) { | 299 if (is_extended_mode()) { |
299 ParseSourceElement(CHECK_OK); | 300 ParseSourceElement(CHECK_OK); |
300 } else { | 301 } else { |
301 ParseStatement(CHECK_OK); | 302 ParseStatement(CHECK_OK); |
302 } | 303 } |
303 } | 304 } |
304 Expect(i::Token::RBRACE, ok); | 305 Expect(i::Token::RBRACE, ok); |
305 return Statement::Default(); | 306 return Statement::Default(); |
306 } | 307 } |
307 | 308 |
308 | 309 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 // ConstBinding :: | 342 // ConstBinding :: |
342 // Identifier '=' AssignmentExpression | 343 // Identifier '=' AssignmentExpression |
343 // | 344 // |
344 // TODO(ES6): | 345 // TODO(ES6): |
345 // ConstBinding :: | 346 // ConstBinding :: |
346 // BindingPattern '=' AssignmentExpression | 347 // BindingPattern '=' AssignmentExpression |
347 bool require_initializer = false; | 348 bool require_initializer = false; |
348 if (peek() == i::Token::VAR) { | 349 if (peek() == i::Token::VAR) { |
349 Consume(i::Token::VAR); | 350 Consume(i::Token::VAR); |
350 } else if (peek() == i::Token::CONST) { | 351 } else if (peek() == i::Token::CONST) { |
351 if (harmony_scoping_) { | 352 switch (language_mode()) { |
352 if (var_context != kSourceElement && | 353 case i::CLASSIC_MODE: |
353 var_context != kForStatement) { | 354 break; |
| 355 case i::STRICT_MODE: { |
354 i::Scanner::Location location = scanner_->peek_location(); | 356 i::Scanner::Location location = scanner_->peek_location(); |
355 ReportMessageAt(location.beg_pos, location.end_pos, | 357 ReportMessageAt(location, "strict_const", NULL); |
356 "unprotected_const", NULL); | |
357 *ok = false; | 358 *ok = false; |
358 return Statement::Default(); | 359 return Statement::Default(); |
359 } | 360 } |
360 require_initializer = true; | 361 case i::EXTENDED_MODE: |
361 } else if (strict_mode()) { | 362 if (var_context != kSourceElement && |
362 i::Scanner::Location location = scanner_->peek_location(); | 363 var_context != kForStatement) { |
363 ReportMessageAt(location, "strict_const", NULL); | 364 i::Scanner::Location location = scanner_->peek_location(); |
364 *ok = false; | 365 ReportMessageAt(location.beg_pos, location.end_pos, |
365 return Statement::Default(); | 366 "unprotected_const", NULL); |
| 367 *ok = false; |
| 368 return Statement::Default(); |
| 369 } |
| 370 require_initializer = true; |
| 371 break; |
366 } | 372 } |
367 Consume(i::Token::CONST); | 373 Consume(i::Token::CONST); |
368 } else if (peek() == i::Token::LET) { | 374 } else if (peek() == i::Token::LET) { |
| 375 ASSERT(is_extended_mode()); |
369 if (var_context != kSourceElement && | 376 if (var_context != kSourceElement && |
370 var_context != kForStatement) { | 377 var_context != kForStatement) { |
371 i::Scanner::Location location = scanner_->peek_location(); | 378 i::Scanner::Location location = scanner_->peek_location(); |
372 ReportMessageAt(location.beg_pos, location.end_pos, | 379 ReportMessageAt(location.beg_pos, location.end_pos, |
373 "unprotected_let", NULL); | 380 "unprotected_let", NULL); |
374 *ok = false; | 381 *ok = false; |
375 return Statement::Default(); | 382 return Statement::Default(); |
376 } | 383 } |
377 Consume(i::Token::LET); | 384 Consume(i::Token::LET); |
378 } else { | 385 } else { |
379 *ok = false; | 386 *ok = false; |
380 return Statement::Default(); | 387 return Statement::Default(); |
381 } | 388 } |
382 | 389 |
383 // The scope of a var/const declared variable anywhere inside a function | 390 // The scope of a var/const declared variable anywhere inside a function |
384 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope | 391 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope |
385 // of a let declared variable is the scope of the immediately enclosing | 392 // of a let declared variable is the scope of the immediately enclosing |
386 // block. | 393 // block. |
387 int nvars = 0; // the number of variables declared | 394 int nvars = 0; // the number of variables declared |
388 do { | 395 do { |
389 // Parse variable name. | 396 // Parse variable name. |
390 if (nvars > 0) Consume(i::Token::COMMA); | 397 if (nvars > 0) Consume(i::Token::COMMA); |
391 Identifier identifier = ParseIdentifier(CHECK_OK); | 398 Identifier identifier = ParseIdentifier(CHECK_OK); |
392 if (strict_mode() && !identifier.IsValidStrictVariable()) { | 399 if (is_strict_or_extended_mode() && |
| 400 !identifier.IsValidStrictVariable()) { |
393 StrictModeIdentifierViolation(scanner_->location(), | 401 StrictModeIdentifierViolation(scanner_->location(), |
394 "strict_var_name", | 402 "strict_var_name", |
395 identifier, | 403 identifier, |
396 ok); | 404 ok); |
397 return Statement::Default(); | 405 return Statement::Default(); |
398 } | 406 } |
399 nvars++; | 407 nvars++; |
400 if (peek() == i::Token::ASSIGN || require_initializer) { | 408 if (peek() == i::Token::ASSIGN || require_initializer) { |
401 Expect(i::Token::ASSIGN, CHECK_OK); | 409 Expect(i::Token::ASSIGN, CHECK_OK); |
402 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); | 410 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); |
403 if (decl_props != NULL) *decl_props = kHasInitializers; | 411 if (decl_props != NULL) *decl_props = kHasInitializers; |
404 } | 412 } |
405 } while (peek() == i::Token::COMMA); | 413 } while (peek() == i::Token::COMMA); |
406 | 414 |
407 if (num_decl != NULL) *num_decl = nvars; | 415 if (num_decl != NULL) *num_decl = nvars; |
408 return Statement::Default(); | 416 return Statement::Default(); |
409 } | 417 } |
410 | 418 |
411 | 419 |
412 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { | 420 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
413 // ExpressionStatement | LabelledStatement :: | 421 // ExpressionStatement | LabelledStatement :: |
414 // Expression ';' | 422 // Expression ';' |
415 // Identifier ':' Statement | 423 // Identifier ':' Statement |
416 | 424 |
417 Expression expr = ParseExpression(true, CHECK_OK); | 425 Expression expr = ParseExpression(true, CHECK_OK); |
418 if (expr.IsRawIdentifier()) { | 426 if (expr.IsRawIdentifier()) { |
419 ASSERT(!expr.AsIdentifier().IsFutureReserved()); | 427 ASSERT(!expr.AsIdentifier().IsFutureReserved()); |
420 ASSERT(!strict_mode() || !expr.AsIdentifier().IsFutureStrictReserved()); | 428 ASSERT(!is_strict_or_extended_mode() || |
| 429 !expr.AsIdentifier().IsFutureStrictReserved()); |
421 if (peek() == i::Token::COLON) { | 430 if (peek() == i::Token::COLON) { |
422 Consume(i::Token::COLON); | 431 Consume(i::Token::COLON); |
423 return ParseStatement(ok); | 432 return ParseStatement(ok); |
424 } | 433 } |
425 // Preparsing is disabled for extensions (because the extension details | 434 // Preparsing is disabled for extensions (because the extension details |
426 // aren't passed to lazily compiled functions), so we don't | 435 // aren't passed to lazily compiled functions), so we don't |
427 // accept "native function" in the preparser. | 436 // accept "native function" in the preparser. |
428 } | 437 } |
429 // Parsed expression statement. | 438 // Parsed expression statement. |
430 ExpectSemicolon(CHECK_OK); | 439 ExpectSemicolon(CHECK_OK); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 515 } |
507 ExpectSemicolon(CHECK_OK); | 516 ExpectSemicolon(CHECK_OK); |
508 return Statement::Default(); | 517 return Statement::Default(); |
509 } | 518 } |
510 | 519 |
511 | 520 |
512 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { | 521 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { |
513 // WithStatement :: | 522 // WithStatement :: |
514 // 'with' '(' Expression ')' Statement | 523 // 'with' '(' Expression ')' Statement |
515 Expect(i::Token::WITH, CHECK_OK); | 524 Expect(i::Token::WITH, CHECK_OK); |
516 if (strict_mode()) { | 525 if (is_strict_or_extended_mode()) { |
517 i::Scanner::Location location = scanner_->location(); | 526 i::Scanner::Location location = scanner_->location(); |
518 ReportMessageAt(location, "strict_mode_with", NULL); | 527 ReportMessageAt(location, "strict_mode_with", NULL); |
519 *ok = false; | 528 *ok = false; |
520 return Statement::Default(); | 529 return Statement::Default(); |
521 } | 530 } |
522 Expect(i::Token::LPAREN, CHECK_OK); | 531 Expect(i::Token::LPAREN, CHECK_OK); |
523 ParseExpression(true, CHECK_OK); | 532 ParseExpression(true, CHECK_OK); |
524 Expect(i::Token::RPAREN, CHECK_OK); | 533 Expect(i::Token::RPAREN, CHECK_OK); |
525 | 534 |
526 scope_->EnterWith(); | 535 scope_->EnterWith(); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 | 684 |
676 Expect(i::Token::TRY, CHECK_OK); | 685 Expect(i::Token::TRY, CHECK_OK); |
677 | 686 |
678 ParseBlock(CHECK_OK); | 687 ParseBlock(CHECK_OK); |
679 | 688 |
680 bool catch_or_finally_seen = false; | 689 bool catch_or_finally_seen = false; |
681 if (peek() == i::Token::CATCH) { | 690 if (peek() == i::Token::CATCH) { |
682 Consume(i::Token::CATCH); | 691 Consume(i::Token::CATCH); |
683 Expect(i::Token::LPAREN, CHECK_OK); | 692 Expect(i::Token::LPAREN, CHECK_OK); |
684 Identifier id = ParseIdentifier(CHECK_OK); | 693 Identifier id = ParseIdentifier(CHECK_OK); |
685 if (strict_mode() && !id.IsValidStrictVariable()) { | 694 if (is_strict_or_extended_mode() && |
| 695 !id.IsValidStrictVariable()) { |
686 StrictModeIdentifierViolation(scanner_->location(), | 696 StrictModeIdentifierViolation(scanner_->location(), |
687 "strict_catch_variable", | 697 "strict_catch_variable", |
688 id, | 698 id, |
689 ok); | 699 ok); |
690 return Statement::Default(); | 700 return Statement::Default(); |
691 } | 701 } |
692 Expect(i::Token::RPAREN, CHECK_OK); | 702 Expect(i::Token::RPAREN, CHECK_OK); |
693 scope_->EnterWith(); | 703 scope_->EnterWith(); |
694 ParseBlock(ok); | 704 ParseBlock(ok); |
695 scope_->LeaveWith(); | 705 scope_->LeaveWith(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 763 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
754 | 764 |
755 i::Scanner::Location before = scanner_->peek_location(); | 765 i::Scanner::Location before = scanner_->peek_location(); |
756 Expression expression = ParseConditionalExpression(accept_IN, CHECK_OK); | 766 Expression expression = ParseConditionalExpression(accept_IN, CHECK_OK); |
757 | 767 |
758 if (!i::Token::IsAssignmentOp(peek())) { | 768 if (!i::Token::IsAssignmentOp(peek())) { |
759 // Parsed conditional expression only (no assignment). | 769 // Parsed conditional expression only (no assignment). |
760 return expression; | 770 return expression; |
761 } | 771 } |
762 | 772 |
763 if (strict_mode() && expression.IsIdentifier() && | 773 if (is_strict_or_extended_mode() && |
| 774 expression.IsIdentifier() && |
764 expression.AsIdentifier().IsEvalOrArguments()) { | 775 expression.AsIdentifier().IsEvalOrArguments()) { |
765 i::Scanner::Location after = scanner_->location(); | 776 i::Scanner::Location after = scanner_->location(); |
766 ReportMessageAt(before.beg_pos, after.end_pos, | 777 ReportMessageAt(before.beg_pos, after.end_pos, |
767 "strict_lhs_assignment", NULL); | 778 "strict_lhs_assignment", NULL); |
768 *ok = false; | 779 *ok = false; |
769 return Expression::Default(); | 780 return Expression::Default(); |
770 } | 781 } |
771 | 782 |
772 i::Token::Value op = Next(); // Get assignment operator. | 783 i::Token::Value op = Next(); // Get assignment operator. |
773 ParseAssignmentExpression(accept_IN, CHECK_OK); | 784 ParseAssignmentExpression(accept_IN, CHECK_OK); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 | 852 |
842 i::Token::Value op = peek(); | 853 i::Token::Value op = peek(); |
843 if (i::Token::IsUnaryOp(op)) { | 854 if (i::Token::IsUnaryOp(op)) { |
844 op = Next(); | 855 op = Next(); |
845 ParseUnaryExpression(ok); | 856 ParseUnaryExpression(ok); |
846 return Expression::Default(); | 857 return Expression::Default(); |
847 } else if (i::Token::IsCountOp(op)) { | 858 } else if (i::Token::IsCountOp(op)) { |
848 op = Next(); | 859 op = Next(); |
849 i::Scanner::Location before = scanner_->peek_location(); | 860 i::Scanner::Location before = scanner_->peek_location(); |
850 Expression expression = ParseUnaryExpression(CHECK_OK); | 861 Expression expression = ParseUnaryExpression(CHECK_OK); |
851 if (strict_mode() && expression.IsIdentifier() && | 862 if (is_strict_or_extended_mode() && |
| 863 expression.IsIdentifier() && |
852 expression.AsIdentifier().IsEvalOrArguments()) { | 864 expression.AsIdentifier().IsEvalOrArguments()) { |
853 i::Scanner::Location after = scanner_->location(); | 865 i::Scanner::Location after = scanner_->location(); |
854 ReportMessageAt(before.beg_pos, after.end_pos, | 866 ReportMessageAt(before.beg_pos, after.end_pos, |
855 "strict_lhs_prefix", NULL); | 867 "strict_lhs_prefix", NULL); |
856 *ok = false; | 868 *ok = false; |
857 } | 869 } |
858 return Expression::Default(); | 870 return Expression::Default(); |
859 } else { | 871 } else { |
860 return ParsePostfixExpression(ok); | 872 return ParsePostfixExpression(ok); |
861 } | 873 } |
862 } | 874 } |
863 | 875 |
864 | 876 |
865 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { | 877 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { |
866 // PostfixExpression :: | 878 // PostfixExpression :: |
867 // LeftHandSideExpression ('++' | '--')? | 879 // LeftHandSideExpression ('++' | '--')? |
868 | 880 |
869 i::Scanner::Location before = scanner_->peek_location(); | 881 i::Scanner::Location before = scanner_->peek_location(); |
870 Expression expression = ParseLeftHandSideExpression(CHECK_OK); | 882 Expression expression = ParseLeftHandSideExpression(CHECK_OK); |
871 if (!scanner_->HasAnyLineTerminatorBeforeNext() && | 883 if (!scanner_->HasAnyLineTerminatorBeforeNext() && |
872 i::Token::IsCountOp(peek())) { | 884 i::Token::IsCountOp(peek())) { |
873 if (strict_mode() && expression.IsIdentifier() && | 885 if (is_strict_or_extended_mode() && |
| 886 expression.IsIdentifier() && |
874 expression.AsIdentifier().IsEvalOrArguments()) { | 887 expression.AsIdentifier().IsEvalOrArguments()) { |
875 i::Scanner::Location after = scanner_->location(); | 888 i::Scanner::Location after = scanner_->location(); |
876 ReportMessageAt(before.beg_pos, after.end_pos, | 889 ReportMessageAt(before.beg_pos, after.end_pos, |
877 "strict_lhs_postfix", NULL); | 890 "strict_lhs_postfix", NULL); |
878 *ok = false; | 891 *ok = false; |
879 return Expression::Default(); | 892 return Expression::Default(); |
880 } | 893 } |
881 Next(); | 894 Next(); |
882 return Expression::Default(); | 895 return Expression::Default(); |
883 } | 896 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 case i::Token::FUTURE_RESERVED_WORD: { | 1063 case i::Token::FUTURE_RESERVED_WORD: { |
1051 Next(); | 1064 Next(); |
1052 i::Scanner::Location location = scanner_->location(); | 1065 i::Scanner::Location location = scanner_->location(); |
1053 ReportMessageAt(location.beg_pos, location.end_pos, | 1066 ReportMessageAt(location.beg_pos, location.end_pos, |
1054 "reserved_word", NULL); | 1067 "reserved_word", NULL); |
1055 *ok = false; | 1068 *ok = false; |
1056 return Expression::Default(); | 1069 return Expression::Default(); |
1057 } | 1070 } |
1058 | 1071 |
1059 case i::Token::FUTURE_STRICT_RESERVED_WORD: | 1072 case i::Token::FUTURE_STRICT_RESERVED_WORD: |
1060 if (strict_mode()) { | 1073 if (is_strict_or_extended_mode()) { |
1061 Next(); | 1074 Next(); |
1062 i::Scanner::Location location = scanner_->location(); | 1075 i::Scanner::Location location = scanner_->location(); |
1063 ReportMessageAt(location, "strict_reserved_word", NULL); | 1076 ReportMessageAt(location, "strict_reserved_word", NULL); |
1064 *ok = false; | 1077 *ok = false; |
1065 return Expression::Default(); | 1078 return Expression::Default(); |
1066 } | 1079 } |
1067 // FALLTHROUGH | 1080 // FALLTHROUGH |
1068 case i::Token::IDENTIFIER: { | 1081 case i::Token::IDENTIFIER: { |
1069 Identifier id = ParseIdentifier(CHECK_OK); | 1082 Identifier id = ParseIdentifier(CHECK_OK); |
1070 result = Expression::FromIdentifier(id); | 1083 result = Expression::FromIdentifier(id); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 old_type = finder->AddNumber(scanner_->literal_ascii_string(), type); | 1163 old_type = finder->AddNumber(scanner_->literal_ascii_string(), type); |
1151 } else if (scanner_->is_literal_ascii()) { | 1164 } else if (scanner_->is_literal_ascii()) { |
1152 old_type = finder->AddAsciiSymbol(scanner_->literal_ascii_string(), | 1165 old_type = finder->AddAsciiSymbol(scanner_->literal_ascii_string(), |
1153 type); | 1166 type); |
1154 } else { | 1167 } else { |
1155 old_type = finder->AddUC16Symbol(scanner_->literal_uc16_string(), type); | 1168 old_type = finder->AddUC16Symbol(scanner_->literal_uc16_string(), type); |
1156 } | 1169 } |
1157 if (HasConflict(old_type, type)) { | 1170 if (HasConflict(old_type, type)) { |
1158 if (IsDataDataConflict(old_type, type)) { | 1171 if (IsDataDataConflict(old_type, type)) { |
1159 // Both are data properties. | 1172 // Both are data properties. |
1160 if (!strict_mode()) return; | 1173 if (is_classic_mode()) return; |
1161 ReportMessageAt(scanner_->location(), | 1174 ReportMessageAt(scanner_->location(), |
1162 "strict_duplicate_property", NULL); | 1175 "strict_duplicate_property", NULL); |
1163 } else if (IsDataAccessorConflict(old_type, type)) { | 1176 } else if (IsDataAccessorConflict(old_type, type)) { |
1164 // Both a data and an accessor property with the same name. | 1177 // Both a data and an accessor property with the same name. |
1165 ReportMessageAt(scanner_->location(), | 1178 ReportMessageAt(scanner_->location(), |
1166 "accessor_data_property", NULL); | 1179 "accessor_data_property", NULL); |
1167 } else { | 1180 } else { |
1168 ASSERT(IsAccessorAccessorConflict(old_type, type)); | 1181 ASSERT(IsAccessorAccessorConflict(old_type, type)); |
1169 // Both accessors of the same type. | 1182 // Both accessors of the same type. |
1170 ReportMessageAt(scanner_->location(), | 1183 ReportMessageAt(scanner_->location(), |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 log_->ResumeRecording(); | 1370 log_->ResumeRecording(); |
1358 if (!*ok) Expression::Default(); | 1371 if (!*ok) Expression::Default(); |
1359 | 1372 |
1360 Expect(i::Token::RBRACE, CHECK_OK); | 1373 Expect(i::Token::RBRACE, CHECK_OK); |
1361 | 1374 |
1362 // Position right after terminal '}'. | 1375 // Position right after terminal '}'. |
1363 int end_pos = scanner_->location().end_pos; | 1376 int end_pos = scanner_->location().end_pos; |
1364 log_->LogFunction(function_block_pos, end_pos, | 1377 log_->LogFunction(function_block_pos, end_pos, |
1365 function_scope.materialized_literal_count(), | 1378 function_scope.materialized_literal_count(), |
1366 function_scope.expected_properties(), | 1379 function_scope.expected_properties(), |
1367 strict_mode_flag()); | 1380 language_mode()); |
1368 } else { | 1381 } else { |
1369 ParseSourceElements(i::Token::RBRACE, CHECK_OK); | 1382 ParseSourceElements(i::Token::RBRACE, CHECK_OK); |
1370 Expect(i::Token::RBRACE, CHECK_OK); | 1383 Expect(i::Token::RBRACE, CHECK_OK); |
1371 } | 1384 } |
1372 | 1385 |
1373 if (strict_mode()) { | 1386 if (is_strict_or_extended_mode()) { |
1374 int end_position = scanner_->location().end_pos; | 1387 int end_position = scanner_->location().end_pos; |
1375 CheckOctalLiteral(start_position, end_position, CHECK_OK); | 1388 CheckOctalLiteral(start_position, end_position, CHECK_OK); |
1376 CheckDelayedStrictModeViolation(start_position, end_position, CHECK_OK); | 1389 CheckDelayedStrictModeViolation(start_position, end_position, CHECK_OK); |
1377 return Expression::StrictFunction(); | 1390 return Expression::StrictFunction(); |
1378 } | 1391 } |
1379 | 1392 |
1380 return Expression::Default(); | 1393 return Expression::Default(); |
1381 } | 1394 } |
1382 | 1395 |
1383 | 1396 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 i::Token::Value next = Next(); | 1480 i::Token::Value next = Next(); |
1468 switch (next) { | 1481 switch (next) { |
1469 case i::Token::FUTURE_RESERVED_WORD: { | 1482 case i::Token::FUTURE_RESERVED_WORD: { |
1470 i::Scanner::Location location = scanner_->location(); | 1483 i::Scanner::Location location = scanner_->location(); |
1471 ReportMessageAt(location.beg_pos, location.end_pos, | 1484 ReportMessageAt(location.beg_pos, location.end_pos, |
1472 "reserved_word", NULL); | 1485 "reserved_word", NULL); |
1473 *ok = false; | 1486 *ok = false; |
1474 return GetIdentifierSymbol(); | 1487 return GetIdentifierSymbol(); |
1475 } | 1488 } |
1476 case i::Token::FUTURE_STRICT_RESERVED_WORD: | 1489 case i::Token::FUTURE_STRICT_RESERVED_WORD: |
1477 if (strict_mode()) { | 1490 if (is_strict_or_extended_mode()) { |
1478 i::Scanner::Location location = scanner_->location(); | 1491 i::Scanner::Location location = scanner_->location(); |
1479 ReportMessageAt(location.beg_pos, location.end_pos, | 1492 ReportMessageAt(location.beg_pos, location.end_pos, |
1480 "strict_reserved_word", NULL); | 1493 "strict_reserved_word", NULL); |
1481 *ok = false; | 1494 *ok = false; |
1482 } | 1495 } |
1483 // FALLTHROUGH | 1496 // FALLTHROUGH |
1484 case i::Token::IDENTIFIER: | 1497 case i::Token::IDENTIFIER: |
1485 return GetIdentifierSymbol(); | 1498 return GetIdentifierSymbol(); |
1486 default: | 1499 default: |
1487 *ok = false; | 1500 *ok = false; |
1488 return Identifier::Default(); | 1501 return Identifier::Default(); |
1489 } | 1502 } |
1490 } | 1503 } |
1491 | 1504 |
1492 | 1505 |
1493 void PreParser::SetStrictModeViolation(i::Scanner::Location location, | 1506 void PreParser::SetStrictModeViolation(i::Scanner::Location location, |
1494 const char* type, | 1507 const char* type, |
1495 bool* ok) { | 1508 bool* ok) { |
1496 if (strict_mode()) { | 1509 if (is_strict_or_extended_mode()) { |
1497 ReportMessageAt(location, type, NULL); | 1510 ReportMessageAt(location, type, NULL); |
1498 *ok = false; | 1511 *ok = false; |
1499 return; | 1512 return; |
1500 } | 1513 } |
1501 // Delay report in case this later turns out to be strict code | 1514 // Delay report in case this later turns out to be strict code |
1502 // (i.e., for function names and parameters prior to a "use strict" | 1515 // (i.e., for function names and parameters prior to a "use strict" |
1503 // directive). | 1516 // directive). |
1504 // It's safe to overwrite an existing violation. | 1517 // It's safe to overwrite an existing violation. |
1505 // It's either from a function that turned out to be non-strict, | 1518 // It's either from a function that turned out to be non-strict, |
1506 // or it's in the current function (and we just need to report | 1519 // or it's in the current function (and we just need to report |
(...skipping 19 matching lines...) Expand all Loading... |
1526 void PreParser::StrictModeIdentifierViolation(i::Scanner::Location location, | 1539 void PreParser::StrictModeIdentifierViolation(i::Scanner::Location location, |
1527 const char* eval_args_type, | 1540 const char* eval_args_type, |
1528 Identifier identifier, | 1541 Identifier identifier, |
1529 bool* ok) { | 1542 bool* ok) { |
1530 const char* type = eval_args_type; | 1543 const char* type = eval_args_type; |
1531 if (identifier.IsFutureReserved()) { | 1544 if (identifier.IsFutureReserved()) { |
1532 type = "reserved_word"; | 1545 type = "reserved_word"; |
1533 } else if (identifier.IsFutureStrictReserved()) { | 1546 } else if (identifier.IsFutureStrictReserved()) { |
1534 type = "strict_reserved_word"; | 1547 type = "strict_reserved_word"; |
1535 } | 1548 } |
1536 if (strict_mode()) { | 1549 if (is_strict_or_extended_mode()) { |
1537 ReportMessageAt(location, type, NULL); | 1550 ReportMessageAt(location, type, NULL); |
1538 *ok = false; | 1551 *ok = false; |
1539 return; | 1552 return; |
1540 } | 1553 } |
1541 strict_mode_violation_location_ = location; | 1554 strict_mode_violation_location_ = location; |
1542 strict_mode_violation_type_ = type; | 1555 strict_mode_violation_type_ = type; |
1543 } | 1556 } |
1544 | 1557 |
1545 | 1558 |
1546 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { | 1559 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); | 1727 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); |
1715 } | 1728 } |
1716 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); | 1729 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); |
1717 } | 1730 } |
1718 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); | 1731 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); |
1719 | 1732 |
1720 backing_store_.AddBlock(bytes); | 1733 backing_store_.AddBlock(bytes); |
1721 return backing_store_.EndSequence().start(); | 1734 return backing_store_.EndSequence().start(); |
1722 } | 1735 } |
1723 } } // v8::preparser | 1736 } } // v8::preparser |
OLD | NEW |