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

Side by Side Diff: src/parsing/parser.cc

Issue 2362463003: Declare the arguments object before creating the function var, to make sure it masks it (Closed)
Patch Set: Add comment Created 4 years, 3 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
« no previous file with comments | « src/ast/scopes.cc ('k') | test/mjsunit/regress/regress-649067.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast-expression-rewriter.h" 10 #include "src/ast/ast-expression-rewriter.h"
(...skipping 2824 matching lines...) Expand 10 before | Expand all | Expand 10 after
2835 expected_property_count = function_state.expected_property_count(); 2835 expected_property_count = function_state.expected_property_count();
2836 if (use_temp_zone) { 2836 if (use_temp_zone) {
2837 // If the preconditions are correct the function body should never be 2837 // If the preconditions are correct the function body should never be
2838 // accessed, but do this anyway for better behaviour if they're wrong. 2838 // accessed, but do this anyway for better behaviour if they're wrong.
2839 body = nullptr; 2839 body = nullptr;
2840 } 2840 }
2841 } 2841 }
2842 2842
2843 // Parsing the body may change the language mode in our scope. 2843 // Parsing the body may change the language mode in our scope.
2844 language_mode = scope->language_mode(); 2844 language_mode = scope->language_mode();
2845 scope->DeclareArguments(ast_value_factory());
2846 if (main_scope != scope) {
2847 main_scope->DeclareArguments(ast_value_factory());
2848 }
2849 2845
2850 // Validate name and parameter names. We can do this only after parsing the 2846 // Validate name and parameter names. We can do this only after parsing the
2851 // function, since the function can declare itself strict. 2847 // function, since the function can declare itself strict.
2852 CheckFunctionName(language_mode, function_name, function_name_validity, 2848 CheckFunctionName(language_mode, function_name, function_name_validity,
2853 function_name_location, CHECK_OK); 2849 function_name_location, CHECK_OK);
2854 const bool allow_duplicate_parameters = 2850 const bool allow_duplicate_parameters =
2855 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind); 2851 is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind);
2856 ValidateFormalParameters(language_mode, allow_duplicate_parameters, 2852 ValidateFormalParameters(language_mode, allow_duplicate_parameters,
2857 CHECK_OK); 2853 CHECK_OK);
2858 2854
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
3427 3423
3428 result->Add(init_block, zone()); 3424 result->Add(init_block, zone());
3429 result->Add(inner_block, zone()); 3425 result->Add(inner_block, zone());
3430 } else { 3426 } else {
3431 DCHECK_EQ(inner_scope, function_scope); 3427 DCHECK_EQ(inner_scope, function_scope);
3432 if (is_sloppy(function_scope->language_mode())) { 3428 if (is_sloppy(function_scope->language_mode())) {
3433 InsertSloppyBlockFunctionVarBindings(function_scope); 3429 InsertSloppyBlockFunctionVarBindings(function_scope);
3434 } 3430 }
3435 } 3431 }
3436 3432
3433 if (!IsArrowFunction(kind)) {
3434 // Declare arguments after parsing the function since lexical 'arguments'
3435 // masks the arguments object. Declare arguments before declaring the
3436 // function var since the arguments object masks 'function arguments'.
3437 function_scope->DeclareArguments(ast_value_factory());
3438 }
3439
3437 if (function_type == FunctionLiteral::kNamedExpression) { 3440 if (function_type == FunctionLiteral::kNamedExpression) {
3438 Statement* statement; 3441 Statement* statement;
3439 if (function_scope->LookupLocal(function_name) == nullptr) { 3442 if (function_scope->LookupLocal(function_name) == nullptr) {
3440 // Now that we know the language mode, we can create the const assignment 3443 // Now that we know the language mode, we can create the const assignment
3441 // in the previously reserved spot. 3444 // in the previously reserved spot.
3442 DCHECK_EQ(function_scope, scope()); 3445 DCHECK_EQ(function_scope, scope());
3443 Variable* fvar = function_scope->DeclareFunctionVar(function_name); 3446 Variable* fvar = function_scope->DeclareFunctionVar(function_name);
3444 VariableProxy* fproxy = factory()->NewVariableProxy(fvar); 3447 VariableProxy* fproxy = factory()->NewVariableProxy(fvar);
3445 statement = factory()->NewExpressionStatement( 3448 statement = factory()->NewExpressionStatement(
3446 factory()->NewAssignment(Token::INIT, fproxy, 3449 factory()->NewAssignment(Token::INIT, fproxy,
(...skipping 2156 matching lines...) Expand 10 before | Expand all | Expand 10 after
5603 5606
5604 return final_loop; 5607 return final_loop;
5605 } 5608 }
5606 5609
5607 #undef CHECK_OK 5610 #undef CHECK_OK
5608 #undef CHECK_OK_VOID 5611 #undef CHECK_OK_VOID
5609 #undef CHECK_FAILED 5612 #undef CHECK_FAILED
5610 5613
5611 } // namespace internal 5614 } // namespace internal
5612 } // namespace v8 5615 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.cc ('k') | test/mjsunit/regress/regress-649067.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698