Reviewers: arv_chromum.org,
Message:
PTAL. Addressed all your comments except for message location, also fixed
some
issues with super calls from arguments of super constructor.
Note that I currently disallow 'super(super(...))' (which is technically
ok).
I do allow 'super(new super(...))' though.
Message location will follow in separate CL.
Description:
harmony-classes: Fix some issues with syntactic restriction on super(...).
[email protected]
BUG=v8:3330
LOG=N
Please review this at https://codereview.chromium.org/770843002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+46, -12 lines):
M src/ast-this-access-visitor.h
M src/ast-this-access-visitor.cc
M src/scopes.cc
M test/mjsunit/harmony/classes.js
Index: src/ast-this-access-visitor.cc
diff --git a/src/ast-this-access-visitor.cc b/src/ast-this-access-visitor.cc
index
e66f961f817197d85e2b02f30cefcec00effc9d4..cf4a3de842a999a764a57aa1ecf437222a738e50
100644
--- a/src/ast-this-access-visitor.cc
+++ b/src/ast-this-access-visitor.cc
@@ -22,6 +22,21 @@ void ATAV::VisitVariableProxy(VariableProxy* proxy) {
}
+void ATAV::VisitSuperReference(SuperReference* leaf) {
+ // disallow super.method() and super(...).
+ uses_this_ = true;
+}
+
+
+void ATAV::VisitCallNew(CallNew* e) {
+ // new super(..) does not use 'this'.
+ if (!e->expression()->IsSuperReference()) {
+ Visit(e->expression());
+ }
+ VisitExpressions(e->arguments());
+}
+
+
//
---------------------------------------------------------------------------
// -- Leaf nodes
-------------------------------------------------------------
//
---------------------------------------------------------------------------
@@ -43,8 +58,6 @@ void
ATAV::VisitNativeFunctionLiteral(NativeFunctionLiteral* leaf) {}
void ATAV::VisitLiteral(Literal* leaf) {}
void ATAV::VisitRegExpLiteral(RegExpLiteral* leaf) {}
void ATAV::VisitThisFunction(ThisFunction* leaf) {}
-void ATAV::VisitSuperReference(SuperReference* leaf) {}
-
//
---------------------------------------------------------------------------
// -- Pass-through
nodes------------------------------------------------------
@@ -95,7 +108,7 @@ void ATAV::VisitTryFinallyStatement(TryFinallyStatement*
stmt) {
void ATAV::VisitClassLiteral(ClassLiteral* e) {
VisitIfNotNull(e->extends());
- VisitIfNotNull(e->constructor());
+ Visit(e->constructor());
ZoneList<ObjectLiteralProperty*>* properties = e->properties();
for (int i = 0; i < properties->length(); i++) {
Visit(properties->at(i)->value());
@@ -142,12 +155,6 @@ void ATAV::VisitCall(Call* e) {
}
-void ATAV::VisitCallNew(CallNew* e) {
- Visit(e->expression());
- VisitExpressions(e->arguments());
-}
-
-
void ATAV::VisitCallRuntime(CallRuntime* e) {
VisitExpressions(e->arguments());
}
Index: src/ast-this-access-visitor.h
diff --git a/src/ast-this-access-visitor.h b/src/ast-this-access-visitor.h
index
3317922ca5b8191911eab8ac14fe857f25e35a48..277553defdc65246845df46dfe4c6e5546016101
100644
--- a/src/ast-this-access-visitor.h
+++ b/src/ast-this-access-visitor.h
@@ -30,5 +30,5 @@ class AstThisAccessVisitor : public AstVisitor {
DISALLOW_COPY_AND_ASSIGN(AstThisAccessVisitor);
};
}
-} // namespace v8::intrenal
+} // namespace v8::internal
#endif // V8_AST_THIS_ACCESS_VISITOR_H_
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index
74c3f0be04db03830ea4d2006642a571c7178018..39b67a886444fe1db46a54e4006d37abd68d447a
100644
--- a/src/scopes.cc
+++ b/src/scopes.cc
@@ -902,9 +902,8 @@ void Scope::Print(int n) {
if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n");
if (scope_uses_super_property_)
Indent(n1, "// scope uses 'super' property\n");
- if (scope_uses_super_constructor_call_) {
+ if (scope_uses_super_constructor_call_)
Indent(n1, "// scope uses 'super' constructor\n");
- }
if (scope_uses_this_) Indent(n1, "// scope uses 'this'\n");
if (inner_scope_uses_arguments_) {
Indent(n1, "// inner scope uses 'arguments'\n");
Index: test/mjsunit/harmony/classes.js
diff --git a/test/mjsunit/harmony/classes.js
b/test/mjsunit/harmony/classes.js
index
5cea2a98e5901990a0f9caeb36b3e57750770768..29ffbf8d7de2ca507324bd9becb13c6734dd0c69
100644
--- a/test/mjsunit/harmony/classes.js
+++ b/test/mjsunit/harmony/classes.js
@@ -805,6 +805,28 @@ function assertAccessorDescriptor(object, name) {
assertThrows(function() {
class C {
constructor() {
+ super.method();
+ super(this);
+ }
+ }; new C();
+ }, TypeError);
+ assertThrows(function() {
+ class C {
+ constructor() {
+ super(super.method());
+ }
+ }; new C();
+ }, TypeError);
+ assertThrows(function() {
+ class C {
+ constructor() {
+ super(super());
+ }
+ }; new C();
+ }, TypeError);
+ assertThrows(function() {
+ class C {
+ constructor() {
super(1, 2, Object.getPrototypeOf(this));
}
}; new C();
@@ -848,4 +870,10 @@ function assertAccessorDescriptor(object, name) {
}
};
new C3();
+
+ class C4 extends Object {
+ constructor() {
+ super(new super());
+ }
+ }; new C4();
}());
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.