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

Side by Side Diff: src/parser.cc

Issue 6335013: Strict mode eval/arguments LHS. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR Feedback Created 9 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/mjsunit/strict-mode.js » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 2274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 2285
2286 // Signal a reference error if the expression is an invalid left-hand 2286 // Signal a reference error if the expression is an invalid left-hand
2287 // side expression. We could report this as a syntax error here but 2287 // side expression. We could report this as a syntax error here but
2288 // for compatibility with JSC we choose to report the error at 2288 // for compatibility with JSC we choose to report the error at
2289 // runtime. 2289 // runtime.
2290 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2290 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2291 Handle<String> type = Factory::invalid_lhs_in_assignment_symbol(); 2291 Handle<String> type = Factory::invalid_lhs_in_assignment_symbol();
2292 expression = NewThrowReferenceError(type); 2292 expression = NewThrowReferenceError(type);
2293 } 2293 }
2294 2294
2295 if (temp_scope_->StrictMode()) {
2296 // Assignment to eval or arguments is disallowed in strict mode.
2297 CheckStrictModeLValue(expression, "strict_lhs_assignment", CHECK_OK);
2298 }
2299
2295 Token::Value op = Next(); // Get assignment operator. 2300 Token::Value op = Next(); // Get assignment operator.
2296 int pos = scanner().location().beg_pos; 2301 int pos = scanner().location().beg_pos;
2297 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2302 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2298 2303
2299 // TODO(1231235): We try to estimate the set of properties set by 2304 // TODO(1231235): We try to estimate the set of properties set by
2300 // constructors. We define a new property whenever there is an 2305 // constructors. We define a new property whenever there is an
2301 // assignment to a property of 'this'. We should probably only add 2306 // assignment to a property of 'this'. We should probably only add
2302 // properties if we haven't seen them before. Otherwise we'll 2307 // properties if we haven't seen them before. Otherwise we'll
2303 // probably overestimate the number of properties. 2308 // probably overestimate the number of properties.
2304 Property* property = expression ? expression->AsProperty() : NULL; 2309 Property* property = expression ? expression->AsProperty() : NULL;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2511 op = Next(); 2516 op = Next();
2512 Expression* expression = ParseUnaryExpression(CHECK_OK); 2517 Expression* expression = ParseUnaryExpression(CHECK_OK);
2513 // Signal a reference error if the expression is an invalid 2518 // Signal a reference error if the expression is an invalid
2514 // left-hand side expression. We could report this as a syntax 2519 // left-hand side expression. We could report this as a syntax
2515 // error here but for compatibility with JSC we choose to report the 2520 // error here but for compatibility with JSC we choose to report the
2516 // error at runtime. 2521 // error at runtime.
2517 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2522 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2518 Handle<String> type = Factory::invalid_lhs_in_prefix_op_symbol(); 2523 Handle<String> type = Factory::invalid_lhs_in_prefix_op_symbol();
2519 expression = NewThrowReferenceError(type); 2524 expression = NewThrowReferenceError(type);
2520 } 2525 }
2526
2527 if (temp_scope_->StrictMode()) {
2528 // Prefix expression operand in strict mode may not be eval or arguments.
2529 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK);
2530 }
2531
2521 int position = scanner().location().beg_pos; 2532 int position = scanner().location().beg_pos;
2522 IncrementOperation* increment = new IncrementOperation(op, expression); 2533 IncrementOperation* increment = new IncrementOperation(op, expression);
2523 return new CountOperation(true /* prefix */, increment, position); 2534 return new CountOperation(true /* prefix */, increment, position);
2524 2535
2525 } else { 2536 } else {
2526 return ParsePostfixExpression(ok); 2537 return ParsePostfixExpression(ok);
2527 } 2538 }
2528 } 2539 }
2529 2540
2530 2541
2531 Expression* Parser::ParsePostfixExpression(bool* ok) { 2542 Expression* Parser::ParsePostfixExpression(bool* ok) {
2532 // PostfixExpression :: 2543 // PostfixExpression ::
2533 // LeftHandSideExpression ('++' | '--')? 2544 // LeftHandSideExpression ('++' | '--')?
2534 2545
2535 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); 2546 Expression* expression = ParseLeftHandSideExpression(CHECK_OK);
2536 if (!scanner().has_line_terminator_before_next() && 2547 if (!scanner().has_line_terminator_before_next() &&
2537 Token::IsCountOp(peek())) { 2548 Token::IsCountOp(peek())) {
2538 // Signal a reference error if the expression is an invalid 2549 // Signal a reference error if the expression is an invalid
2539 // left-hand side expression. We could report this as a syntax 2550 // left-hand side expression. We could report this as a syntax
2540 // error here but for compatibility with JSC we choose to report the 2551 // error here but for compatibility with JSC we choose to report the
2541 // error at runtime. 2552 // error at runtime.
2542 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2553 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2543 Handle<String> type = Factory::invalid_lhs_in_postfix_op_symbol(); 2554 Handle<String> type = Factory::invalid_lhs_in_postfix_op_symbol();
2544 expression = NewThrowReferenceError(type); 2555 expression = NewThrowReferenceError(type);
2545 } 2556 }
2557
2558 if (temp_scope_->StrictMode()) {
2559 // Postfix expression operand in strict mode may not be eval or arguments.
2560 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK);
2561 }
2562
2546 Token::Value next = Next(); 2563 Token::Value next = Next();
2547 int position = scanner().location().beg_pos; 2564 int position = scanner().location().beg_pos;
2548 IncrementOperation* increment = new IncrementOperation(next, expression); 2565 IncrementOperation* increment = new IncrementOperation(next, expression);
2549 expression = new CountOperation(false /* postfix */, increment, position); 2566 expression = new CountOperation(false /* postfix */, increment, position);
2550 } 2567 }
2551 return expression; 2568 return expression;
2552 } 2569 }
2553 2570
2554 2571
2555 Expression* Parser::ParseLeftHandSideExpression(bool* ok) { 2572 Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
3685 Handle<String> Parser::ParseIdentifierName(bool* ok) { 3702 Handle<String> Parser::ParseIdentifierName(bool* ok) {
3686 Token::Value next = Next(); 3703 Token::Value next = Next();
3687 if (next != Token::IDENTIFIER && !Token::IsKeyword(next)) { 3704 if (next != Token::IDENTIFIER && !Token::IsKeyword(next)) {
3688 ReportUnexpectedToken(next); 3705 ReportUnexpectedToken(next);
3689 *ok = false; 3706 *ok = false;
3690 return Handle<String>(); 3707 return Handle<String>();
3691 } 3708 }
3692 return GetSymbol(ok); 3709 return GetSymbol(ok);
3693 } 3710 }
3694 3711
3712
3713 // Checks LHS expression for assignment and prefix/postfix increment/decrement
3714 // in strict mode.
3715 void Parser::CheckStrictModeLValue(Expression* expression,
3716 const char* error,
3717 bool* ok) {
3718 ASSERT(temp_scope_->StrictMode());
3719 VariableProxy* lhs = expression != NULL
3720 ? expression->AsVariableProxy()
3721 : NULL;
3722
3723 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) {
3724 ReportMessage(error, Vector<const char*>::empty());
3725 *ok = false;
3726 }
3727 }
3728
3729
3695 // Checks whether octal literal last seen is between beg_pos and end_pos. 3730 // Checks whether octal literal last seen is between beg_pos and end_pos.
3696 // If so, reports an error. 3731 // If so, reports an error.
3697 void Parser::CheckOctalLiteral(int beg_pos, int end_pos, bool* ok) { 3732 void Parser::CheckOctalLiteral(int beg_pos, int end_pos, bool* ok) {
3698 int octal = scanner().octal_position(); 3733 int octal = scanner().octal_position();
3699 if (beg_pos <= octal && octal <= end_pos) { 3734 if (beg_pos <= octal && octal <= end_pos) {
3700 ReportMessageAt(Scanner::Location(octal, octal + 1), "strict_octal_literal", 3735 ReportMessageAt(Scanner::Location(octal, octal + 1), "strict_octal_literal",
3701 Vector<const char*>::empty()); 3736 Vector<const char*>::empty());
3702 scanner().clear_octal_position(); 3737 scanner().clear_octal_position();
3703 *ok = false; 3738 *ok = false;
3704 } 3739 }
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after
4992 Handle<String> source = Handle<String>(String::cast(script->source())); 5027 Handle<String> source = Handle<String>(String::cast(script->source()));
4993 result = parser.ParseProgram(source, info->is_global()); 5028 result = parser.ParseProgram(source, info->is_global());
4994 } 5029 }
4995 } 5030 }
4996 5031
4997 info->SetFunction(result); 5032 info->SetFunction(result);
4998 return (result != NULL); 5033 return (result != NULL);
4999 } 5034 }
5000 5035
5001 } } // namespace v8::internal 5036 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | test/mjsunit/strict-mode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698