Revision: 24340
Author:   dslo...@chromium.org
Date:     Tue Sep 30 18:12:22 2014 UTC
Log:      Desugar 'super(..)' into 'super.constructor(...)'

R=a...@chromium.org, ma...@chromium.org
BUG=v8:3330
LOG=N

Review URL: https://codereview.chromium.org/615043002
https://code.google.com/p/v8/source/detail?r=24340

Modified:
 /branches/bleeding_edge/src/ast.h
 /branches/bleeding_edge/test/mjsunit/harmony/super.js

=======================================
--- /branches/bleeding_edge/src/ast.h   Tue Sep 30 10:29:32 2014 UTC
+++ /branches/bleeding_edge/src/ast.h   Tue Sep 30 18:12:22 2014 UTC
@@ -3390,7 +3390,16 @@
   Call* NewCall(Expression* expression,
                 ZoneList<Expression*>* arguments,
                 int pos) {
- Call* call = new (zone_) Call(zone_, expression, arguments, pos, id_gen_);
+    SuperReference* super_ref = expression->AsSuperReference();
+    Call* call;
+    if (super_ref != NULL) {
+      Literal* constructor =
+          NewStringLiteral(ast_value_factory_->constructor_string(), pos);
+ Property* superConstructor = NewProperty(super_ref, constructor, pos); + call = new (zone_) Call(zone_, superConstructor, arguments, pos, id_gen_);
+    } else {
+      call = new (zone_) Call(zone_, expression, arguments, pos, id_gen_);
+    }
     VISIT_AND_RETURN(Call, call)
   }

=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/super.js Tue Sep 30 15:30:10 2014 UTC +++ /branches/bleeding_edge/test/mjsunit/harmony/super.js Tue Sep 30 18:12:22 2014 UTC
@@ -474,6 +474,64 @@
 }());


+(function TestSuperCall() {
+  function Subclass(base, constructor) {
+    var homeObject = { __proto__ : base.prototype };
+    var result = constructor.toMethod(homeObject);
+    homeObject.constructor = result;
+    result.prototype = homeObject;
+    return result;
+  }
+
+  var baseCalled = 0;
+  var derivedCalled = 0;
+  var derivedDerivedCalled = 0;
+
+  function Base() {
+    baseCalled++;
+  }
+
+  var Derived = Subclass(Base, function () {
+    super();
+    derivedCalled++;
+  });
+
+  assertEquals(Base, Base.prototype.constructor);
+  assertEquals(Base.prototype, Derived.prototype.__proto__);
+
+  baseCalled = 0;
+  derivedCalled = 0;
+  new Derived();
+  assertEquals(1, baseCalled);
+  assertEquals(1, derivedCalled);
+
+  var DerivedDerived = Subclass(Derived, function () {
+    super();
+    derivedDerivedCalled++;
+  });
+
+  baseCalled = 0;
+  derivedCalled = 0;
+  derivedDerivedCalled = 0;
+  new DerivedDerived();
+  assertEquals(1, baseCalled);
+  assertEquals(1, derivedCalled);
+  assertEquals(1, derivedDerivedCalled);
+
+  function Base2(v) {
+    this.fromBase = v;
+  }
+  var Derived2 = Subclass(Base2, function (v1, v2) {
+    super(v1);
+    this.fromDerived = v2;
+  });
+
+  var d = new Derived2("base", "derived");
+  assertEquals("base", d.fromBase);
+  assertEquals("derived", d.fromDerived);
+}());
+
+
 (function TestUnsupportedCases() {
   function f1(x) { return super[x]; }
   function f2(x) { super[x] = 5; }

--
--
v8-dev mailing list
v8-dev@googlegroups.com
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 v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to