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

Side by Side Diff: src/parsing/pattern-rewriter.cc

Issue 2081323006: Revert of Rewrite scopes of non-simple default arguments (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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/parsing/parser.cc ('k') | test/mjsunit/regress/regress-616386.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/ast/ast.h" 5 #include "src/ast/ast.h"
6 #include "src/messages.h" 6 #include "src/messages.h"
7 #include "src/parsing/parameter-initializer-rewriter.h" 7 #include "src/parsing/parameter-initializer-rewriter.h"
8 #include "src/parsing/parser.h" 8 #include "src/parsing/parser.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 if (IsInitializerContext()) { 670 if (IsInitializerContext()) {
671 Expression* is_undefined = factory()->NewCompareOperation( 671 Expression* is_undefined = factory()->NewCompareOperation(
672 Token::EQ_STRICT, factory()->NewVariableProxy(temp), 672 Token::EQ_STRICT, factory()->NewVariableProxy(temp),
673 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), 673 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition),
674 RelocInfo::kNoPosition); 674 RelocInfo::kNoPosition);
675 value = factory()->NewConditional(is_undefined, initializer, 675 value = factory()->NewConditional(is_undefined, initializer,
676 factory()->NewVariableProxy(temp), 676 factory()->NewVariableProxy(temp),
677 RelocInfo::kNoPosition); 677 RelocInfo::kNoPosition);
678 } 678 }
679 679
680 // Two cases for scope rewriting the scope of default parameters:
681 // - Eagerly parsed arrow functions are initially parsed as having
682 // initializers in the enclosing scope, but when the arrow is encountered,
683 // need to be in the scope of the function.
684 // - When an extra declaration scope needs to be inserted to account for
685 // a sloppy eval in a default parameter or function body, the initializer
686 // needs to be in that new inner scope which was added after initial
687 // parsing.
688 // Each of these cases can be handled by rewriting the contents of the
689 // initializer to the current scope. The source scope is typically the outer
690 // scope when one case occurs; when both cases occur, both scopes need to
691 // be included as the outer scope. (Both rewritings still need to be done
692 // to account for lazily parsed arrow functions which hit the second case.)
693 // TODO(littledan): Remove the outer_scope parameter of
694 // RewriteParameterInitializerScope
695 if (IsBindingContext() && 680 if (IsBindingContext() &&
696 descriptor_->declaration_kind == DeclarationDescriptor::PARAMETER && 681 descriptor_->declaration_kind == DeclarationDescriptor::PARAMETER &&
697 (scope()->is_arrow_scope() || scope()->is_block_scope())) { 682 scope()->is_arrow_scope()) {
698 if (scope()->outer_scope()->is_arrow_scope() && scope()->is_block_scope()) {
699 RewriteParameterInitializerScope(parser_->stack_limit(), initializer,
700 scope()->outer_scope()->outer_scope(),
701 scope());
702 }
703 RewriteParameterInitializerScope(parser_->stack_limit(), initializer, 683 RewriteParameterInitializerScope(parser_->stack_limit(), initializer,
704 scope()->outer_scope(), scope()); 684 scope()->outer_scope(), scope());
705 } 685 }
706 686
707 PatternContext old_context = SetAssignmentContextIfNeeded(initializer); 687 PatternContext old_context = SetAssignmentContextIfNeeded(initializer);
708 RecurseIntoSubpattern(node->target(), value); 688 RecurseIntoSubpattern(node->target(), value);
709 set_context(old_context); 689 set_context(old_context);
710 } 690 }
711 691
712 692
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 NOT_A_PATTERN(TryFinallyStatement) 755 NOT_A_PATTERN(TryFinallyStatement)
776 NOT_A_PATTERN(UnaryOperation) 756 NOT_A_PATTERN(UnaryOperation)
777 NOT_A_PATTERN(VariableDeclaration) 757 NOT_A_PATTERN(VariableDeclaration)
778 NOT_A_PATTERN(WhileStatement) 758 NOT_A_PATTERN(WhileStatement)
779 NOT_A_PATTERN(WithStatement) 759 NOT_A_PATTERN(WithStatement)
780 NOT_A_PATTERN(Yield) 760 NOT_A_PATTERN(Yield)
781 761
782 #undef NOT_A_PATTERN 762 #undef NOT_A_PATTERN
783 } // namespace internal 763 } // namespace internal
784 } // namespace v8 764 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | test/mjsunit/regress/regress-616386.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698