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

Unified Diff: test/mjsunit/harmony/classes-subclass-arrays.js

Issue 975463002: Implement subclassing Arrays. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix arm again 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
Index: test/mjsunit/harmony/classes-subclass-arrays.js
diff --git a/test/mjsunit/harmony/classes-subclass-arrays.js b/test/mjsunit/harmony/classes-subclass-arrays.js
new file mode 100644
index 0000000000000000000000000000000000000000..e0363c715bc433b7706c1aed00ab4ada0c6d10c2
--- /dev/null
+++ b/test/mjsunit/harmony/classes-subclass-arrays.js
@@ -0,0 +1,150 @@
+// 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: --harmony-classes
+'use strict';
+
+(function TestDefaultConstructor() {
+ class Stack extends Array { }
+ {
+ let s1 = new Stack();
+ assertSame(Stack.prototype, s1.__proto__);
+ assertTrue(Array.isArray(s1));
+ assertSame(0, s1.length);
+ s1[0] = 'xyz';
+ assertSame(1, s1.length);
+ assertSame('xyz', s1[0]);
+ s1.push(42);
+ assertSame(2, s1.length);
+ assertSame('xyz', s1[0]);
+ assertSame(42, s1[1]);
+ }
+
+ {
+ let s2 = new Stack(10);
+ assertSame(Stack.prototype, s2.__proto__);
+ assertTrue(Array.isArray(s2));
+ assertSame(10, s2.length);
+ assertSame(undefined, s2[0]);
+ }
+
+ {
+ let a = [1,2,3];
+ let s3 = new Stack(a);
+ assertSame(Stack.prototype, s3.__proto__);
+ assertTrue(Array.isArray(s3));
+ assertSame(1, s3.length);
+ assertSame(a, s3[0]);
+ }
+
+ {
+ let s4 = new Stack(1, 2, 3);
+ assertSame(Stack.prototype, s4.__proto__);
+ assertTrue(Array.isArray(s4));
+ assertSame(3, s4.length);
+ assertSame(1, s4[0]);
+ assertSame(2, s4[1]);
+ assertSame(3, s4[2]);
+ }
+
+ {
+ let s5 = new Stack(undefined, undefined, undefined);
+ assertSame(Stack.prototype, s5.__proto__);
+ assertTrue(Array.isArray(s5));
+ assertSame(3, s5.length);
+ assertSame(undefined, s5[0]);
+ assertSame(undefined, s5[1]);
+ assertSame(undefined, s5[2]);
+ }
+}());
+
+
+(function TestEmptyArgsSuper() {
+ class Stack extends Array {
+ constructor() { super(); }
+ }
+ let s1 = new Stack();
+ assertSame(Stack.prototype, s1.__proto__);
+ assertTrue(Array.isArray(s1));
+ assertSame(0, s1.length);
+ s1[0] = 'xyz';
+ assertSame(1, s1.length);
+ assertSame('xyz', s1[0]);
+ s1.push(42);
+ assertSame(2, s1.length);
+ assertSame('xyz', s1[0]);
+ assertSame(42, s1[1]);
+}());
+
+
+(function TestOneArgSuper() {
+ class Stack extends Array {
+ constructor(x) {
+ super(x);
+ }
+ }
+
+ {
+ let s2 = new Stack(10, 'ignored arg');
+ assertSame(Stack.prototype, s2.__proto__);
+ assertTrue(Array.isArray(s2));
+ assertSame(10, s2.length);
+ assertSame(undefined, s2[0]);
+ }
+
+ {
+ let a = [1,2,3];
+ let s3 = new Stack(a, 'ignored arg');
+ assertSame(Stack.prototype, s3.__proto__);
+ assertTrue(Array.isArray(s3));
+ assertSame(1, s3.length);
+ assertSame(a, s3[0]);
+ }
+}());
+
+
+(function TestMultipleArgsSuper() {
+ class Stack extends Array {
+ constructor(x, y, z) {
+ super(x, y, z);
+ }
+ }
+ {
+ let s4 = new Stack(1, 2, 3, 4, 5);
+ assertSame(Stack.prototype, s4.__proto__);
+ assertTrue(Array.isArray(s4));
+ assertSame(3, s4.length);
+ assertSame(1, s4[0]);
+ assertSame(2, s4[1]);
+ assertSame(3, s4[2]);
+ }
+
+ {
+ let s5 = new Stack(undefined);
+ assertSame(Stack.prototype, s5.__proto__);
+ assertTrue(Array.isArray(s5));
+ assertTrue(s5.__proto__ == Stack.prototype);
+ assertSame(3, s5.length);
+ assertSame(undefined, s5[0]);
+ assertSame(undefined, s5[1]);
+ assertSame(undefined, s5[2]);
+ }
+}());
+
+
+(function TestArrayConcat() {
+ class Stack extends Array { }
+ let s1 = new Stack(1,2,3);
+
+ assertArrayEquals([1,2,3,4,5,6], s1.concat([4,5,6]));
+ assertArrayEquals([4,5,6,1,2,3], [4,5,6].concat(s1));
+}());
+
+
+(function TestJSONStringify() {
+ class Stack extends Array { }
+
+ let s1 = new Stack(1,2,3);
+ assertSame("[1,2,3]", JSON.stringify(s1));
+}());

Powered by Google App Engine
This is Rietveld 408576698