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_classic_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_classic_mode() && !identifier.IsValidStrictVariable()) { |
393 StrictModeIdentifierViolation(scanner_->location(), | 400 StrictModeIdentifierViolation(scanner_->location(), |
394 "strict_var_name", | 401 "strict_var_name", |
395 identifier, | 402 identifier, |
396 ok); | 403 ok); |
397 return Statement::Default(); | 404 return Statement::Default(); |
398 } | 405 } |
399 nvars++; | 406 nvars++; |
400 if (peek() == i::Token::ASSIGN || require_initializer) { | 407 if (peek() == i::Token::ASSIGN || require_initializer) { |
401 Expect(i::Token::ASSIGN, CHECK_OK); | 408 Expect(i::Token::ASSIGN, CHECK_OK); |
402 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); | 409 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); |
403 if (decl_props != NULL) *decl_props = kHasInitializers; | 410 if (decl_props != NULL) *decl_props = kHasInitializers; |
404 } | 411 } |
405 } while (peek() == i::Token::COMMA); | 412 } while (peek() == i::Token::COMMA); |
406 | 413 |
407 if (num_decl != NULL) *num_decl = nvars; | 414 if (num_decl != NULL) *num_decl = nvars; |
408 return Statement::Default(); | 415 return Statement::Default(); |
409 } | 416 } |
410 | 417 |
411 | 418 |
412 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { | 419 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
413 // ExpressionStatement | LabelledStatement :: | 420 // ExpressionStatement | LabelledStatement :: |
414 // Expression ';' | 421 // Expression ';' |
415 // Identifier ':' Statement | 422 // Identifier ':' Statement |
416 | 423 |
417 Expression expr = ParseExpression(true, CHECK_OK); | 424 Expression expr = ParseExpression(true, CHECK_OK); |
418 if (expr.IsRawIdentifier()) { | 425 if (expr.IsRawIdentifier()) { |
419 ASSERT(!expr.AsIdentifier().IsFutureReserved()); | 426 ASSERT(!expr.AsIdentifier().IsFutureReserved()); |
420 ASSERT(!strict_mode() || !expr.AsIdentifier().IsFutureStrictReserved()); | 427 ASSERT(is_classic_mode() || !expr.AsIdentifier().IsFutureStrictReserved()); |
421 if (peek() == i::Token::COLON) { | 428 if (peek() == i::Token::COLON) { |
422 Consume(i::Token::COLON); | 429 Consume(i::Token::COLON); |
423 return ParseStatement(ok); | 430 return ParseStatement(ok); |
424 } | 431 } |
425 // Preparsing is disabled for extensions (because the extension details | 432 // Preparsing is disabled for extensions (because the extension details |
426 // aren't passed to lazily compiled functions), so we don't | 433 // aren't passed to lazily compiled functions), so we don't |
427 // accept "native function" in the preparser. | 434 // accept "native function" in the preparser. |
428 } | 435 } |
429 // Parsed expression statement. | 436 // Parsed expression statement. |
430 ExpectSemicolon(CHECK_OK); | 437 ExpectSemicolon(CHECK_OK); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 513 } |
507 ExpectSemicolon(CHECK_OK); | 514 ExpectSemicolon(CHECK_OK); |
508 return Statement::Default(); | 515 return Statement::Default(); |
509 } | 516 } |
510 | 517 |
511 | 518 |
512 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { | 519 PreParser::Statement PreParser::ParseWithStatement(bool* ok) { |
513 // WithStatement :: | 520 // WithStatement :: |
514 // 'with' '(' Expression ')' Statement | 521 // 'with' '(' Expression ')' Statement |
515 Expect(i::Token::WITH, CHECK_OK); | 522 Expect(i::Token::WITH, CHECK_OK); |
516 if (strict_mode()) { | 523 if (!is_classic_mode()) { |
517 i::Scanner::Location location = scanner_->location(); | 524 i::Scanner::Location location = scanner_->location(); |
518 ReportMessageAt(location, "strict_mode_with", NULL); | 525 ReportMessageAt(location, "strict_mode_with", NULL); |
519 *ok = false; | 526 *ok = false; |
520 return Statement::Default(); | 527 return Statement::Default(); |
521 } | 528 } |
522 Expect(i::Token::LPAREN, CHECK_OK); | 529 Expect(i::Token::LPAREN, CHECK_OK); |
523 ParseExpression(true, CHECK_OK); | 530 ParseExpression(true, CHECK_OK); |
524 Expect(i::Token::RPAREN, CHECK_OK); | 531 Expect(i::Token::RPAREN, CHECK_OK); |
525 | 532 |
526 scope_->EnterWith(); | 533 scope_->EnterWith(); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 | 682 |
676 Expect(i::Token::TRY, CHECK_OK); | 683 Expect(i::Token::TRY, CHECK_OK); |
677 | 684 |
678 ParseBlock(CHECK_OK); | 685 ParseBlock(CHECK_OK); |
679 | 686 |
680 bool catch_or_finally_seen = false; | 687 bool catch_or_finally_seen = false; |
681 if (peek() == i::Token::CATCH) { | 688 if (peek() == i::Token::CATCH) { |
682 Consume(i::Token::CATCH); | 689 Consume(i::Token::CATCH); |
683 Expect(i::Token::LPAREN, CHECK_OK); | 690 Expect(i::Token::LPAREN, CHECK_OK); |
684 Identifier id = ParseIdentifier(CHECK_OK); | 691 Identifier id = ParseIdentifier(CHECK_OK); |
685 if (strict_mode() && !id.IsValidStrictVariable()) { | 692 if (!is_classic_mode() && !id.IsValidStrictVariable()) { |
686 StrictModeIdentifierViolation(scanner_->location(), | 693 StrictModeIdentifierViolation(scanner_->location(), |
687 "strict_catch_variable", | 694 "strict_catch_variable", |
688 id, | 695 id, |
689 ok); | 696 ok); |
690 return Statement::Default(); | 697 return Statement::Default(); |
691 } | 698 } |
692 Expect(i::Token::RPAREN, CHECK_OK); | 699 Expect(i::Token::RPAREN, CHECK_OK); |
693 scope_->EnterWith(); | 700 scope_->EnterWith(); |
694 ParseBlock(ok); | 701 ParseBlock(ok); |
695 scope_->LeaveWith(); | 702 scope_->LeaveWith(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 760 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
754 | 761 |
755 i::Scanner::Location before = scanner_->peek_location(); | 762 i::Scanner::Location before = scanner_->peek_location(); |
756 Expression expression = ParseConditionalExpression(accept_IN, CHECK_OK); | 763 Expression expression = ParseConditionalExpression(accept_IN, CHECK_OK); |
757 | 764 |
758 if (!i::Token::IsAssignmentOp(peek())) { | 765 if (!i::Token::IsAssignmentOp(peek())) { |
759 // Parsed conditional expression only (no assignment). | 766 // Parsed conditional expression only (no assignment). |
760 return expression; | 767 return expression; |
761 } | 768 } |
762 | 769 |
763 if (strict_mode() && expression.IsIdentifier() && | 770 if (!is_classic_mode() && |
| 771 expression.IsIdentifier() && |
764 expression.AsIdentifier().IsEvalOrArguments()) { | 772 expression.AsIdentifier().IsEvalOrArguments()) { |
765 i::Scanner::Location after = scanner_->location(); | 773 i::Scanner::Location after = scanner_->location(); |
766 ReportMessageAt(before.beg_pos, after.end_pos, | 774 ReportMessageAt(before.beg_pos, after.end_pos, |
767 "strict_lhs_assignment", NULL); | 775 "strict_lhs_assignment", NULL); |
768 *ok = false; | 776 *ok = false; |
769 return Expression::Default(); | 777 return Expression::Default(); |
770 } | 778 } |
771 | 779 |
772 i::Token::Value op = Next(); // Get assignment operator. | 780 i::Token::Value op = Next(); // Get assignment operator. |
773 ParseAssignmentExpression(accept_IN, CHECK_OK); | 781 ParseAssignmentExpression(accept_IN, CHECK_OK); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 | 849 |
842 i::Token::Value op = peek(); | 850 i::Token::Value op = peek(); |
843 if (i::Token::IsUnaryOp(op)) { | 851 if (i::Token::IsUnaryOp(op)) { |
844 op = Next(); | 852 op = Next(); |
845 ParseUnaryExpression(ok); | 853 ParseUnaryExpression(ok); |
846 return Expression::Default(); | 854 return Expression::Default(); |
847 } else if (i::Token::IsCountOp(op)) { | 855 } else if (i::Token::IsCountOp(op)) { |
848 op = Next(); | 856 op = Next(); |
849 i::Scanner::Location before = scanner_->peek_location(); | 857 i::Scanner::Location before = scanner_->peek_location(); |
850 Expression expression = ParseUnaryExpression(CHECK_OK); | 858 Expression expression = ParseUnaryExpression(CHECK_OK); |
851 if (strict_mode() && expression.IsIdentifier() && | 859 if (!is_classic_mode() && |
| 860 expression.IsIdentifier() && |
852 expression.AsIdentifier().IsEvalOrArguments()) { | 861 expression.AsIdentifier().IsEvalOrArguments()) { |
853 i::Scanner::Location after = scanner_->location(); | 862 i::Scanner::Location after = scanner_->location(); |
854 ReportMessageAt(before.beg_pos, after.end_pos, | 863 ReportMessageAt(before.beg_pos, after.end_pos, |
855 "strict_lhs_prefix", NULL); | 864 "strict_lhs_prefix", NULL); |
856 *ok = false; | 865 *ok = false; |
857 } | 866 } |
858 return Expression::Default(); | 867 return Expression::Default(); |
859 } else { | 868 } else { |
860 return ParsePostfixExpression(ok); | 869 return ParsePostfixExpression(ok); |
861 } | 870 } |
862 } | 871 } |
863 | 872 |
864 | 873 |
865 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { | 874 PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) { |
866 // PostfixExpression :: | 875 // PostfixExpression :: |
867 // LeftHandSideExpression ('++' | '--')? | 876 // LeftHandSideExpression ('++' | '--')? |
868 | 877 |
869 i::Scanner::Location before = scanner_->peek_location(); | 878 i::Scanner::Location before = scanner_->peek_location(); |
870 Expression expression = ParseLeftHandSideExpression(CHECK_OK); | 879 Expression expression = ParseLeftHandSideExpression(CHECK_OK); |
871 if (!scanner_->HasAnyLineTerminatorBeforeNext() && | 880 if (!scanner_->HasAnyLineTerminatorBeforeNext() && |
872 i::Token::IsCountOp(peek())) { | 881 i::Token::IsCountOp(peek())) { |
873 if (strict_mode() && expression.IsIdentifier() && | 882 if (!is_classic_mode() && |
| 883 expression.IsIdentifier() && |
874 expression.AsIdentifier().IsEvalOrArguments()) { | 884 expression.AsIdentifier().IsEvalOrArguments()) { |
875 i::Scanner::Location after = scanner_->location(); | 885 i::Scanner::Location after = scanner_->location(); |
876 ReportMessageAt(before.beg_pos, after.end_pos, | 886 ReportMessageAt(before.beg_pos, after.end_pos, |
877 "strict_lhs_postfix", NULL); | 887 "strict_lhs_postfix", NULL); |
878 *ok = false; | 888 *ok = false; |
879 return Expression::Default(); | 889 return Expression::Default(); |
880 } | 890 } |
881 Next(); | 891 Next(); |
882 return Expression::Default(); | 892 return Expression::Default(); |
883 } | 893 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 case i::Token::FUTURE_RESERVED_WORD: { | 1060 case i::Token::FUTURE_RESERVED_WORD: { |
1051 Next(); | 1061 Next(); |
1052 i::Scanner::Location location = scanner_->location(); | 1062 i::Scanner::Location location = scanner_->location(); |
1053 ReportMessageAt(location.beg_pos, location.end_pos, | 1063 ReportMessageAt(location.beg_pos, location.end_pos, |
1054 "reserved_word", NULL); | 1064 "reserved_word", NULL); |
1055 *ok = false; | 1065 *ok = false; |
1056 return Expression::Default(); | 1066 return Expression::Default(); |
1057 } | 1067 } |
1058 | 1068 |
1059 case i::Token::FUTURE_STRICT_RESERVED_WORD: | 1069 case i::Token::FUTURE_STRICT_RESERVED_WORD: |
1060 if (strict_mode()) { | 1070 if (!is_classic_mode()) { |
1061 Next(); | 1071 Next(); |
1062 i::Scanner::Location location = scanner_->location(); | 1072 i::Scanner::Location location = scanner_->location(); |
1063 ReportMessageAt(location, "strict_reserved_word", NULL); | 1073 ReportMessageAt(location, "strict_reserved_word", NULL); |
1064 *ok = false; | 1074 *ok = false; |
1065 return Expression::Default(); | 1075 return Expression::Default(); |
1066 } | 1076 } |
1067 // FALLTHROUGH | 1077 // FALLTHROUGH |
1068 case i::Token::IDENTIFIER: { | 1078 case i::Token::IDENTIFIER: { |
1069 Identifier id = ParseIdentifier(CHECK_OK); | 1079 Identifier id = ParseIdentifier(CHECK_OK); |
1070 result = Expression::FromIdentifier(id); | 1080 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); | 1160 old_type = finder->AddNumber(scanner_->literal_ascii_string(), type); |
1151 } else if (scanner_->is_literal_ascii()) { | 1161 } else if (scanner_->is_literal_ascii()) { |
1152 old_type = finder->AddAsciiSymbol(scanner_->literal_ascii_string(), | 1162 old_type = finder->AddAsciiSymbol(scanner_->literal_ascii_string(), |
1153 type); | 1163 type); |
1154 } else { | 1164 } else { |
1155 old_type = finder->AddUC16Symbol(scanner_->literal_uc16_string(), type); | 1165 old_type = finder->AddUC16Symbol(scanner_->literal_uc16_string(), type); |
1156 } | 1166 } |
1157 if (HasConflict(old_type, type)) { | 1167 if (HasConflict(old_type, type)) { |
1158 if (IsDataDataConflict(old_type, type)) { | 1168 if (IsDataDataConflict(old_type, type)) { |
1159 // Both are data properties. | 1169 // Both are data properties. |
1160 if (!strict_mode()) return; | 1170 if (is_classic_mode()) return; |
1161 ReportMessageAt(scanner_->location(), | 1171 ReportMessageAt(scanner_->location(), |
1162 "strict_duplicate_property", NULL); | 1172 "strict_duplicate_property", NULL); |
1163 } else if (IsDataAccessorConflict(old_type, type)) { | 1173 } else if (IsDataAccessorConflict(old_type, type)) { |
1164 // Both a data and an accessor property with the same name. | 1174 // Both a data and an accessor property with the same name. |
1165 ReportMessageAt(scanner_->location(), | 1175 ReportMessageAt(scanner_->location(), |
1166 "accessor_data_property", NULL); | 1176 "accessor_data_property", NULL); |
1167 } else { | 1177 } else { |
1168 ASSERT(IsAccessorAccessorConflict(old_type, type)); | 1178 ASSERT(IsAccessorAccessorConflict(old_type, type)); |
1169 // Both accessors of the same type. | 1179 // Both accessors of the same type. |
1170 ReportMessageAt(scanner_->location(), | 1180 ReportMessageAt(scanner_->location(), |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 log_->ResumeRecording(); | 1367 log_->ResumeRecording(); |
1358 if (!*ok) Expression::Default(); | 1368 if (!*ok) Expression::Default(); |
1359 | 1369 |
1360 Expect(i::Token::RBRACE, CHECK_OK); | 1370 Expect(i::Token::RBRACE, CHECK_OK); |
1361 | 1371 |
1362 // Position right after terminal '}'. | 1372 // Position right after terminal '}'. |
1363 int end_pos = scanner_->location().end_pos; | 1373 int end_pos = scanner_->location().end_pos; |
1364 log_->LogFunction(function_block_pos, end_pos, | 1374 log_->LogFunction(function_block_pos, end_pos, |
1365 function_scope.materialized_literal_count(), | 1375 function_scope.materialized_literal_count(), |
1366 function_scope.expected_properties(), | 1376 function_scope.expected_properties(), |
1367 strict_mode_flag()); | 1377 language_mode()); |
1368 } else { | 1378 } else { |
1369 ParseSourceElements(i::Token::RBRACE, CHECK_OK); | 1379 ParseSourceElements(i::Token::RBRACE, CHECK_OK); |
1370 Expect(i::Token::RBRACE, CHECK_OK); | 1380 Expect(i::Token::RBRACE, CHECK_OK); |
1371 } | 1381 } |
1372 | 1382 |
1373 if (strict_mode()) { | 1383 if (!is_classic_mode()) { |
1374 int end_position = scanner_->location().end_pos; | 1384 int end_position = scanner_->location().end_pos; |
1375 CheckOctalLiteral(start_position, end_position, CHECK_OK); | 1385 CheckOctalLiteral(start_position, end_position, CHECK_OK); |
1376 CheckDelayedStrictModeViolation(start_position, end_position, CHECK_OK); | 1386 CheckDelayedStrictModeViolation(start_position, end_position, CHECK_OK); |
1377 return Expression::StrictFunction(); | 1387 return Expression::StrictFunction(); |
1378 } | 1388 } |
1379 | 1389 |
1380 return Expression::Default(); | 1390 return Expression::Default(); |
1381 } | 1391 } |
1382 | 1392 |
1383 | 1393 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 i::Token::Value next = Next(); | 1477 i::Token::Value next = Next(); |
1468 switch (next) { | 1478 switch (next) { |
1469 case i::Token::FUTURE_RESERVED_WORD: { | 1479 case i::Token::FUTURE_RESERVED_WORD: { |
1470 i::Scanner::Location location = scanner_->location(); | 1480 i::Scanner::Location location = scanner_->location(); |
1471 ReportMessageAt(location.beg_pos, location.end_pos, | 1481 ReportMessageAt(location.beg_pos, location.end_pos, |
1472 "reserved_word", NULL); | 1482 "reserved_word", NULL); |
1473 *ok = false; | 1483 *ok = false; |
1474 return GetIdentifierSymbol(); | 1484 return GetIdentifierSymbol(); |
1475 } | 1485 } |
1476 case i::Token::FUTURE_STRICT_RESERVED_WORD: | 1486 case i::Token::FUTURE_STRICT_RESERVED_WORD: |
1477 if (strict_mode()) { | 1487 if (!is_classic_mode()) { |
1478 i::Scanner::Location location = scanner_->location(); | 1488 i::Scanner::Location location = scanner_->location(); |
1479 ReportMessageAt(location.beg_pos, location.end_pos, | 1489 ReportMessageAt(location.beg_pos, location.end_pos, |
1480 "strict_reserved_word", NULL); | 1490 "strict_reserved_word", NULL); |
1481 *ok = false; | 1491 *ok = false; |
1482 } | 1492 } |
1483 // FALLTHROUGH | 1493 // FALLTHROUGH |
1484 case i::Token::IDENTIFIER: | 1494 case i::Token::IDENTIFIER: |
1485 return GetIdentifierSymbol(); | 1495 return GetIdentifierSymbol(); |
1486 default: | 1496 default: |
1487 *ok = false; | 1497 *ok = false; |
1488 return Identifier::Default(); | 1498 return Identifier::Default(); |
1489 } | 1499 } |
1490 } | 1500 } |
1491 | 1501 |
1492 | 1502 |
1493 void PreParser::SetStrictModeViolation(i::Scanner::Location location, | 1503 void PreParser::SetStrictModeViolation(i::Scanner::Location location, |
1494 const char* type, | 1504 const char* type, |
1495 bool* ok) { | 1505 bool* ok) { |
1496 if (strict_mode()) { | 1506 if (!is_classic_mode()) { |
1497 ReportMessageAt(location, type, NULL); | 1507 ReportMessageAt(location, type, NULL); |
1498 *ok = false; | 1508 *ok = false; |
1499 return; | 1509 return; |
1500 } | 1510 } |
1501 // Delay report in case this later turns out to be strict code | 1511 // 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" | 1512 // (i.e., for function names and parameters prior to a "use strict" |
1503 // directive). | 1513 // directive). |
1504 // It's safe to overwrite an existing violation. | 1514 // It's safe to overwrite an existing violation. |
1505 // It's either from a function that turned out to be non-strict, | 1515 // 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 | 1516 // 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, | 1536 void PreParser::StrictModeIdentifierViolation(i::Scanner::Location location, |
1527 const char* eval_args_type, | 1537 const char* eval_args_type, |
1528 Identifier identifier, | 1538 Identifier identifier, |
1529 bool* ok) { | 1539 bool* ok) { |
1530 const char* type = eval_args_type; | 1540 const char* type = eval_args_type; |
1531 if (identifier.IsFutureReserved()) { | 1541 if (identifier.IsFutureReserved()) { |
1532 type = "reserved_word"; | 1542 type = "reserved_word"; |
1533 } else if (identifier.IsFutureStrictReserved()) { | 1543 } else if (identifier.IsFutureStrictReserved()) { |
1534 type = "strict_reserved_word"; | 1544 type = "strict_reserved_word"; |
1535 } | 1545 } |
1536 if (strict_mode()) { | 1546 if (!is_classic_mode()) { |
1537 ReportMessageAt(location, type, NULL); | 1547 ReportMessageAt(location, type, NULL); |
1538 *ok = false; | 1548 *ok = false; |
1539 return; | 1549 return; |
1540 } | 1550 } |
1541 strict_mode_violation_location_ = location; | 1551 strict_mode_violation_location_ = location; |
1542 strict_mode_violation_type_ = type; | 1552 strict_mode_violation_type_ = type; |
1543 } | 1553 } |
1544 | 1554 |
1545 | 1555 |
1546 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { | 1556 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)); | 1724 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); |
1715 } | 1725 } |
1716 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); | 1726 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); |
1717 } | 1727 } |
1718 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); | 1728 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); |
1719 | 1729 |
1720 backing_store_.AddBlock(bytes); | 1730 backing_store_.AddBlock(bytes); |
1721 return backing_store_.EndSequence().start(); | 1731 return backing_store_.EndSequence().start(); |
1722 } | 1732 } |
1723 } } // v8::preparser | 1733 } } // v8::preparser |
OLD | NEW |