Chromium Code Reviews| Index: src/parsing/pattern-rewriter.cc |
| diff --git a/src/parsing/pattern-rewriter.cc b/src/parsing/pattern-rewriter.cc |
| index 91d75495469b9f966641eec51f772d016a056dc6..808c0c096458cf7aa0f0c8a0809b5abe7e4e3423 100644 |
| --- a/src/parsing/pattern-rewriter.cc |
| +++ b/src/parsing/pattern-rewriter.cc |
| @@ -677,9 +677,29 @@ void Parser::PatternRewriter::VisitAssignment(Assignment* node) { |
| RelocInfo::kNoPosition); |
| } |
| + // Two cases for scope rewriting the scope of default parameters: |
| + // - Eagerly parsed arrow functions are initially parsed as having |
| + // initializers in the enclosing scope, but when the arrow is encountered, |
| + // need to be in the scope of the function. |
| + // - When an extra declaration scope needs to be inserted to account for |
| + // a sloppy eval in a default parameter or function body, the initializer |
| + // needs to be in that new inner scope which was added after initial |
| + // parsing. |
| + // Each of these cases can be handled by rewriting the contents of the |
| + // initializer to the current scope. The source scope is typically the outer |
| + // scope when one case occurs; when both cases occur, both scopes need to |
| + // be included as the outer scope. (Both rewritings still need to be done |
| + // to account for lazily parsed arrow functions which hit the second case.) |
| + // TODO(littledan): Remove the outer_scope parameter of |
|
adamk
2016/06/22 17:55:39
How will removing this work? Is the idea to always
|
| + // RewriteParameterInitializerScope |
| if (IsBindingContext() && |
| descriptor_->declaration_kind == DeclarationDescriptor::PARAMETER && |
| - scope()->is_arrow_scope()) { |
| + (scope()->is_arrow_scope() || scope()->is_block_scope())) { |
| + if (scope()->outer_scope()->is_arrow_scope() && scope()->is_block_scope()) { |
| + RewriteParameterInitializerScope(parser_->stack_limit(), initializer, |
| + scope()->outer_scope()->outer_scope(), |
| + scope()); |
| + } |
| RewriteParameterInitializerScope(parser_->stack_limit(), initializer, |
| scope()->outer_scope(), scope()); |
| } |