harmony-classes: Fix some issues with syntactic restriction on super(...).
authordslomov <dslomov@chromium.org>
Mon, 1 Dec 2014 20:13:44 +0000 (12:13 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 1 Dec 2014 20:13:54 +0000 (20:13 +0000)
R=arv@chromium.org
BUG=v8:3330
LOG=N

Review URL: https://codereview.chromium.org/770843002

Cr-Commit-Position: refs/heads/master@{#25589}

src/ast-this-access-visitor.cc
src/ast-this-access-visitor.h
src/scopes.cc
test/mjsunit/harmony/classes.js

index e66f961..cf4a3de 100644 (file)
@@ -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 3317922..277553d 100644 (file)
@@ -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 74c3f0b..39b67a8 100644 (file)
@@ -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 5cea2a9..29ffbf8 100644 (file)
@@ -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();
 }());