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

Unified Diff: src/parameter-initializer-rewriter.cc

Issue 1405313002: [es6] Fix scoping for default parameters in arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix class literal handling 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parameter-initializer-rewriter.h ('k') | src/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parameter-initializer-rewriter.cc
diff --git a/src/parameter-initializer-rewriter.cc b/src/parameter-initializer-rewriter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..54c5472bdbc47003149ad504f7898d4b96fd8e62
--- /dev/null
+++ b/src/parameter-initializer-rewriter.cc
@@ -0,0 +1,84 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/v8.h"
+
+#include "src/parameter-initializer-rewriter.h"
+
+#include "src/ast.h"
+#include "src/ast-expression-visitor.h"
+#include "src/scopes.h"
+
+namespace v8 {
+namespace internal {
+
+namespace {
+
+
+class Rewriter final : public AstExpressionVisitor {
+ public:
+ Rewriter(uintptr_t stack_limit, Expression* initializer, Scope* old_scope,
+ Scope* new_scope)
+ : AstExpressionVisitor(stack_limit, initializer),
+ old_scope_(old_scope),
+ new_scope_(new_scope) {}
+
+ private:
+ void VisitExpression(Expression* expr) override {}
+
+ void VisitFunctionLiteral(FunctionLiteral* expr) override;
+ void VisitClassLiteral(ClassLiteral* expr) override;
+ void VisitVariableProxy(VariableProxy* expr) override;
+
+ Scope* old_scope_;
+ Scope* new_scope_;
+};
+
+
+void Rewriter::VisitFunctionLiteral(FunctionLiteral* function_literal) {
+ function_literal->scope()->set_outer_scope(new_scope_);
+}
+
+
+void Rewriter::VisitClassLiteral(ClassLiteral* class_literal) {
+ class_literal->scope()->set_outer_scope(new_scope_);
+ if (class_literal->extends() != nullptr) {
+ Visit(class_literal->extends());
+ }
+ // No need to visit the constructor since it will have the class
+ // scope on its scope chain.
+ ZoneList<ObjectLiteralProperty*>* props = class_literal->properties();
+ for (int i = 0; i < props->length(); ++i) {
+ ObjectLiteralProperty* prop = props->at(i);
+ if (!prop->key()->IsLiteral()) {
+ Visit(prop->key());
+ }
+ // No need to visit the values, since all values are functions with
+ // the class scope on their scope chain.
+ DCHECK(prop->value()->IsFunctionLiteral());
+ }
+}
+
+
+void Rewriter::VisitVariableProxy(VariableProxy* proxy) {
+ DCHECK(!proxy->is_resolved());
+ if (old_scope_->RemoveUnresolved(proxy)) {
+ new_scope_->AddUnresolved(proxy);
+ }
+}
+
+
+} // anonymous namespace
+
+
+void RewriteParameterInitializerScope(uintptr_t stack_limit,
+ Expression* initializer, Scope* old_scope,
+ Scope* new_scope) {
+ Rewriter rewriter(stack_limit, initializer, old_scope, new_scope);
+ rewriter.Run();
+}
+
+
+} // namespace internal
+} // namespace v8
« 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