OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 info()->is_extended_mode()); | 763 info()->is_extended_mode()); |
764 ASSERT(info()->language_mode() == shared_info->language_mode()); | 764 ASSERT(info()->language_mode() == shared_info->language_mode()); |
765 scope->SetLanguageMode(shared_info->language_mode()); | 765 scope->SetLanguageMode(shared_info->language_mode()); |
766 FunctionLiteral::FunctionType function_type = shared_info->is_expression() | 766 FunctionLiteral::FunctionType function_type = shared_info->is_expression() |
767 ? (shared_info->is_anonymous() | 767 ? (shared_info->is_anonymous() |
768 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 768 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
769 : FunctionLiteral::NAMED_EXPRESSION) | 769 : FunctionLiteral::NAMED_EXPRESSION) |
770 : FunctionLiteral::DECLARATION; | 770 : FunctionLiteral::DECLARATION; |
771 bool ok = true; | 771 bool ok = true; |
772 result = ParseFunctionLiteral(name, | 772 result = ParseFunctionLiteral(name, |
| 773 Scanner::Location::invalid(), |
773 false, // Strict mode name already checked. | 774 false, // Strict mode name already checked. |
774 shared_info->is_generator(), | 775 shared_info->is_generator(), |
775 RelocInfo::kNoPosition, | 776 RelocInfo::kNoPosition, |
776 function_type, | 777 function_type, |
777 &ok); | 778 &ok); |
778 // Make sure the results agree. | 779 // Make sure the results agree. |
779 ASSERT(ok == (result != NULL)); | 780 ASSERT(ok == (result != NULL)); |
780 } | 781 } |
781 | 782 |
782 // Make sure the target stack is empty. | 783 // Make sure the target stack is empty. |
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 // GeneratorDeclaration :: | 1673 // GeneratorDeclaration :: |
1673 // 'function' '*' Identifier '(' FormalParameterListopt ')' | 1674 // 'function' '*' Identifier '(' FormalParameterListopt ')' |
1674 // '{' FunctionBody '}' | 1675 // '{' FunctionBody '}' |
1675 Expect(Token::FUNCTION, CHECK_OK); | 1676 Expect(Token::FUNCTION, CHECK_OK); |
1676 int pos = position(); | 1677 int pos = position(); |
1677 bool is_generator = allow_generators() && Check(Token::MUL); | 1678 bool is_generator = allow_generators() && Check(Token::MUL); |
1678 bool is_strict_reserved = false; | 1679 bool is_strict_reserved = false; |
1679 Handle<String> name = ParseIdentifierOrStrictReservedWord( | 1680 Handle<String> name = ParseIdentifierOrStrictReservedWord( |
1680 &is_strict_reserved, CHECK_OK); | 1681 &is_strict_reserved, CHECK_OK); |
1681 FunctionLiteral* fun = ParseFunctionLiteral(name, | 1682 FunctionLiteral* fun = ParseFunctionLiteral(name, |
| 1683 scanner().location(), |
1682 is_strict_reserved, | 1684 is_strict_reserved, |
1683 is_generator, | 1685 is_generator, |
1684 pos, | 1686 pos, |
1685 FunctionLiteral::DECLARATION, | 1687 FunctionLiteral::DECLARATION, |
1686 CHECK_OK); | 1688 CHECK_OK); |
1687 // Even if we're not at the top-level of the global or a function | 1689 // Even if we're not at the top-level of the global or a function |
1688 // scope, we treat it as such and introduce the function with its | 1690 // scope, we treat it as such and introduce the function with its |
1689 // initial value upon entering the corresponding scope. | 1691 // initial value upon entering the corresponding scope. |
1690 // In extended mode, a function behaves as a lexical binding, except in the | 1692 // In extended mode, a function behaves as a lexical binding, except in the |
1691 // global scope. | 1693 // global scope. |
(...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3244 // error here but for compatibility with JSC we choose to report the | 3246 // error here but for compatibility with JSC we choose to report the |
3245 // error at runtime. | 3247 // error at runtime. |
3246 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 3248 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
3247 Handle<String> message = | 3249 Handle<String> message = |
3248 isolate()->factory()->invalid_lhs_in_postfix_op_string(); | 3250 isolate()->factory()->invalid_lhs_in_postfix_op_string(); |
3249 expression = NewThrowReferenceError(message); | 3251 expression = NewThrowReferenceError(message); |
3250 } | 3252 } |
3251 | 3253 |
3252 if (!top_scope_->is_classic_mode()) { | 3254 if (!top_scope_->is_classic_mode()) { |
3253 // Postfix expression operand in strict mode may not be eval or arguments. | 3255 // Postfix expression operand in strict mode may not be eval or arguments. |
3254 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); | 3256 CheckStrictModeLValue(expression, "strict_lhs_postfix", CHECK_OK); |
3255 } | 3257 } |
3256 MarkAsLValue(expression); | 3258 MarkAsLValue(expression); |
3257 | 3259 |
3258 Token::Value next = Next(); | 3260 Token::Value next = Next(); |
3259 expression = | 3261 expression = |
3260 factory()->NewCountOperation(next, | 3262 factory()->NewCountOperation(next, |
3261 false /* postfix */, | 3263 false /* postfix */, |
3262 expression, | 3264 expression, |
3263 position()); | 3265 position()); |
3264 } | 3266 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3393 // ('[' Expression ']' | '.' Identifier | Arguments)* | 3395 // ('[' Expression ']' | '.' Identifier | Arguments)* |
3394 | 3396 |
3395 // Parse the initial primary or function expression. | 3397 // Parse the initial primary or function expression. |
3396 Expression* result = NULL; | 3398 Expression* result = NULL; |
3397 if (peek() == Token::FUNCTION) { | 3399 if (peek() == Token::FUNCTION) { |
3398 Expect(Token::FUNCTION, CHECK_OK); | 3400 Expect(Token::FUNCTION, CHECK_OK); |
3399 int function_token_position = position(); | 3401 int function_token_position = position(); |
3400 bool is_generator = allow_generators() && Check(Token::MUL); | 3402 bool is_generator = allow_generators() && Check(Token::MUL); |
3401 Handle<String> name; | 3403 Handle<String> name; |
3402 bool is_strict_reserved_name = false; | 3404 bool is_strict_reserved_name = false; |
| 3405 Scanner::Location function_name_location = Scanner::Location::invalid(); |
3403 if (peek_any_identifier()) { | 3406 if (peek_any_identifier()) { |
3404 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, | 3407 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, |
3405 CHECK_OK); | 3408 CHECK_OK); |
| 3409 function_name_location = scanner().location(); |
3406 } | 3410 } |
3407 FunctionLiteral::FunctionType function_type = name.is_null() | 3411 FunctionLiteral::FunctionType function_type = name.is_null() |
3408 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 3412 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
3409 : FunctionLiteral::NAMED_EXPRESSION; | 3413 : FunctionLiteral::NAMED_EXPRESSION; |
3410 result = ParseFunctionLiteral(name, | 3414 result = ParseFunctionLiteral(name, |
| 3415 function_name_location, |
3411 is_strict_reserved_name, | 3416 is_strict_reserved_name, |
3412 is_generator, | 3417 is_generator, |
3413 function_token_position, | 3418 function_token_position, |
3414 function_type, | 3419 function_type, |
3415 CHECK_OK); | 3420 CHECK_OK); |
3416 } else { | 3421 } else { |
3417 result = ParsePrimaryExpression(CHECK_OK); | 3422 result = ParsePrimaryExpression(CHECK_OK); |
3418 } | 3423 } |
3419 | 3424 |
3420 while (true) { | 3425 while (true) { |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3757 return NULL; | 3762 return NULL; |
3758 } | 3763 } |
3759 // Validate the property. | 3764 // Validate the property. |
3760 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty; | 3765 PropertyKind type = is_getter ? kGetterProperty : kSetterProperty; |
3761 checker.CheckProperty(next, type, CHECK_OK); | 3766 checker.CheckProperty(next, type, CHECK_OK); |
3762 Handle<String> name = is_keyword | 3767 Handle<String> name = is_keyword |
3763 ? isolate_->factory()->InternalizeUtf8String(Token::String(next)) | 3768 ? isolate_->factory()->InternalizeUtf8String(Token::String(next)) |
3764 : GetSymbol(); | 3769 : GetSymbol(); |
3765 FunctionLiteral* value = | 3770 FunctionLiteral* value = |
3766 ParseFunctionLiteral(name, | 3771 ParseFunctionLiteral(name, |
| 3772 scanner().location(), |
3767 false, // reserved words are allowed here | 3773 false, // reserved words are allowed here |
3768 false, // not a generator | 3774 false, // not a generator |
3769 RelocInfo::kNoPosition, | 3775 RelocInfo::kNoPosition, |
3770 FunctionLiteral::ANONYMOUS_EXPRESSION, | 3776 FunctionLiteral::ANONYMOUS_EXPRESSION, |
3771 CHECK_OK); | 3777 CHECK_OK); |
3772 // Allow any number of parameters for compatibilty with JSC. | 3778 // Allow any number of parameters for compatibilty with JSC. |
3773 // Specification only allows zero parameters for get and one for set. | 3779 // Specification only allows zero parameters for get and one for set. |
3774 ObjectLiteral::Property* property = | 3780 ObjectLiteral::Property* property = |
3775 factory()->NewObjectLiteralProperty(is_getter, value, next_pos); | 3781 factory()->NewObjectLiteralProperty(is_getter, value, next_pos); |
3776 if (ObjectLiteral::IsBoilerplateProperty(property)) { | 3782 if (ObjectLiteral::IsBoilerplateProperty(property)) { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4003 int properties_; | 4009 int properties_; |
4004 LanguageMode mode_; | 4010 LanguageMode mode_; |
4005 // For error messages. | 4011 // For error messages. |
4006 const char* message_; | 4012 const char* message_; |
4007 const char* argument_opt_; | 4013 const char* argument_opt_; |
4008 }; | 4014 }; |
4009 | 4015 |
4010 | 4016 |
4011 FunctionLiteral* Parser::ParseFunctionLiteral( | 4017 FunctionLiteral* Parser::ParseFunctionLiteral( |
4012 Handle<String> function_name, | 4018 Handle<String> function_name, |
| 4019 Scanner::Location function_name_location, |
4013 bool name_is_strict_reserved, | 4020 bool name_is_strict_reserved, |
4014 bool is_generator, | 4021 bool is_generator, |
4015 int function_token_pos, | 4022 int function_token_pos, |
4016 FunctionLiteral::FunctionType function_type, | 4023 FunctionLiteral::FunctionType function_type, |
4017 bool* ok) { | 4024 bool* ok) { |
4018 // Function :: | 4025 // Function :: |
4019 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 4026 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
4020 | 4027 |
4021 int pos = function_token_pos == RelocInfo::kNoPosition | 4028 int pos = function_token_pos == RelocInfo::kNoPosition |
4022 ? peek_position() : function_token_pos; | 4029 ? peek_position() : function_token_pos; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4288 expected_property_count = function_state.expected_property_count(); | 4295 expected_property_count = function_state.expected_property_count(); |
4289 handler_count = function_state.handler_count(); | 4296 handler_count = function_state.handler_count(); |
4290 | 4297 |
4291 Expect(Token::RBRACE, CHECK_OK); | 4298 Expect(Token::RBRACE, CHECK_OK); |
4292 scope->set_end_position(scanner().location().end_pos); | 4299 scope->set_end_position(scanner().location().end_pos); |
4293 } | 4300 } |
4294 | 4301 |
4295 // Validate strict mode. | 4302 // Validate strict mode. |
4296 if (!top_scope_->is_classic_mode()) { | 4303 if (!top_scope_->is_classic_mode()) { |
4297 if (IsEvalOrArguments(function_name)) { | 4304 if (IsEvalOrArguments(function_name)) { |
4298 int start_pos = scope->start_position(); | 4305 ReportMessageAt(function_name_location, |
4299 int position = function_token_pos != RelocInfo::kNoPosition | 4306 "strict_function_name", |
4300 ? function_token_pos : (start_pos > 0 ? start_pos - 1 : start_pos); | 4307 Vector<const char*>::empty()); |
4301 Scanner::Location location = Scanner::Location(position, start_pos); | |
4302 ReportMessageAt(location, | |
4303 "strict_function_name", Vector<const char*>::empty()); | |
4304 *ok = false; | 4308 *ok = false; |
4305 return NULL; | 4309 return NULL; |
4306 } | 4310 } |
4307 if (name_loc.IsValid()) { | 4311 if (name_loc.IsValid()) { |
4308 ReportMessageAt(name_loc, "strict_param_name", | 4312 ReportMessageAt(name_loc, "strict_param_name", |
4309 Vector<const char*>::empty()); | 4313 Vector<const char*>::empty()); |
4310 *ok = false; | 4314 *ok = false; |
4311 return NULL; | 4315 return NULL; |
4312 } | 4316 } |
4313 if (dupe_loc.IsValid()) { | 4317 if (dupe_loc.IsValid()) { |
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5684 ASSERT(info()->isolate()->has_pending_exception()); | 5688 ASSERT(info()->isolate()->has_pending_exception()); |
5685 } else { | 5689 } else { |
5686 result = ParseProgram(); | 5690 result = ParseProgram(); |
5687 } | 5691 } |
5688 } | 5692 } |
5689 info()->SetFunction(result); | 5693 info()->SetFunction(result); |
5690 return (result != NULL); | 5694 return (result != NULL); |
5691 } | 5695 } |
5692 | 5696 |
5693 } } // namespace v8::internal | 5697 } } // namespace v8::internal |
OLD | NEW |