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

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

Issue 2171703004: Rescope arrow-function parameter lists by moving the delta to the parameter scope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove unnecessary DCHECK Created 4 years, 4 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-base.h ('k') | src/parsing/preparser.h » ('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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 Expression* expr = factory()->NewDoExpression(block_, temp, pos); 373 Expression* expr = factory()->NewDoExpression(block_, temp, pos);
374 node->Rewrite(expr); 374 node->Rewrite(expr);
375 block_ = old_block; 375 block_ = old_block;
376 if (block_) { 376 if (block_) {
377 block_->statements()->Add(factory()->NewExpressionStatement(expr, pos), 377 block_->statements()->Add(factory()->NewExpressionStatement(expr, pos),
378 zone()); 378 zone());
379 } 379 }
380 return set_context(old_context); 380 return set_context(old_context);
381 } 381 }
382 382
383 // Two cases for scope rewriting the scope of default parameters: 383 // When an extra declaration scope needs to be inserted to account for
384 // - Eagerly parsed arrow functions are initially parsed as having 384 // a sloppy eval in a default parameter or function body, the expressions
385 // expressions in the enclosing scope, but when the arrow is encountered, 385 // needs to be in that new inner scope which was added after initial
386 // need to be in the scope of the function. 386 // parsing.
387 // - When an extra declaration scope needs to be inserted to account for
388 // a sloppy eval in a default parameter or function body, the expressions
389 // needs to be in that new inner scope which was added after initial
390 // parsing.
391 // Each of these cases can be handled by rewriting the contents of the
392 // expression to the current scope. The source scope is typically the outer
393 // scope when one case occurs; when both cases occur, both scopes need to
394 // be included as the outer scope. (Both rewritings still need to be done
395 // to account for lazily parsed arrow functions which hit the second case.)
396 // TODO(littledan): Remove the outer_scope parameter of
397 // RewriteParameterInitializerScope
398 void Parser::PatternRewriter::RewriteParameterScopes(Expression* expr) { 387 void Parser::PatternRewriter::RewriteParameterScopes(Expression* expr) {
399 if (!IsBindingContext()) return; 388 if (!IsBindingContext()) return;
400 if (descriptor_->declaration_kind != DeclarationDescriptor::PARAMETER) return; 389 if (descriptor_->declaration_kind != DeclarationDescriptor::PARAMETER) return;
401 if (!scope()->is_arrow_scope() && !scope()->is_block_scope()) return; 390 if (!scope()->is_block_scope()) return;
402 391
403 // Either this scope is an arrow scope or a declaration block scope.
404 DCHECK(scope()->is_declaration_scope()); 392 DCHECK(scope()->is_declaration_scope());
393 DCHECK(scope()->outer_scope()->is_function_scope());
394 DCHECK(scope()->calls_sloppy_eval());
405 395
406 if (scope()->outer_scope()->is_arrow_scope() && scope()->is_block_scope()) { 396 ReparentParameterExpressionScope(parser_->stack_limit(), expr, scope());
407 RewriteParameterInitializerScope(parser_->stack_limit(), expr,
408 scope()->outer_scope()->outer_scope(),
409 scope());
410 }
411 RewriteParameterInitializerScope(parser_->stack_limit(), expr,
412 scope()->outer_scope(), scope());
413 } 397 }
414 398
415 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern, 399 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern,
416 Variable** temp_var) { 400 Variable** temp_var) {
417 auto temp = *temp_var = CreateTempVar(current_value_); 401 auto temp = *temp_var = CreateTempVar(current_value_);
418 402
419 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone()); 403 block_->statements()->Add(parser_->BuildAssertIsCoercible(temp), zone());
420 404
421 for (ObjectLiteralProperty* property : *pattern->properties()) { 405 for (ObjectLiteralProperty* property : *pattern->properties()) {
422 PatternContext context = SetInitializerContextIfNeeded(property->value()); 406 PatternContext context = SetInitializerContextIfNeeded(property->value());
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 NOT_A_PATTERN(TryFinallyStatement) 758 NOT_A_PATTERN(TryFinallyStatement)
775 NOT_A_PATTERN(UnaryOperation) 759 NOT_A_PATTERN(UnaryOperation)
776 NOT_A_PATTERN(VariableDeclaration) 760 NOT_A_PATTERN(VariableDeclaration)
777 NOT_A_PATTERN(WhileStatement) 761 NOT_A_PATTERN(WhileStatement)
778 NOT_A_PATTERN(WithStatement) 762 NOT_A_PATTERN(WithStatement)
779 NOT_A_PATTERN(Yield) 763 NOT_A_PATTERN(Yield)
780 764
781 #undef NOT_A_PATTERN 765 #undef NOT_A_PATTERN
782 } // namespace internal 766 } // namespace internal
783 } // namespace v8 767 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698