Bug 1055472 - Part 18: Incorportate arai's test into the subclassing suite. (r=me)
☠☠ backed out by 70f41cd98857 ☠ ☠
authorEric Faust <efaustbmo@gmail.com>
Wed, 18 Nov 2015 14:11:14 -0800
changeset 273149 0389acea3fc76584ffb374a2dc26d2c086b229ac
parent 273148 6f4006cfea7a22d27608e4872d2901167f9e8fd9
child 273150 b6c8ce8730d72856699345a4d3c52781e5a84fa7
push id68184
push userefaustbmo@gmail.com
push dateWed, 18 Nov 2015 22:11:26 +0000
treeherdermozilla-inbound@0389acea3fc7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1055472
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1055472 - Part 18: Incorportate arai's test into the subclassing suite. (r=me)
js/src/tests/ecma_6/Class/extendBuiltinConstructors.js
--- a/js/src/tests/ecma_6/Class/extendBuiltinConstructors.js
+++ b/js/src/tests/ecma_6/Class/extendBuiltinConstructors.js
@@ -1,23 +1,60 @@
 var test = `
 
-function testBuiltin(builtin, ...args) {
-    class inst extends builtin {
+function testBuiltinInstanceIsInstanceOf(instance, builtin, class_) {
+    assertEq(instance instanceof class_, true);
+    assertEq(instance instanceof builtin, true);
+
+    if (builtin === Array)
+        assertEq(Array.isArray(instance), true);
+}
+
+function testBuiltinInstance(builtin, ...args) {
+    class sub extends builtin {
         constructor(...args) {
             super(...args);
             this.called = true;
         }
     }
 
-    let instance = new inst(...args);
-    assertEq(instance instanceof inst, true);
-    assertEq(instance instanceof builtin, true);
+    let instance = new sub(...args);
     assertEq(instance.called, true);
-    return instance;
+    testBuiltinInstanceIsInstanceOf(instance, builtin, sub);
+}
+
+function testBuiltinMultipleSubclasses(builtin, ...args) {
+    function f(obj, prop) {
+        assertEq(obj.prop, prop);
+    }
+
+    class sub1 extends builtin { };
+    class sub2 extends builtin { };
+
+    const prop1 = "A";
+    const prop2 = "B";
+
+    sub1.prototype.prop = prop1;
+    sub2.prototype.prop = prop2;
+
+    let instance1 = new sub1(...args);
+    let instance2 = new sub2(...args);
+
+    // Also make sure we get the properties we want with a default constructor
+    testBuiltinInstanceIsInstanceOf(instance1, builtin, sub1);
+
+    for (let i = 0; i < 10; i++) {
+        f(instance1, prop1);
+        f(instance2, prop2);
+    }
+}
+
+function testBuiltin(builtin, ...args) {
+    testBuiltinInstance(builtin, ...args);
+    testBuiltinMultipleSubclasses(builtin, ...args);
 }
 
 function testBuiltinTypedArrays() {
     let typedArrays = [Int8Array,
                        Uint8Array,
                        Uint8ClampedArray,
                        Int16Array,
                        Uint16Array,
@@ -29,31 +66,16 @@ function testBuiltinTypedArrays() {
     for (let array of typedArrays) {
         testBuiltin(array);
         testBuiltin(array, 5);
         testBuiltin(array, new array());
         testBuiltin(array, new ArrayBuffer());
     }
 }
 
-function testBuiltinArray() {
-    let argsLists = [
-        [],
-        [15],
-        [3.0],
-        ["non-length one-arg"],
-        [5, 10, 15, "these are elements"]
-    ];
-
-    for (let args of argsLists) {
-        let instance = testBuiltin(Array, ...args);
-        assertEq(Array.isArray(instance), true);
-    }
-}
-
 testBuiltin(Function);
 testBuiltin(Object);
 testBuiltin(Boolean);
 testBuiltin(Error);
 testBuiltin(EvalError);
 testBuiltin(RangeError);
 testBuiltin(ReferenceError);
 testBuiltin(SyntaxError);
@@ -70,17 +92,21 @@ testBuiltin(Map);
 testBuiltin(Set);
 testBuiltin(WeakMap);
 testBuiltin(WeakSet);
 testBuiltin(ArrayBuffer);
 testBuiltinTypedArrays();
 testBuiltin(DataView, new ArrayBuffer());
 testBuiltin(DataView, new (newGlobal().ArrayBuffer)());
 testBuiltin(String);
-testBuiltinArray();
+testBuiltin(Array);
+testBuiltin(Array, 15);
+testBuiltin(Array, 3.0);
+testBuiltin(Array, "non-length one-arg");
+testBuiltin(Array, 5, 10, 15, "these are elements");
 
 `;
 
 if (classesEnabled())
     eval(test);
 
 if (typeof reportCompare === 'function')
     reportCompare(0,0,"OK");