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

Side by Side Diff: src/parameter-initializer-rewriter.cc

Issue 1414283002: [es6] Fix scoping for default parameters in arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 5 years, 2 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/parameter-initializer-rewriter.h ('k') | src/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "src/parameter-initializer-rewriter.h"
8
9 #include "src/ast.h"
10 #include "src/ast-expression-visitor.h"
11 #include "src/scopes.h"
12
13 namespace v8 {
14 namespace internal {
15
16 namespace {
17
18
19 class Rewriter final : public AstExpressionVisitor {
20 public:
21 Rewriter(uintptr_t stack_limit, Expression* initializer, Scope* old_scope,
22 Scope* new_scope)
23 : AstExpressionVisitor(stack_limit, initializer),
24 old_scope_(old_scope),
25 new_scope_(new_scope) {}
26
27 private:
28 void VisitExpression(Expression* expr) override {}
29
30 void VisitFunctionLiteral(FunctionLiteral* expr) override;
31 void VisitClassLiteral(ClassLiteral* expr) override;
32 void VisitVariableProxy(VariableProxy* expr) override;
33
34 Scope* old_scope_;
35 Scope* new_scope_;
36 };
37
38
39 void Rewriter::VisitFunctionLiteral(FunctionLiteral* function_literal) {
40 function_literal->scope()->ReplaceOuterScope(new_scope_);
41 }
42
43
44 void Rewriter::VisitClassLiteral(ClassLiteral* class_literal) {
45 class_literal->scope()->ReplaceOuterScope(new_scope_);
46 if (class_literal->extends() != nullptr) {
47 Visit(class_literal->extends());
48 }
49 // No need to visit the constructor since it will have the class
50 // scope on its scope chain.
51 ZoneList<ObjectLiteralProperty*>* props = class_literal->properties();
52 for (int i = 0; i < props->length(); ++i) {
53 ObjectLiteralProperty* prop = props->at(i);
54 if (!prop->key()->IsLiteral()) {
55 Visit(prop->key());
56 }
57 // No need to visit the values, since all values are functions with
58 // the class scope on their scope chain.
59 DCHECK(prop->value()->IsFunctionLiteral());
60 }
61 }
62
63
64 void Rewriter::VisitVariableProxy(VariableProxy* proxy) {
65 DCHECK(!proxy->is_resolved());
66 if (old_scope_->RemoveUnresolved(proxy)) {
67 new_scope_->AddUnresolved(proxy);
68 }
69 }
70
71
72 } // anonymous namespace
73
74
75 void RewriteParameterInitializerScope(uintptr_t stack_limit,
76 Expression* initializer, Scope* old_scope,
77 Scope* new_scope) {
78 Rewriter rewriter(stack_limit, initializer, old_scope, new_scope);
79 rewriter.Run();
80 }
81
82
83 } // namespace internal
84 } // namespace v8
OLDNEW
« no previous file with comments | « src/parameter-initializer-rewriter.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698