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

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

Issue 2086353003: Reland of write 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
680 if (IsBindingContext() && 695 if (IsBindingContext() &&
681 descriptor_->declaration_kind == DeclarationDescriptor::PARAMETER && 696 descriptor_->declaration_kind == DeclarationDescriptor::PARAMETER &&
682 scope()->is_arrow_scope()) { 697 (scope()->is_arrow_scope() || scope()->is_block_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 }
683 RewriteParameterInitializerScope(parser_->stack_limit(), initializer, 703 RewriteParameterInitializerScope(parser_->stack_limit(), initializer,
684 scope()->outer_scope(), scope()); 704 scope()->outer_scope(), scope());
685 } 705 }
686 706
687 PatternContext old_context = SetAssignmentContextIfNeeded(initializer); 707 PatternContext old_context = SetAssignmentContextIfNeeded(initializer);
688 RecurseIntoSubpattern(node->target(), value); 708 RecurseIntoSubpattern(node->target(), value);
689 set_context(old_context); 709 set_context(old_context);
690 } 710 }
691 711
692 712
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 NOT_A_PATTERN(TryFinallyStatement) 775 NOT_A_PATTERN(TryFinallyStatement)
756 NOT_A_PATTERN(UnaryOperation) 776 NOT_A_PATTERN(UnaryOperation)
757 NOT_A_PATTERN(VariableDeclaration) 777 NOT_A_PATTERN(VariableDeclaration)
758 NOT_A_PATTERN(WhileStatement) 778 NOT_A_PATTERN(WhileStatement)
759 NOT_A_PATTERN(WithStatement) 779 NOT_A_PATTERN(WithStatement)
760 NOT_A_PATTERN(Yield) 780 NOT_A_PATTERN(Yield)
761 781
762 #undef NOT_A_PATTERN 782 #undef NOT_A_PATTERN
763 } // namespace internal 783 } // namespace internal
764 } // namespace v8 784 } // 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