Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
|
adamk
2014/05/29 00:07:14
Same nit, short license.
| |
| 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-collections --allow-natives-syntax | |
| 29 | |
| 30 | |
| 31 (function TestSetIterator() { | |
| 32 var s = new Set; | |
| 33 var iter = s.values(); | |
| 34 assertEquals('Set Iterator', %_ClassOf(iter)); | |
| 35 | |
| 36 var SetIteratorPrototype = iter.__proto__; | |
| 37 assertFalse(SetIteratorPrototype.hasOwnProperty('constructor')); | |
| 38 assertEquals(SetIteratorPrototype.__proto__, Object.prototype); | |
| 39 | |
| 40 var propertyNames = Object.getOwnPropertyNames(SetIteratorPrototype); | |
| 41 assertArrayEquals(['next'], propertyNames); | |
| 42 | |
| 43 assertEquals(new Set().values().__proto__. SetIteratorPrototype); | |
| 44 assertEquals(new Set().entries().__proto__. SetIteratorPrototype); | |
| 45 })(); | |
| 46 | |
| 47 | |
| 48 (function TestSetIteratorValues() { | |
| 49 var s = new Set; | |
| 50 s.add(1); | |
| 51 s.add(2); | |
| 52 s.add(3); | |
| 53 var iter = s.values(); | |
| 54 | |
| 55 assertEquals({value: 1, done: false}, iter.next()); | |
| 56 assertEquals({value: 2, done: false}, iter.next()); | |
| 57 assertEquals({value: 3, done: false}, iter.next()); | |
| 58 assertEquals({value: undefined, done: true}, iter.next()); | |
| 59 assertEquals({value: undefined, done: true}, iter.next()); | |
| 60 })(); | |
| 61 | |
| 62 | |
| 63 (function TestSetIteratorEntries() { | |
| 64 var s = new Set; | |
| 65 s.add(1); | |
| 66 s.add(2); | |
| 67 s.add(3); | |
| 68 var iter = s.entries(); | |
| 69 | |
| 70 assertEquals({value: [1, 1], done: false}, iter.next()); | |
| 71 assertEquals({value: [2, 2], done: false}, iter.next()); | |
| 72 assertEquals({value: [3, 3], done: false}, iter.next()); | |
| 73 assertEquals({value: undefined, done: true}, iter.next()); | |
| 74 assertEquals({value: undefined, done: true}, iter.next()); | |
| 75 })(); | |
| 76 | |
| 77 | |
| 78 (function TestSetInvalidReceiver() { | |
| 79 assertThrows(function() { | |
| 80 Set.prototype.values.call({}); | |
| 81 }, TypeError); | |
| 82 assertThrows(function() { | |
| 83 Set.prototype.entries.call({}); | |
| 84 }, TypeError); | |
| 85 })(); | |
| 86 | |
| 87 | |
| 88 (function TestSetIteratorInvalidReceiver() { | |
| 89 var iter = new Set().values(); | |
| 90 assertThrows(function() { | |
| 91 iter.next.call({}); | |
| 92 }); | |
| 93 })(); | |
| 94 | |
| 95 | |
| 96 (function TestMapIterator() { | |
| 97 var m = new Map; | |
| 98 var iter = m.values(); | |
| 99 assertEquals('Map Iterator', %_ClassOf(iter)); | |
| 100 | |
| 101 var MapIteratorPrototype = iter.__proto__; | |
| 102 assertFalse(MapIteratorPrototype.hasOwnProperty('constructor')); | |
| 103 assertEquals(MapIteratorPrototype.__proto__, Object.prototype); | |
| 104 | |
| 105 var propertyNames = Object.getOwnPropertyNames(MapIteratorPrototype); | |
| 106 assertArrayEquals(['next'], propertyNames); | |
| 107 | |
| 108 assertEquals(new Map().values().__proto__. MapIteratorPrototype); | |
| 109 assertEquals(new Map().keys().__proto__. MapIteratorPrototype); | |
| 110 assertEquals(new Map().entries().__proto__. MapIteratorPrototype); | |
| 111 })(); | |
| 112 | |
| 113 | |
| 114 (function TestMapIteratorValues() { | |
| 115 var m = new Map; | |
| 116 m.set(1, 11); | |
| 117 m.set(2, 22); | |
| 118 m.set(3, 33); | |
| 119 var iter = m.values(); | |
| 120 | |
| 121 assertEquals({value: 11, done: false}, iter.next()); | |
| 122 assertEquals({value: 22, done: false}, iter.next()); | |
| 123 assertEquals({value: 33, done: false}, iter.next()); | |
| 124 assertEquals({value: undefined, done: true}, iter.next()); | |
| 125 assertEquals({value: undefined, done: true}, iter.next()); | |
| 126 })(); | |
| 127 | |
| 128 | |
| 129 (function TestMapIteratorKeys() { | |
| 130 var m = new Map; | |
| 131 m.set(1, 11); | |
| 132 m.set(2, 22); | |
| 133 m.set(3, 33); | |
| 134 var iter = m.keys(); | |
| 135 | |
| 136 assertEquals({value: 1, done: false}, iter.next()); | |
| 137 assertEquals({value: 2, done: false}, iter.next()); | |
| 138 assertEquals({value: 3, done: false}, iter.next()); | |
| 139 assertEquals({value: undefined, done: true}, iter.next()); | |
| 140 assertEquals({value: undefined, done: true}, iter.next()); | |
| 141 })(); | |
| 142 | |
| 143 | |
| 144 (function TestMapIteratorEntries() { | |
| 145 var m = new Map; | |
| 146 m.set(1, 11); | |
| 147 m.set(2, 22); | |
| 148 m.set(3, 33); | |
| 149 var iter = m.entries(); | |
| 150 | |
| 151 assertEquals({value: [1, 11], done: false}, iter.next()); | |
| 152 assertEquals({value: [2, 22], done: false}, iter.next()); | |
| 153 assertEquals({value: [3, 33], done: false}, iter.next()); | |
| 154 assertEquals({value: undefined, done: true}, iter.next()); | |
| 155 assertEquals({value: undefined, done: true}, iter.next()); | |
| 156 })(); | |
| 157 | |
| 158 | |
| 159 (function TestMapInvalidReceiver() { | |
| 160 assertThrows(function() { | |
| 161 Map.prototype.values.call({}); | |
| 162 }, TypeError); | |
| 163 assertThrows(function() { | |
| 164 Map.prototype.keys.call({}); | |
| 165 }, TypeError); | |
| 166 assertThrows(function() { | |
| 167 Map.prototype.entries.call({}); | |
| 168 }, TypeError); | |
| 169 })(); | |
| 170 | |
| 171 | |
| 172 (function TestMapIteratorInvalidReceiver() { | |
| 173 var iter = new Map().values(); | |
| 174 assertThrows(function() { | |
| 175 iter.next.call({}); | |
| 176 }, TypeError); | |
| 177 })(); | |
| OLD | NEW |