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

Unified Diff: test/mjsunit/es6/classes-subclass-builtins.js

Issue 1427483002: [es6] Better support for built-ins subclassing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Avoid crashes in case of Function subclassing 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
« src/runtime/runtime-object.cc ('K') | « src/x64/builtins-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/es6/classes-subclass-builtins.js
diff --git a/test/mjsunit/es6/classes-subclass-builtins.js b/test/mjsunit/es6/classes-subclass-builtins.js
new file mode 100644
index 0000000000000000000000000000000000000000..ac657cf9b280bbe2d5a9ab65d3c0f54f5e807ad7
--- /dev/null
+++ b/test/mjsunit/es6/classes-subclass-builtins.js
@@ -0,0 +1,342 @@
+// 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.
+
+// Flags: --allow-natives-syntax
+
+"use strict";
+
+
+function checkPrototypeChain(object, constructors) {
+ var proto = object.__proto__;
+ for (var i = 0; i < constructors.length; i++) {
+ assertEquals(constructors[i].prototype, proto);
+ assertEquals(constructors[i], proto.constructor);
+ proto = proto.__proto__;
+ }
+}
+
+
+/*
+// TODO(ishell): BUG: v8:3101, fix this case.
+(function() {
+ class A extends Object {
+ constructor(v) {
+ assertTrue(%IsConstructCall());
+ super(v);
+ this.a = 42;
+ }
+ }
+
+ var s = new A("foo");
+ assertTrue(s instanceof Object);
+ assertTrue(s instanceof String);
+ assertTrue(s instanceof A);
+ assertEquals("foo", s.valueOf());
+ assertEquals(42, s.a);
+
+ var s1 = new A("bar");
+ assertTrue(%HaveSameMap(s, s1));
+
+
+ var n = new A(153);
+ assertTrue(n instanceof Object);
+ assertTrue(n instanceof Number);
+ assertTrue(n instanceof A);
+ assertEquals(153, n.valueOf());
+ assertEquals(42, n.a);
+
+ var n1 = new A(312);
+ assertTrue(%HaveSameMap(n, n1));
+ assertTrue(%HaveSameMap(n, s));
+
+
+ var b = new A(true);
+ assertTrue(b instanceof Object);
+ assertTrue(b instanceof Boolean);
+ assertTrue(b instanceof A);
+ assertEquals(153, b.valueOf());
+ assertEquals(42, b.a);
+
+ var b1 = new A(true);
+ assertTrue(%HaveSameMap(b, b1));
+ assertTrue(%HaveSameMap(b, s));
+
+})();
+//*/
+
+
+(function() {
+ class A extends String {
+ constructor(v) {
+ assertTrue(%IsConstructCall());
+ super(v);
+ this.a = 42;
+ }
+ }
+
+ var o = new A("foo");
+ assertTrue(o instanceof Object);
+ assertTrue(o instanceof String);
+ assertTrue(o instanceof A);
+ assertEquals("object", typeof o);
+ checkPrototypeChain(o, [A, String]);
+
+ assertEquals("foo", o.valueOf());
+ assertEquals(42, o.a);
+
+ var o1 = new A("bar");
+ assertTrue(%HaveSameMap(o, o1));
+})();
+
+
+(function() {
+ class A extends Number {
+ constructor(v) {
+ assertTrue(%IsConstructCall());
+ super(v);
+ this.a = 42;
+ }
+ }
+
+ var o = new A(153);
+ assertTrue(o instanceof Object);
+ assertTrue(o instanceof Number);
+ assertTrue(o instanceof A);
+ assertEquals("object", typeof o);
+ checkPrototypeChain(o, [A, Number]);
+ assertEquals(153, o.valueOf());
+ assertEquals(42, o.a);
+
+ var o1 = new A(312);
+ assertTrue(%HaveSameMap(o, o1));
+})();
+
+
+(function() {
+ class A extends Boolean {
+ constructor(v) {
+ assertTrue(%IsConstructCall());
+ super(v);
+ this.a = 42;
+ }
+ }
+
+ var o = new A(true);
+ assertTrue(o instanceof Object);
+ assertTrue(o instanceof Boolean);
+ assertTrue(o instanceof A);
+ assertEquals("object", typeof o);
+ checkPrototypeChain(o, [A, Boolean]);
+ assertTrue(o.valueOf());
+ assertEquals(42, o.a);
+
+ var o1 = new A(false);
+ assertTrue(%HaveSameMap(o, o1));
+})();
+
+
+/*
+// TODO(ishell): BUG: v8:3101, fix this case.
+(function() {
+ class A extends Function {
+ constructor(v) {
+ assertTrue(%IsConstructCall());
+ super(v);
+ this.a = 42;
+ }
+ }
+
+ var o = new A("return 153;");
+ assertTrue(o instanceof Function);
+ assertTrue(o instanceof A);
+ assertTrue(o instanceof Object);
+ assertEquals("function", typeof o);
+ checkPrototypeChain(o, [A, Function]);
+ assertEquals(42, o.a);
+
+ var o1 = new A("return 312;");
+ assertTrue(%HaveSameMap(o, o1));
+})();
+//*/
+
+
+(function() {
+ class A extends Array {
+ constructor(v) {
+ assertTrue(%IsConstructCall());
+ super(v);
+ this.a = 42;
+ }
+ }
+
+ var o = new A(10);
+ assertTrue(o instanceof Object);
+ assertTrue(o instanceof Array);
+ assertTrue(o instanceof A);
+ assertEquals("object", typeof o);
+ checkPrototypeChain(o, [A, Array]);
+ assertEquals(10, o.length);
+ assertEquals(42, o.a);
+
+ var o1 = new A(7);
+ assertTrue(%HaveSameMap(o, o1));
+})();
+
+
+(function() {
+ class A extends Int32Array {
+ constructor(v) {
+ assertTrue(%IsConstructCall());
+ super(v);
+ this.a = 42;
+ }
+ }
+
+ var o = new A(10);
+ assertTrue(o instanceof Object);
+ assertTrue(o instanceof Int32Array);
+ assertTrue(o instanceof A);
+ assertEquals("object", typeof o);
+ checkPrototypeChain(o, [A, Int32Array]);
+ assertEquals(10, o.length);
+ assertEquals(42, o.a);
+
+ var o1 = new A(7);
+ assertTrue(%HaveSameMap(o, o1));
+})();
+
+
+(function() {
+ class A extends RegExp {
+ constructor(v) {
+ assertTrue(%IsConstructCall());
+ super(v);
+ this.a = 42;
+ }
+ }
+
+ var o = new A("o..h");
+ assertTrue(o instanceof Object);
+ assertTrue(o instanceof RegExp);
+ assertTrue(o instanceof A);
+ assertEquals("object", typeof o);
+ checkPrototypeChain(o, [A, RegExp]);
+ assertTrue(o.test("ouch"));
+ assertEquals(42, o.a);
+
+ var o1 = new A(7);
+ assertTrue(%HaveSameMap(o, o1));
+})();
+
+
+(function() {
+ class A extends Boolean {
+ constructor() {
+ assertTrue(%IsConstructCall());
+ super(true);
+ this.a00 = 0
+ this.a01 = 0
+ this.a02 = 0
+ this.a03 = 0
+ this.a04 = 0
+ this.a05 = 0
+ this.a06 = 0
+ this.a07 = 0
+ this.a08 = 0
+ this.a09 = 0
+ this.a10 = 0
+ this.a11 = 0
+ this.a12 = 0
+ this.a13 = 0
+ this.a14 = 0
+ this.a15 = 0
+ this.a16 = 0
+ this.a17 = 0
+ this.a18 = 0
+ this.a19 = 0
+ }
+ }
+
+ class B extends A {
+ constructor() {
+ assertTrue(%IsConstructCall());
+ super();
+ this.b00 = 0
+ this.b01 = 0
+ this.b02 = 0
+ this.b03 = 0
+ this.b04 = 0
+ this.b05 = 0
+ this.b06 = 0
+ this.b07 = 0
+ this.b08 = 0
+ this.b09 = 0
+ this.b10 = 0
+ this.b11 = 0
+ this.b12 = 0
+ this.b13 = 0
+ this.b14 = 0
+ this.b15 = 0
+ this.b16 = 0
+ this.b17 = 0
+ this.b18 = 0
+ this.b19 = 0
+ }
+ }
+
+ class C extends B {
+ constructor() {
+ assertTrue(%IsConstructCall());
+ super();
+ this.c00 = 0
+ this.c01 = 0
+ this.c02 = 0
+ this.c03 = 0
+ this.c04 = 0
+ this.c05 = 0
+ this.c06 = 0
+ this.c07 = 0
+ this.c08 = 0
+ this.c09 = 0
+ this.c10 = 0
+ this.c11 = 0
+ this.c12 = 0
+ this.c13 = 0
+ this.c14 = 0
+ this.c15 = 0
+ this.c16 = 0
+ this.c17 = 0
+ this.c18 = 0
+ this.c19 = 0
+ }
+ }
+
+ var o = new C();
+ assertTrue(o instanceof Object);
+ assertTrue(o instanceof Boolean);
+ assertTrue(o instanceof A);
+ assertTrue(o instanceof B);
+ assertTrue(o instanceof C);
+ assertEquals("object", typeof o);
+ checkPrototypeChain(o, [C, B, A, Boolean]);
+})();
+
+
+(function() {
+ assertThrows("class A extends undefined {}");
+ assertThrows("class B extends NaN {}");
+ assertThrows("class C extends Infinity {}");
+})();
+
+
+(function() {
+ class A extends null {}
+ assertThrows("new A");
+})();
+
+
+(function() {
+ class A extends Symbol {}
+ assertThrows("new A");
+})();
« src/runtime/runtime-object.cc ('K') | « src/x64/builtins-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698