OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 // Flags: --harmony-iteration --harmony-symbols --allow-natives-syntax | |
29 | |
rossberg
2013/06/13 08:22:02
Can you add some tests using for-of?
arv (Not doing code reviews)
2013/06/13 13:54:27
I was planning to. I just wanted to send this out
| |
30 function TestArrayPrototype() { | |
31 assertTrue(Array.prototype.hasOwnProperty('entries')); | |
32 assertTrue(Array.prototype.hasOwnProperty('values')); | |
33 assertTrue(Array.prototype.hasOwnProperty('keys')); | |
34 | |
35 assertFalse(Array.prototype.propertyIsEnumerable('entries')); | |
36 assertFalse(Array.prototype.propertyIsEnumerable('values')); | |
37 assertFalse(Array.prototype.propertyIsEnumerable('keys')); | |
38 } | |
39 TestArrayPrototype(); | |
40 | |
41 function assertIteratorResult(value, done, result) { | |
42 assertEquals({ value: value, done: done}, result); | |
43 } | |
44 | |
45 function TestValues() { | |
46 var array = ['a', 'b', 'c']; | |
47 var iterator = array.values(); | |
48 assertIteratorResult('a', false, iterator.next()); | |
49 assertIteratorResult('b', false, iterator.next()); | |
50 assertIteratorResult('c', false, iterator.next()); | |
51 assertIteratorResult(void 0, true, iterator.next()); | |
52 | |
53 array.push('d'); | |
54 assertIteratorResult(void 0, true, iterator.next()); | |
55 } | |
56 TestValues(); | |
57 | |
58 function TestValuesMutate() { | |
59 var array = ['a', 'b', 'c']; | |
60 var iterator = array.values(); | |
61 assertIteratorResult('a', false, iterator.next()); | |
62 assertIteratorResult('b', false, iterator.next()); | |
63 assertIteratorResult('c', false, iterator.next()); | |
64 array.push('d'); | |
65 assertIteratorResult('d', false, iterator.next()); | |
66 assertIteratorResult(void 0, true, iterator.next()); | |
67 } | |
68 TestValuesMutate(); | |
69 | |
70 function TestKeys() { | |
71 var array = ['a', 'b', 'c']; | |
72 var iterator = array.keys(); | |
73 assertIteratorResult('0', false, iterator.next()); | |
74 assertIteratorResult('1', false, iterator.next()); | |
75 assertIteratorResult('2', false, iterator.next()); | |
76 assertIteratorResult(void 0, true, iterator.next()); | |
77 | |
78 array.push('d'); | |
79 assertIteratorResult(void 0, true, iterator.next()); | |
80 } | |
81 TestKeys(); | |
82 | |
83 function TestKeysMutate() { | |
84 var array = ['a', 'b', 'c']; | |
85 var iterator = array.keys(); | |
86 assertIteratorResult('0', false, iterator.next()); | |
87 assertIteratorResult('1', false, iterator.next()); | |
88 assertIteratorResult('2', false, iterator.next()); | |
89 array.push('d'); | |
90 assertIteratorResult('3', false, iterator.next()); | |
91 assertIteratorResult(void 0, true, iterator.next()); | |
92 } | |
93 TestKeysMutate(); | |
94 | |
95 function TestEntries() { | |
96 var array = ['a', 'b', 'c']; | |
97 var iterator = array.entries(); | |
98 assertIteratorResult(['0', 'a'], false, iterator.next()); | |
99 assertIteratorResult(['1', 'b'], false, iterator.next()); | |
100 assertIteratorResult(['2', 'c'], false, iterator.next()); | |
101 assertIteratorResult(void 0, true, iterator.next()); | |
102 | |
103 array.push('d'); | |
104 assertIteratorResult(void 0, true, iterator.next()); | |
105 } | |
106 TestEntries(); | |
107 | |
108 function TestEntriesMutate() { | |
109 var array = ['a', 'b', 'c']; | |
110 var iterator = array.entries(); | |
111 assertIteratorResult(['0', 'a'], false, iterator.next()); | |
112 assertIteratorResult(['1', 'b'], false, iterator.next()); | |
113 assertIteratorResult(['2', 'c'], false, iterator.next()); | |
114 array.push('d'); | |
115 assertIteratorResult(['3', 'd'], false, iterator.next()); | |
116 assertIteratorResult(void 0, true, iterator.next()); | |
117 } | |
118 TestEntriesMutate(); | |
119 | |
120 function TestArrayIteratorPrototype() { | |
121 var array = []; | |
122 var iterator = array.values(); | |
123 | |
124 var ArrayIterator = iterator.constructor; | |
125 assertEquals(ArrayIterator.prototype, array.values().__proto__); | |
126 assertEquals(ArrayIterator.prototype, array.keys().__proto__); | |
127 assertEquals(ArrayIterator.prototype, array.entries().__proto__); | |
128 | |
129 assertEquals(Object.prototype, ArrayIterator.prototype.__proto__); | |
130 | |
131 assertEquals('Array Iterator', %_ClassOf(array.values())); | |
132 assertEquals('Array Iterator', %_ClassOf(array.keys())); | |
133 assertEquals('Array Iterator', %_ClassOf(array.entries())); | |
134 | |
135 var prototypeDescriptor = | |
136 Object.getOwnPropertyDescriptor(ArrayIterator, 'prototype'); | |
137 assertFalse(prototypeDescriptor.configurable); | |
138 assertFalse(prototypeDescriptor.enumerable); | |
139 assertFalse(prototypeDescriptor.writable); | |
140 } | |
141 TestArrayIteratorPrototype(); | |
OLD | NEW |