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

Side by Side Diff: src/parser.cc

Issue 8688007: Statically check for assignments to const in harmony mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month 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
OLDNEW
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 2671 matching lines...) Expand 10 before | Expand all | Expand 10 after
2682 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2682 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2683 Handle<String> type = 2683 Handle<String> type =
2684 isolate()->factory()->invalid_lhs_in_assignment_symbol(); 2684 isolate()->factory()->invalid_lhs_in_assignment_symbol();
2685 expression = NewThrowReferenceError(type); 2685 expression = NewThrowReferenceError(type);
2686 } 2686 }
2687 2687
2688 if (!top_scope_->is_classic_mode()) { 2688 if (!top_scope_->is_classic_mode()) {
2689 // Assignment to eval or arguments is disallowed in strict mode. 2689 // Assignment to eval or arguments is disallowed in strict mode.
2690 CheckStrictModeLValue(expression, "strict_lhs_assignment", CHECK_OK); 2690 CheckStrictModeLValue(expression, "strict_lhs_assignment", CHECK_OK);
2691 } 2691 }
2692 MarkAsUsedAsLValue(expression);
2692 2693
2693 Token::Value op = Next(); // Get assignment operator. 2694 Token::Value op = Next(); // Get assignment operator.
2694 int pos = scanner().location().beg_pos; 2695 int pos = scanner().location().beg_pos;
2695 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2696 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2696 2697
2697 // TODO(1231235): We try to estimate the set of properties set by 2698 // TODO(1231235): We try to estimate the set of properties set by
2698 // constructors. We define a new property whenever there is an 2699 // constructors. We define a new property whenever there is an
2699 // assignment to a property of 'this'. We should probably only add 2700 // assignment to a property of 'this'. We should probably only add
2700 // properties if we haven't seen them before. Otherwise we'll 2701 // properties if we haven't seen them before. Otherwise we'll
2701 // probably overestimate the number of properties. 2702 // probably overestimate the number of properties.
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2915 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2916 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2916 Handle<String> type = 2917 Handle<String> type =
2917 isolate()->factory()->invalid_lhs_in_prefix_op_symbol(); 2918 isolate()->factory()->invalid_lhs_in_prefix_op_symbol();
2918 expression = NewThrowReferenceError(type); 2919 expression = NewThrowReferenceError(type);
2919 } 2920 }
2920 2921
2921 if (!top_scope_->is_classic_mode()) { 2922 if (!top_scope_->is_classic_mode()) {
2922 // Prefix expression operand in strict mode may not be eval or arguments. 2923 // Prefix expression operand in strict mode may not be eval or arguments.
2923 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); 2924 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK);
2924 } 2925 }
2926 MarkAsUsedAsLValue(expression);
2925 2927
2926 int position = scanner().location().beg_pos; 2928 int position = scanner().location().beg_pos;
2927 return new(zone()) CountOperation(isolate(), 2929 return new(zone()) CountOperation(isolate(),
2928 op, 2930 op,
2929 true /* prefix */, 2931 true /* prefix */,
2930 expression, 2932 expression,
2931 position); 2933 position);
2932 2934
2933 } else { 2935 } else {
2934 return ParsePostfixExpression(ok); 2936 return ParsePostfixExpression(ok);
(...skipping 15 matching lines...) Expand all
2950 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2952 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2951 Handle<String> type = 2953 Handle<String> type =
2952 isolate()->factory()->invalid_lhs_in_postfix_op_symbol(); 2954 isolate()->factory()->invalid_lhs_in_postfix_op_symbol();
2953 expression = NewThrowReferenceError(type); 2955 expression = NewThrowReferenceError(type);
2954 } 2956 }
2955 2957
2956 if (!top_scope_->is_classic_mode()) { 2958 if (!top_scope_->is_classic_mode()) {
2957 // Postfix expression operand in strict mode may not be eval or arguments. 2959 // Postfix expression operand in strict mode may not be eval or arguments.
2958 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); 2960 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK);
2959 } 2961 }
2962 MarkAsUsedAsLValue(expression);
2960 2963
2961 Token::Value next = Next(); 2964 Token::Value next = Next();
2962 int position = scanner().location().beg_pos; 2965 int position = scanner().location().beg_pos;
2963 expression = 2966 expression =
2964 new(zone()) CountOperation(isolate(), 2967 new(zone()) CountOperation(isolate(),
2965 next, 2968 next,
2966 false /* postfix */, 2969 false /* postfix */,
2967 expression, 2970 expression,
2968 position); 2971 position);
2969 } 2972 }
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after
4308 next != Token::FUTURE_STRICT_RESERVED_WORD && 4311 next != Token::FUTURE_STRICT_RESERVED_WORD &&
4309 !Token::IsKeyword(next)) { 4312 !Token::IsKeyword(next)) {
4310 ReportUnexpectedToken(next); 4313 ReportUnexpectedToken(next);
4311 *ok = false; 4314 *ok = false;
4312 return Handle<String>(); 4315 return Handle<String>();
4313 } 4316 }
4314 return GetSymbol(ok); 4317 return GetSymbol(ok);
4315 } 4318 }
4316 4319
4317 4320
4321 void Parser::MarkAsUsedAsLValue(Expression* expression) {
4322 VariableProxy* lhs = expression != NULL
4323 ? expression->AsVariableProxy()
4324 : NULL;
4325
4326 if (lhs != NULL) lhs->MarkAsUsedAsLValue();
4327 }
4328
4329
4318 // Checks LHS expression for assignment and prefix/postfix increment/decrement 4330 // Checks LHS expression for assignment and prefix/postfix increment/decrement
4319 // in strict mode. 4331 // in strict mode.
4320 void Parser::CheckStrictModeLValue(Expression* expression, 4332 void Parser::CheckStrictModeLValue(Expression* expression,
4321 const char* error, 4333 const char* error,
4322 bool* ok) { 4334 bool* ok) {
4323 ASSERT(!top_scope_->is_classic_mode()); 4335 ASSERT(!top_scope_->is_classic_mode());
4324 VariableProxy* lhs = expression != NULL 4336 VariableProxy* lhs = expression != NULL
4325 ? expression->AsVariableProxy() 4337 ? expression->AsVariableProxy()
4326 : NULL; 4338 : NULL;
4327 4339
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
5480 ASSERT(info->isolate()->has_pending_exception()); 5492 ASSERT(info->isolate()->has_pending_exception());
5481 } else { 5493 } else {
5482 result = parser.ParseProgram(info); 5494 result = parser.ParseProgram(info);
5483 } 5495 }
5484 } 5496 }
5485 info->SetFunction(result); 5497 info->SetFunction(result);
5486 return (result != NULL); 5498 return (result != NULL);
5487 } 5499 }
5488 5500
5489 } } // namespace v8::internal 5501 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698