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

Side by Side 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: typo + test rename Created 5 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Flags: --harmony-classes
6 'use strict';
7
8 (function TestDefaultConstructor() {
9 class Stack extends Array { }
10 {
11 let s1 = new Stack();
12 assertTrue(s1.__proto__ == Stack.prototype);
13 assertSame(0, s1.length);
14 s1[0] = 'xyz';
15 assertSame(1, s1.length);
16 assertEquals('xyz', s1[0]);
17 s1.push(42);
18 assertSame(2, s1.length);
19 assertEquals('xyz', s1[0]);
20 assertEquals(42, s1[1]);
21 }
22
23 {
24 let s2 = new Stack(10);
25 assertTrue(s2.__proto__ == Stack.prototype);
26 assertSame(10, s2.length);
27 assertSame(undefined, s2[0]);
28 }
29
30 {
31 let a = [1,2,3];
32 let s3 = new Stack(a);
33 assertTrue(s3.__proto__ == Stack.prototype);
34 assertSame(1, s3.length);
35 assertSame(a, s3[0]);
36 }
37
38 {
39 let s4 = new Stack(1, 2, 3);
40 assertTrue(s4.__proto__ == Stack.prototype);
41 assertSame(3, s4.length);
42 assertSame(1, s4[0]);
43 assertSame(2, s4[1]);
44 assertSame(3, s4[2]);
45 }
46
47 {
48 let s5 = new Stack(undefined, undefined, undefined);
49 assertTrue(s5.__proto__ == Stack.prototype);
50 assertSame(3, s5.length);
51 assertSame(undefined, s5[0]);
52 assertSame(undefined, s5[1]);
53 assertSame(undefined, s5[2]);
54 }
55 }());
56
57
58 (function TestEmptyArgsSuper() {
59 class Stack extends Array {
60 constructor() { super(); }
61 }
62 let s1 = new Stack();
63 assertTrue(s1.__proto__ == Stack.prototype);
64 assertSame(0, s1.length);
65 s1[0] = 'xyz';
66 assertSame(1, s1.length);
67 assertEquals('xyz', s1[0]);
68 s1.push(42);
69 assertSame(2, s1.length);
70 assertEquals('xyz', s1[0]);
71 assertEquals(42, s1[1]);
72 }());
73
74
75 (function TestOneArgSuper() {
76 class Stack extends Array {
77 constructor(x) {
78 super(x);
79 }
80 }
81
82 {
83 let s2 = new Stack(10, 'ignored arg');
84 assertTrue(s2.__proto__ == Stack.prototype);
85 assertSame(10, s2.length);
86 assertSame(undefined, s2[0]);
87 }
88
89 {
90 let a = [1,2,3];
91 let s3 = new Stack(a, 'ignored arg');
92 assertTrue(s3.__proto__ == Stack.prototype);
93 assertSame(1, s3.length);
94 assertSame(a, s3[0]);
95 }
96 }());
97
98
99 (function TestMultipleArgsSuper() {
100 class Stack extends Array {
101 constructor(x, y, z) {
102 super(x, y, z);
103 }
104 }
105 {
106 let s4 = new Stack(1, 2, 3, 4, 5);
107 assertTrue(s4.__proto__ == Stack.prototype);
108 assertSame(3, s4.length);
109 assertSame(1, s4[0]);
110 assertSame(2, s4[1]);
111 assertSame(3, s4[2]);
112 }
113
114 {
115 let s5 = new Stack(undefined);
116 assertTrue(s5.__proto__ == Stack.prototype);
117 assertSame(3, s5.length);
118 assertSame(undefined, s5[0]);
119 assertSame(undefined, s5[1]);
120 assertSame(undefined, s5[2]);
121 }
122 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698