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 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1438 return new(zone()) ExpressionStatement(new(zone()) Assignment( | 1438 return new(zone()) ExpressionStatement(new(zone()) Assignment( |
1439 Token::INIT_VAR, var, lit, RelocInfo::kNoPosition)); | 1439 Token::INIT_VAR, var, lit, RelocInfo::kNoPosition)); |
1440 } | 1440 } |
1441 | 1441 |
1442 | 1442 |
1443 Statement* Parser::ParseFunctionDeclaration(bool* ok) { | 1443 Statement* Parser::ParseFunctionDeclaration(bool* ok) { |
1444 // FunctionDeclaration :: | 1444 // FunctionDeclaration :: |
1445 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 1445 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
1446 Expect(Token::FUNCTION, CHECK_OK); | 1446 Expect(Token::FUNCTION, CHECK_OK); |
1447 int function_token_position = scanner().location().beg_pos; | 1447 int function_token_position = scanner().location().beg_pos; |
1448 bool is_reserved = false; | 1448 bool is_strict_reserved = false; |
1449 Handle<String> name = ParseIdentifierOrReservedWord(&is_reserved, CHECK_OK); | 1449 Handle<String> name = ParseIdentifierOrStrictReservedWord( |
1450 &is_strict_reserved, CHECK_OK); | |
1450 FunctionLiteral* fun = ParseFunctionLiteral(name, | 1451 FunctionLiteral* fun = ParseFunctionLiteral(name, |
1451 is_reserved, | 1452 is_strict_reserved, |
1452 function_token_position, | 1453 function_token_position, |
1453 DECLARATION, | 1454 DECLARATION, |
1454 CHECK_OK); | 1455 CHECK_OK); |
1455 // Even if we're not at the top-level of the global or a function | 1456 // Even if we're not at the top-level of the global or a function |
1456 // scope, we treat is as such and introduce the function with it's | 1457 // scope, we treat is as such and introduce the function with it's |
1457 // initial value upon entering the corresponding scope. | 1458 // initial value upon entering the corresponding scope. |
1458 Declare(name, Variable::VAR, fun, true, CHECK_OK); | 1459 Declare(name, Variable::VAR, fun, true, CHECK_OK); |
1459 return EmptyStatement(); | 1460 return EmptyStatement(); |
1460 } | 1461 } |
1461 | 1462 |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2763 // MemberExpression :: | 2764 // MemberExpression :: |
2764 // (PrimaryExpression | FunctionLiteral) | 2765 // (PrimaryExpression | FunctionLiteral) |
2765 // ('[' Expression ']' | '.' Identifier | Arguments)* | 2766 // ('[' Expression ']' | '.' Identifier | Arguments)* |
2766 | 2767 |
2767 // Parse the initial primary or function expression. | 2768 // Parse the initial primary or function expression. |
2768 Expression* result = NULL; | 2769 Expression* result = NULL; |
2769 if (peek() == Token::FUNCTION) { | 2770 if (peek() == Token::FUNCTION) { |
2770 Expect(Token::FUNCTION, CHECK_OK); | 2771 Expect(Token::FUNCTION, CHECK_OK); |
2771 int function_token_position = scanner().location().beg_pos; | 2772 int function_token_position = scanner().location().beg_pos; |
2772 Handle<String> name; | 2773 Handle<String> name; |
2773 bool is_reserved_name = false; | 2774 bool is_strict_reserved_name = false; |
2774 if (peek_any_identifier()) { | 2775 if (peek_any_identifier()) { |
2775 name = ParseIdentifierOrReservedWord(&is_reserved_name, CHECK_OK); | 2776 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, |
2777 CHECK_OK); | |
2776 } | 2778 } |
2777 result = ParseFunctionLiteral(name, is_reserved_name, | 2779 result = ParseFunctionLiteral(name, is_strict_reserved_name, |
2778 function_token_position, NESTED, CHECK_OK); | 2780 function_token_position, NESTED, CHECK_OK); |
2779 } else { | 2781 } else { |
2780 result = ParsePrimaryExpression(CHECK_OK); | 2782 result = ParsePrimaryExpression(CHECK_OK); |
2781 } | 2783 } |
2782 | 2784 |
2783 while (true) { | 2785 while (true) { |
2784 switch (peek()) { | 2786 switch (peek()) { |
2785 case Token::LBRACK: { | 2787 case Token::LBRACK: { |
2786 Consume(Token::LBRACK); | 2788 Consume(Token::LBRACK); |
2787 int pos = scanner().location().beg_pos; | 2789 int pos = scanner().location().beg_pos; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2838 case Token::NUMBER: | 2840 case Token::NUMBER: |
2839 return ReportMessage("unexpected_token_number", | 2841 return ReportMessage("unexpected_token_number", |
2840 Vector<const char*>::empty()); | 2842 Vector<const char*>::empty()); |
2841 case Token::STRING: | 2843 case Token::STRING: |
2842 return ReportMessage("unexpected_token_string", | 2844 return ReportMessage("unexpected_token_string", |
2843 Vector<const char*>::empty()); | 2845 Vector<const char*>::empty()); |
2844 case Token::IDENTIFIER: | 2846 case Token::IDENTIFIER: |
2845 return ReportMessage("unexpected_token_identifier", | 2847 return ReportMessage("unexpected_token_identifier", |
2846 Vector<const char*>::empty()); | 2848 Vector<const char*>::empty()); |
2847 case Token::FUTURE_RESERVED_WORD: | 2849 case Token::FUTURE_RESERVED_WORD: |
2850 return ReportMessage("unexpected_reserved", | |
2851 Vector<const char*>::empty()); | |
2852 case Token::FUTURE_STRICT_RESERVED_WORD: | |
2848 return ReportMessage(top_scope_->is_strict_mode() ? | 2853 return ReportMessage(top_scope_->is_strict_mode() ? |
2849 "unexpected_strict_reserved" : | 2854 "unexpected_strict_reserved" : |
2850 "unexpected_token_identifier", | 2855 "unexpected_token_identifier", |
2851 Vector<const char*>::empty()); | 2856 Vector<const char*>::empty()); |
2852 default: | 2857 default: |
2853 const char* name = Token::String(token); | 2858 const char* name = Token::String(token); |
2854 ASSERT(name != NULL); | 2859 ASSERT(name != NULL); |
2855 ReportMessage("unexpected_token", Vector<const char*>(&name, 1)); | 2860 ReportMessage("unexpected_token", Vector<const char*>(&name, 1)); |
2856 } | 2861 } |
2857 } | 2862 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2897 case Token::TRUE_LITERAL: | 2902 case Token::TRUE_LITERAL: |
2898 Consume(Token::TRUE_LITERAL); | 2903 Consume(Token::TRUE_LITERAL); |
2899 result = new(zone()) Literal(isolate()->factory()->true_value()); | 2904 result = new(zone()) Literal(isolate()->factory()->true_value()); |
2900 break; | 2905 break; |
2901 | 2906 |
2902 case Token::FALSE_LITERAL: | 2907 case Token::FALSE_LITERAL: |
2903 Consume(Token::FALSE_LITERAL); | 2908 Consume(Token::FALSE_LITERAL); |
2904 result = new(zone()) Literal(isolate()->factory()->false_value()); | 2909 result = new(zone()) Literal(isolate()->factory()->false_value()); |
2905 break; | 2910 break; |
2906 | 2911 |
2907 case Token::IDENTIFIER: | 2912 case Token::FUTURE_STRICT_RESERVED_WORD: |
2908 case Token::FUTURE_RESERVED_WORD: { | 2913 if (top_scope_->is_strict_mode()) { |
2909 Handle<String> name = ParseIdentifier(CHECK_OK); | 2914 Token::Value tok = Next(); |
2915 ReportUnexpectedToken(tok); | |
2916 *ok = false; | |
2917 return NULL; | |
2918 } | |
2919 // FALLTHROUGH | |
2920 case Token::IDENTIFIER: { | |
2921 Handle<String> name = ParseIdentifierName(CHECK_OK); | |
Lasse Reichstein
2011/06/22 20:29:33
It seems ParseIdentifier would be more correct her
Steven
2011/06/24 11:34:59
Better still: revert the change and just replace F
| |
2910 if (fni_ != NULL) fni_->PushVariableName(name); | 2922 if (fni_ != NULL) fni_->PushVariableName(name); |
2911 result = top_scope_->NewUnresolved(name, | 2923 result = top_scope_->NewUnresolved(name, |
2912 inside_with(), | 2924 inside_with(), |
2913 scanner().location().beg_pos); | 2925 scanner().location().beg_pos); |
2914 break; | 2926 break; |
2915 } | 2927 } |
2916 | 2928 |
2917 case Token::NUMBER: { | 2929 case Token::NUMBER: { |
2918 Consume(Token::NUMBER); | 2930 Consume(Token::NUMBER); |
2919 ASSERT(scanner().is_literal_ascii()); | 2931 ASSERT(scanner().is_literal_ascii()); |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3309 | 3321 |
3310 ObjectLiteral::Property* Parser::ParseObjectLiteralGetSet(bool is_getter, | 3322 ObjectLiteral::Property* Parser::ParseObjectLiteralGetSet(bool is_getter, |
3311 bool* ok) { | 3323 bool* ok) { |
3312 // Special handling of getter and setter syntax: | 3324 // Special handling of getter and setter syntax: |
3313 // { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... } | 3325 // { ... , get foo() { ... }, ... , set foo(v) { ... v ... } , ... } |
3314 // We have already read the "get" or "set" keyword. | 3326 // We have already read the "get" or "set" keyword. |
3315 Token::Value next = Next(); | 3327 Token::Value next = Next(); |
3316 bool is_keyword = Token::IsKeyword(next); | 3328 bool is_keyword = Token::IsKeyword(next); |
3317 if (next == Token::IDENTIFIER || next == Token::NUMBER || | 3329 if (next == Token::IDENTIFIER || next == Token::NUMBER || |
3318 next == Token::FUTURE_RESERVED_WORD || | 3330 next == Token::FUTURE_RESERVED_WORD || |
3331 next == Token::FUTURE_STRICT_RESERVED_WORD || | |
3319 next == Token::STRING || is_keyword) { | 3332 next == Token::STRING || is_keyword) { |
3320 Handle<String> name; | 3333 Handle<String> name; |
3321 if (is_keyword) { | 3334 if (is_keyword) { |
3322 name = isolate_->factory()->LookupAsciiSymbol(Token::String(next)); | 3335 name = isolate_->factory()->LookupAsciiSymbol(Token::String(next)); |
3323 } else { | 3336 } else { |
3324 name = GetSymbol(CHECK_OK); | 3337 name = GetSymbol(CHECK_OK); |
3325 } | 3338 } |
3326 FunctionLiteral* value = | 3339 FunctionLiteral* value = |
3327 ParseFunctionLiteral(name, | 3340 ParseFunctionLiteral(name, |
3328 false, // reserved words are allowed here | 3341 false, // reserved words are allowed here |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3363 if (fni_ != NULL) fni_->Enter(); | 3376 if (fni_ != NULL) fni_->Enter(); |
3364 | 3377 |
3365 Literal* key = NULL; | 3378 Literal* key = NULL; |
3366 Token::Value next = peek(); | 3379 Token::Value next = peek(); |
3367 | 3380 |
3368 // Location of the property name token | 3381 // Location of the property name token |
3369 Scanner::Location loc = scanner().peek_location(); | 3382 Scanner::Location loc = scanner().peek_location(); |
3370 | 3383 |
3371 switch (next) { | 3384 switch (next) { |
3372 case Token::FUTURE_RESERVED_WORD: | 3385 case Token::FUTURE_RESERVED_WORD: |
3386 case Token::FUTURE_STRICT_RESERVED_WORD: | |
3373 case Token::IDENTIFIER: { | 3387 case Token::IDENTIFIER: { |
3374 bool is_getter = false; | 3388 bool is_getter = false; |
3375 bool is_setter = false; | 3389 bool is_setter = false; |
3376 Handle<String> id = | 3390 Handle<String> id = |
3377 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK); | 3391 ParseIdentifierNameOrGetOrSet(&is_getter, &is_setter, CHECK_OK); |
3378 if (fni_ != NULL) fni_->PushLiteralName(id); | 3392 if (fni_ != NULL) fni_->PushLiteralName(id); |
3379 | 3393 |
3380 if ((is_getter || is_setter) && peek() != Token::COLON) { | 3394 if ((is_getter || is_setter) && peek() != Token::COLON) { |
3381 // Update loc to point to the identifier | 3395 // Update loc to point to the identifier |
3382 loc = scanner().peek_location(); | 3396 loc = scanner().peek_location(); |
3383 ObjectLiteral::Property* property = | 3397 ObjectLiteral::Property* property = |
3384 ParseObjectLiteralGetSet(is_getter, CHECK_OK); | 3398 ParseObjectLiteralGetSet(is_getter, CHECK_OK); |
3385 if (IsBoilerplateProperty(property)) { | 3399 if (IsBoilerplateProperty(property)) { |
3386 number_of_boilerplate_properties++; | 3400 number_of_boilerplate_properties++; |
3387 } | 3401 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3526 } | 3540 } |
3527 done = (peek() == Token::RPAREN); | 3541 done = (peek() == Token::RPAREN); |
3528 if (!done) Expect(Token::COMMA, CHECK_OK); | 3542 if (!done) Expect(Token::COMMA, CHECK_OK); |
3529 } | 3543 } |
3530 Expect(Token::RPAREN, CHECK_OK); | 3544 Expect(Token::RPAREN, CHECK_OK); |
3531 return result; | 3545 return result; |
3532 } | 3546 } |
3533 | 3547 |
3534 | 3548 |
3535 FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, | 3549 FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, |
3536 bool name_is_reserved, | 3550 bool name_is_strict_reserved, |
3537 int function_token_position, | 3551 int function_token_position, |
3538 FunctionLiteralType type, | 3552 FunctionLiteralType type, |
3539 bool* ok) { | 3553 bool* ok) { |
3540 // Function :: | 3554 // Function :: |
3541 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 3555 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
3542 bool is_named = !var_name.is_null(); | 3556 bool is_named = !var_name.is_null(); |
3543 | 3557 |
3544 // The name associated with this function. If it's a function expression, | 3558 // The name associated with this function. If it's a function expression, |
3545 // this is the actual function name, otherwise this is the name of the | 3559 // this is the actual function name, otherwise this is the name of the |
3546 // variable declared and initialized with the function (expression). In | 3560 // variable declared and initialized with the function (expression). In |
(...skipping 23 matching lines...) Expand all Loading... | |
3570 // FormalParameterList :: | 3584 // FormalParameterList :: |
3571 // '(' (Identifier)*[','] ')' | 3585 // '(' (Identifier)*[','] ')' |
3572 Expect(Token::LPAREN, CHECK_OK); | 3586 Expect(Token::LPAREN, CHECK_OK); |
3573 start_pos = scanner().location().beg_pos; | 3587 start_pos = scanner().location().beg_pos; |
3574 Scanner::Location name_loc = Scanner::Location::invalid(); | 3588 Scanner::Location name_loc = Scanner::Location::invalid(); |
3575 Scanner::Location dupe_loc = Scanner::Location::invalid(); | 3589 Scanner::Location dupe_loc = Scanner::Location::invalid(); |
3576 Scanner::Location reserved_loc = Scanner::Location::invalid(); | 3590 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
3577 | 3591 |
3578 bool done = (peek() == Token::RPAREN); | 3592 bool done = (peek() == Token::RPAREN); |
3579 while (!done) { | 3593 while (!done) { |
3580 bool is_reserved = false; | 3594 bool is_strict_reserved = false; |
3581 Handle<String> param_name = | 3595 Handle<String> param_name = |
3582 ParseIdentifierOrReservedWord(&is_reserved, CHECK_OK); | 3596 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, |
3597 CHECK_OK); | |
3583 | 3598 |
3584 // Store locations for possible future error reports. | 3599 // Store locations for possible future error reports. |
3585 if (!name_loc.IsValid() && IsEvalOrArguments(param_name)) { | 3600 if (!name_loc.IsValid() && IsEvalOrArguments(param_name)) { |
3586 name_loc = scanner().location(); | 3601 name_loc = scanner().location(); |
3587 } | 3602 } |
3588 if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) { | 3603 if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) { |
3589 has_duplicate_parameters = true; | 3604 has_duplicate_parameters = true; |
3590 dupe_loc = scanner().location(); | 3605 dupe_loc = scanner().location(); |
3591 } | 3606 } |
3592 if (!reserved_loc.IsValid() && is_reserved) { | 3607 if (!reserved_loc.IsValid() && is_strict_reserved) { |
3593 reserved_loc = scanner().location(); | 3608 reserved_loc = scanner().location(); |
3594 } | 3609 } |
3595 | 3610 |
3596 top_scope_->DeclareParameter(param_name); | 3611 top_scope_->DeclareParameter(param_name); |
3597 num_parameters++; | 3612 num_parameters++; |
3598 if (num_parameters > kMaxNumFunctionParameters) { | 3613 if (num_parameters > kMaxNumFunctionParameters) { |
3599 ReportMessageAt(scanner().location(), "too_many_parameters", | 3614 ReportMessageAt(scanner().location(), "too_many_parameters", |
3600 Vector<const char*>::empty()); | 3615 Vector<const char*>::empty()); |
3601 *ok = false; | 3616 *ok = false; |
3602 return NULL; | 3617 return NULL; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3684 Vector<const char*>::empty()); | 3699 Vector<const char*>::empty()); |
3685 *ok = false; | 3700 *ok = false; |
3686 return NULL; | 3701 return NULL; |
3687 } | 3702 } |
3688 if (dupe_loc.IsValid()) { | 3703 if (dupe_loc.IsValid()) { |
3689 ReportMessageAt(dupe_loc, "strict_param_dupe", | 3704 ReportMessageAt(dupe_loc, "strict_param_dupe", |
3690 Vector<const char*>::empty()); | 3705 Vector<const char*>::empty()); |
3691 *ok = false; | 3706 *ok = false; |
3692 return NULL; | 3707 return NULL; |
3693 } | 3708 } |
3694 if (name_is_reserved) { | 3709 if (name_is_strict_reserved) { |
3695 int position = function_token_position != RelocInfo::kNoPosition | 3710 int position = function_token_position != RelocInfo::kNoPosition |
3696 ? function_token_position | 3711 ? function_token_position |
3697 : (start_pos > 0 ? start_pos - 1 : start_pos); | 3712 : (start_pos > 0 ? start_pos - 1 : start_pos); |
3698 Scanner::Location location = Scanner::Location(position, start_pos); | 3713 Scanner::Location location = Scanner::Location(position, start_pos); |
3699 ReportMessageAt(location, "strict_reserved_word", | 3714 ReportMessageAt(location, "strict_reserved_word", |
3700 Vector<const char*>::empty()); | 3715 Vector<const char*>::empty()); |
3701 *ok = false; | 3716 *ok = false; |
3702 return NULL; | 3717 return NULL; |
3703 } | 3718 } |
3704 if (reserved_loc.IsValid()) { | 3719 if (reserved_loc.IsValid()) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3773 } | 3788 } |
3774 | 3789 |
3775 // We have a valid intrinsics call or a call to a builtin. | 3790 // We have a valid intrinsics call or a call to a builtin. |
3776 return new(zone()) CallRuntime(name, function, args); | 3791 return new(zone()) CallRuntime(name, function, args); |
3777 } | 3792 } |
3778 | 3793 |
3779 | 3794 |
3780 bool Parser::peek_any_identifier() { | 3795 bool Parser::peek_any_identifier() { |
3781 Token::Value next = peek(); | 3796 Token::Value next = peek(); |
3782 return next == Token::IDENTIFIER || | 3797 return next == Token::IDENTIFIER || |
3783 next == Token::FUTURE_RESERVED_WORD; | 3798 next == Token::FUTURE_RESERVED_WORD || |
3799 next == Token::FUTURE_STRICT_RESERVED_WORD; | |
3784 } | 3800 } |
3785 | 3801 |
3786 | 3802 |
3787 void Parser::Consume(Token::Value token) { | 3803 void Parser::Consume(Token::Value token) { |
3788 Token::Value next = Next(); | 3804 Token::Value next = Next(); |
3789 USE(next); | 3805 USE(next); |
3790 USE(token); | 3806 USE(token); |
3791 ASSERT(next == token); | 3807 ASSERT(next == token); |
3792 } | 3808 } |
3793 | 3809 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3835 Literal* Parser::GetLiteralTheHole() { | 3851 Literal* Parser::GetLiteralTheHole() { |
3836 return new(zone()) Literal(isolate()->factory()->the_hole_value()); | 3852 return new(zone()) Literal(isolate()->factory()->the_hole_value()); |
3837 } | 3853 } |
3838 | 3854 |
3839 | 3855 |
3840 Literal* Parser::GetLiteralNumber(double value) { | 3856 Literal* Parser::GetLiteralNumber(double value) { |
3841 return NewNumberLiteral(value); | 3857 return NewNumberLiteral(value); |
3842 } | 3858 } |
3843 | 3859 |
3844 | 3860 |
3845 Handle<String> Parser::ParseIdentifier(bool* ok) { | 3861 Handle<String> Parser::ParseIdentifier(bool* ok) { |
Lasse Reichstein
2011/06/22 20:29:33
This also (like the next function) parse identifie
Steven
2011/06/24 11:34:59
Because they implement a different behavior. And t
Lasse Reichstein
2011/06/24 12:38:04
Makes sense when explained :)
| |
3846 bool is_reserved; | 3862 if (top_scope_->is_strict_mode()) { |
3847 return ParseIdentifierOrReservedWord(&is_reserved, ok); | 3863 Expect(Token::IDENTIFIER, ok); |
3864 } else if (!Check(Token::IDENTIFIER)) { | |
3865 Expect(Token::FUTURE_STRICT_RESERVED_WORD, ok); | |
3866 } | |
3867 if (!*ok) return Handle<String>(); | |
3868 return GetSymbol(ok); | |
3848 } | 3869 } |
3849 | 3870 |
3850 | 3871 |
3851 Handle<String> Parser::ParseIdentifierOrReservedWord(bool* is_reserved, | 3872 Handle<String> Parser::ParseIdentifierOrStrictReservedWord( |
3852 bool* ok) { | 3873 bool* is_strict_reserved, bool* ok) { |
3853 *is_reserved = false; | 3874 *is_strict_reserved = false; |
3854 if (top_scope_->is_strict_mode()) { | 3875 if (!Check(Token::IDENTIFIER)) { |
3855 Expect(Token::IDENTIFIER, ok); | 3876 Expect(Token::FUTURE_STRICT_RESERVED_WORD, ok); |
3856 } else { | 3877 *is_strict_reserved = true; |
3857 if (!Check(Token::IDENTIFIER)) { | |
3858 Expect(Token::FUTURE_RESERVED_WORD, ok); | |
3859 *is_reserved = true; | |
3860 } | |
3861 } | 3878 } |
3862 if (!*ok) return Handle<String>(); | 3879 if (!*ok) return Handle<String>(); |
3863 return GetSymbol(ok); | 3880 return GetSymbol(ok); |
3864 } | 3881 } |
3865 | 3882 |
3866 | 3883 |
3867 Handle<String> Parser::ParseIdentifierName(bool* ok) { | 3884 Handle<String> Parser::ParseIdentifierName(bool* ok) { |
3868 Token::Value next = Next(); | 3885 Token::Value next = Next(); |
3869 if (next != Token::IDENTIFIER && | 3886 if (next != Token::IDENTIFIER && |
3870 next != Token::FUTURE_RESERVED_WORD && | 3887 next != Token::FUTURE_RESERVED_WORD && |
3871 !Token::IsKeyword(next)) { | 3888 next != Token::FUTURE_STRICT_RESERVED_WORD && |
3889 !Token::IsKeyword(next)) { | |
3872 ReportUnexpectedToken(next); | 3890 ReportUnexpectedToken(next); |
3873 *ok = false; | 3891 *ok = false; |
3874 return Handle<String>(); | 3892 return Handle<String>(); |
3875 } | 3893 } |
3876 return GetSymbol(ok); | 3894 return GetSymbol(ok); |
3877 } | 3895 } |
3878 | 3896 |
3879 | 3897 |
3880 // Checks LHS expression for assignment and prefix/postfix increment/decrement | 3898 // Checks LHS expression for assignment and prefix/postfix increment/decrement |
3881 // in strict mode. | 3899 // in strict mode. |
(...skipping 22 matching lines...) Expand all Loading... | |
3904 ReportMessageAt(octal, "strict_octal_literal", | 3922 ReportMessageAt(octal, "strict_octal_literal", |
3905 Vector<const char*>::empty()); | 3923 Vector<const char*>::empty()); |
3906 scanner().clear_octal_position(); | 3924 scanner().clear_octal_position(); |
3907 *ok = false; | 3925 *ok = false; |
3908 } | 3926 } |
3909 } | 3927 } |
3910 | 3928 |
3911 | 3929 |
3912 // This function reads an identifier and determines whether or not it | 3930 // This function reads an identifier and determines whether or not it |
3913 // is 'get' or 'set'. | 3931 // is 'get' or 'set'. |
3914 Handle<String> Parser::ParseIdentifierOrGetOrSet(bool* is_get, | 3932 Handle<String> Parser::ParseIdentifierNameOrGetOrSet(bool* is_get, |
3915 bool* is_set, | 3933 bool* is_set, |
3916 bool* ok) { | 3934 bool* ok) { |
3917 Handle<String> result = ParseIdentifier(ok); | 3935 Handle<String> result = ParseIdentifierName(ok); |
3918 if (!*ok) return Handle<String>(); | 3936 if (!*ok) return Handle<String>(); |
3919 if (scanner().is_literal_ascii() && scanner().literal_length() == 3) { | 3937 if (scanner().is_literal_ascii() && scanner().literal_length() == 3) { |
3920 const char* token = scanner().literal_ascii_string().start(); | 3938 const char* token = scanner().literal_ascii_string().start(); |
3921 *is_get = strncmp(token, "get", 3) == 0; | 3939 *is_get = strncmp(token, "get", 3) == 0; |
3922 *is_set = !*is_get && strncmp(token, "set", 3) == 0; | 3940 *is_set = !*is_get && strncmp(token, "set", 3) == 0; |
3923 } | 3941 } |
3924 return result; | 3942 return result; |
3925 } | 3943 } |
3926 | 3944 |
3927 | 3945 |
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5008 info->is_global(), | 5026 info->is_global(), |
5009 info->StrictMode()); | 5027 info->StrictMode()); |
5010 } | 5028 } |
5011 } | 5029 } |
5012 | 5030 |
5013 info->SetFunction(result); | 5031 info->SetFunction(result); |
5014 return (result != NULL); | 5032 return (result != NULL); |
5015 } | 5033 } |
5016 | 5034 |
5017 } } // namespace v8::internal | 5035 } } // namespace v8::internal |
OLD | NEW |