Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/parser.cc

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

Powered by Google App Engine
This is Rietveld 408576698