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

Unified Diff: test/mjsunit/harmony/classes-experimental.js

Issue 908883002: new classes: implement new.target passing to superclass constructor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix x64 arithmetic Created 5 years, 10 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/x64/full-codegen-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/classes-experimental.js
diff --git a/test/mjsunit/harmony/classes-experimental.js b/test/mjsunit/harmony/classes-experimental.js
index ed720d97b6275462e397d3f55e81746a450839f1..36c4dd82465130b767c460bf67fcae9f2077eabc 100644
--- a/test/mjsunit/harmony/classes-experimental.js
+++ b/test/mjsunit/harmony/classes-experimental.js
@@ -5,63 +5,223 @@
// Flags: --experimental-classes --harmony-classes
'use strict';
+(function TestArgumentsAccess() {
+ class Base {
+ constructor() {
+ assertEquals(2, arguments.length);
+ assertEquals(1, arguments[0]);
+ assertEquals(2, arguments[1]);
+ }
+ }
+
+ let b = new Base(1,2);
+
+ class Subclass extends Base {
+ constructor() {
+ assertEquals(2, arguments.length);
+ assertEquals(3, arguments[0]);
+ assertEquals(4, arguments[1]);
+ super(1,2);
+ }
+ }
+
+ let s = new Subclass(3,4);
+ assertEquals(0, Subclass.length);
+
+ class Subclass2 extends Base {
+ constructor(x,y) {
+ assertEquals(2, arguments.length);
+ assertEquals(3, arguments[0]);
+ assertEquals(4, arguments[1]);
+ super(1,2);
+ }
+ }
+
+ let s2 = new Subclass2(3,4);
+ assertEquals(2, Subclass2.length);
+}());
+
+(function TestThisAccessRestriction() {
+ class Base {
+ constructor(a, b) {
+ let o = new Object();
+ o.prp = a + b;
+ return o;
+ }
+ }
+
+ class Subclass extends Base {
+ constructor(a, b) {
+ var exn;
+ try {
+ this.prp1 = 3;
+ } catch (e) {
+ exn = e;
+ }
+ assertTrue(exn instanceof ReferenceError);
+ super(a, b);
+ assertSame(a + b, this.prp);
+ assertSame(undefined, this.prp1);
+ assertFalse(this.hasOwnProperty("prp1"));
+ return this;
+ }
+ }
+
+ let b = new Base(1, 2);
+ assertSame(3, b.prp);
+
+
+ let s = new Subclass(2, -1);
+ assertSame(1, s.prp);
+ assertSame(undefined, s.prp1);
+ assertFalse(s.hasOwnProperty("prp1"));
+
+ class Subclass2 extends Base {
+ constructor(x) {
+ super(1,2);
+
+ if (x < 0) return;
+
+ let called = false;
+ function tmp() { called = true; return 3; }
+ var exn = null;
+ try {
+ super(tmp(),4);
+ } catch (e) { exn = e; }
+ assertTrue(exn instanceof ReferenceError);
+ // TODO(dslomov): should be 'true'.
+ assertFalse(called);
+ }
+ }
+
+ var s2 = new Subclass2(1);
+ assertSame(3, s2.prp);
-class Base {
- constructor(a, b) {
- let o = new Object();
- o.prp = a + b;
- return o;
+ var s3 = new Subclass2(-1);
+ assertSame(3, s3.prp);
+
+ assertThrows(function() { Subclass.call(new Object(), 1, 2); }, TypeError);
+ assertThrows(function() { Base.call(new Object(), 1, 2); }, TypeError);
+
+ class BadSubclass extends Base {
+ constructor() {}
+ }
+
+ assertThrows(function() { new BadSubclass(); }, ReferenceError);
+}());
+
+(function TestPrototypeWiring() {
+ class Base {
+ constructor(x) {
+ this.foobar = x;
+ }
+ }
+
+ class Subclass extends Base {
+ constructor(x) {
+ super(x);
+ }
+ }
+
+ let s = new Subclass(1);
+ assertSame(1, s.foobar);
+ assertSame(Subclass.prototype, s.__proto__);
+
+ let s1 = new Subclass(1, 2);
+ assertSame(1, s1.foobar);
+ assertTrue(s1.__proto__ === Subclass.prototype);
+
+ let s2 = new Subclass();
+ assertSame(undefined, s2.foobar);
+ assertSame(Subclass.prototype, s2.__proto__);
+ assertThrows(function() { Subclass(1); }, TypeError);
+ assertThrows(function() { Subclass(1,2,3,4); }, TypeError);
+
+ class Subclass2 extends Subclass {
+ constructor() {
+ super(5, 6, 7);
+ }
}
-}
-
-class Subclass extends Base {
- constructor(a, b) {
- var exn;
- try {
- this.prp1 = 3;
- } catch (e) {
- exn = e;
+
+ let ss2 = new Subclass2();
+ assertSame(5, ss2.foobar);
+ assertSame(Subclass2.prototype, ss2.__proto__);
+
+ class Subclass3 extends Base {
+ constructor(x,y) {
+ super(x + y);
}
- assertTrue(exn instanceof ReferenceError);
- super(a, b);
- assertSame(a + b, this.prp);
- assertSame(undefined, this.prp1);
- assertFalse(this.hasOwnProperty("prp1"));
- return this;
}
-}
-let b = new Base(1, 2);
-assertSame(3, b.prp);
+ let ss3 = new Subclass3(27,42-27);
+ assertSame(42, ss3.foobar);
+ assertSame(Subclass3.prototype, ss3.__proto__);
+}());
+(function TestSublclassingBuiltins() {
+ class ExtendedUint8Array extends Uint8Array {
+ constructor() {
+ super(10);
+ this[0] = 255;
+ this[1] = 0xFFA;
+ }
+ }
-let s = new Subclass(2, -1);
-assertSame(1, s.prp);
-assertSame(undefined, s.prp1);
-assertFalse(s.hasOwnProperty("prp1"));
+ var eua = new ExtendedUint8Array();
+ assertEquals(10, eua.length);
+ assertEquals(10, eua.byteLength);
+ assertEquals(0xFF, eua[0]);
+ assertEquals(0xFA, eua[1]);
+ assertTrue(eua.__proto__ === ExtendedUint8Array.prototype);
+ assertEquals("[object Uint8Array]", Object.prototype.toString.call(eua));
+}());
-class Subclass2 extends Base {
- constructor(x) {
- super(1,2);
+(function TestSubclassingNull() {
+ let N = null;
- if (x < 0) return;
+ class Foo extends N {
+ constructor(x,y) {
+ assertSame(1, x);
+ assertSame(2, y);
+ return {};
+ }
+ }
+
+ new Foo(1,2);
+}());
+
+(function TestSubclassBinding() {
+ class Base {
+ constructor(x, y) {
+ this.x = x;
+ this.y = y;
+ }
+ }
- let called = false;
- function tmp() { called = true; return 3; }
- var exn = null;
- try {
- super(tmp(),4);
- } catch(e) { exn = e; }
- assertTrue(exn !== null);
- assertFalse(called);
+ let obj = {};
+ class Subclass extends Base {
+ constructor(x,y) {
+ super(x,y);
+ assertTrue(this !== obj);
+ }
}
-}
-var s2 = new Subclass2(1);
-assertSame(3, s2.prp);
+ let f = Subclass.bind(obj);
+ assertThrows(function () { f(1, 2); }, TypeError);
+ let s = new f(1, 2);
+ assertSame(1, s.x);
+ assertSame(2, s.y);
+ assertSame(Subclass.prototype, s.__proto__);
-var s3 = new Subclass2(-1);
-assertSame(3, s3.prp);
+ let s1 = new f(1);
+ assertSame(1, s1.x);
+ assertSame(undefined, s1.y);
+ assertSame(Subclass.prototype, s1.__proto__);
-assertThrows(function() { Subclass.call(new Object(), 1, 2); }, TypeError);
-assertThrows(function() { Base.call(new Object(), 1, 2); }, TypeError);
+ let g = Subclass.bind(obj, 1);
+ assertThrows(function () { g(8); }, TypeError);
+ let s2 = new g(8);
+ assertSame(1, s2.x);
+ assertSame(8, s2.y);
+ assertSame(Subclass.prototype, s.__proto__);
+}());
« no previous file with comments | « src/x64/full-codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698