Index: test/mjsunit/harmony/collection-iterator.js |
diff --git a/test/mjsunit/harmony/collection-iterator.js b/test/mjsunit/harmony/collection-iterator.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bc6ee4db0ef566c0a68b8759ed27a1667b15dc75 |
--- /dev/null |
+++ b/test/mjsunit/harmony/collection-iterator.js |
@@ -0,0 +1,177 @@ |
+// Copyright 2014 the V8 project authors. All rights reserved. |
+// Redistribution and use in source and binary forms, with or without |
+// modification, are permitted provided that the following conditions are |
+// met: |
+// |
+// * Redistributions of source code must retain the above copyright |
+// notice, this list of conditions and the following disclaimer. |
+// * Redistributions in binary form must reproduce the above |
+// copyright notice, this list of conditions and the following |
+// disclaimer in the documentation and/or other materials provided |
+// with the distribution. |
+// * Neither the name of Google Inc. nor the names of its |
+// contributors may be used to endorse or promote products derived |
+// from this software without specific prior written permission. |
+// |
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ |
+// Flags: --harmony-collection-iterators --allow-natives-syntax |
+ |
+ |
+(function TestSetIterator() { |
+ var s = new Set; |
+ var iter = s.values(); |
+ assertEquals('Set Iterator', %_ClassOf(iter)); |
+ |
+ var SetIteratorPrototype = iter.__proto__; |
+ assertFalse(SetIteratorPrototype.hasOwnProperty('constructor')); |
+ assertEquals(SetIteratorPrototype.__proto__, Object.prototype); |
+ |
+ var propertyNames = Object.getOwnPropertyNames(SetIteratorPrototype); |
+ assertArrayEquals(['next'], propertyNames); |
+ |
+ assertEquals(new Set().values().__proto__. SetIteratorPrototype); |
+ assertEquals(new Set().entries().__proto__. SetIteratorPrototype); |
+})(); |
+ |
+ |
+(function TestSetIteratorValues() { |
+ var s = new Set; |
+ s.add(1); |
+ s.add(2); |
+ s.add(3); |
+ var iter = s.values(); |
+ |
+ assertEquals({value: 1, done: false}, iter.next()); |
+ assertEquals({value: 2, done: false}, iter.next()); |
+ assertEquals({value: 3, done: false}, iter.next()); |
+ assertEquals({value: undefined, done: true}, iter.next()); |
+ assertEquals({value: undefined, done: true}, iter.next()); |
+})(); |
+ |
+ |
+(function TestSetIteratorEntries() { |
+ var s = new Set; |
+ s.add(1); |
+ s.add(2); |
+ s.add(3); |
+ var iter = s.entries(); |
+ |
+ assertEquals({value: [1, 1], done: false}, iter.next()); |
+ assertEquals({value: [2, 2], done: false}, iter.next()); |
+ assertEquals({value: [3, 3], done: false}, iter.next()); |
+ assertEquals({value: undefined, done: true}, iter.next()); |
+ assertEquals({value: undefined, done: true}, iter.next()); |
+})(); |
+ |
+ |
+(function TestSetInvalidReceiver() { |
+ assertThrows(function() { |
+ Set.prototype.values.call({}); |
+ }, TypeError); |
+ assertThrows(function() { |
+ Set.prototype.entries.call({}); |
+ }, TypeError); |
+})(); |
+ |
+ |
+(function TestSetIteratorInvalidReceiver() { |
+ var iter = new Set().values(); |
+ assertThrows(function() { |
+ iter.next.call({}); |
+ }); |
+})(); |
+ |
+ |
+(function TestMapIterator() { |
+ var m = new Map; |
+ var iter = m.values(); |
+ assertEquals('Map Iterator', %_ClassOf(iter)); |
+ |
+ var MapIteratorPrototype = iter.__proto__; |
+ assertFalse(MapIteratorPrototype.hasOwnProperty('constructor')); |
+ assertEquals(MapIteratorPrototype.__proto__, Object.prototype); |
+ |
+ var propertyNames = Object.getOwnPropertyNames(MapIteratorPrototype); |
+ assertArrayEquals(['next'], propertyNames); |
+ |
+ assertEquals(new Map().values().__proto__. MapIteratorPrototype); |
+ assertEquals(new Map().keys().__proto__. MapIteratorPrototype); |
+ assertEquals(new Map().entries().__proto__. MapIteratorPrototype); |
+})(); |
+ |
+ |
+(function TestMapIteratorValues() { |
+ var m = new Map; |
+ m.set(1, 11); |
+ m.set(2, 22); |
+ m.set(3, 33); |
+ var iter = m.values(); |
+ |
+ assertEquals({value: 11, done: false}, iter.next()); |
+ assertEquals({value: 22, done: false}, iter.next()); |
+ assertEquals({value: 33, done: false}, iter.next()); |
+ assertEquals({value: undefined, done: true}, iter.next()); |
+ assertEquals({value: undefined, done: true}, iter.next()); |
+})(); |
+ |
+ |
+(function TestMapIteratorKeys() { |
+ var m = new Map; |
+ m.set(1, 11); |
+ m.set(2, 22); |
+ m.set(3, 33); |
+ var iter = m.keys(); |
+ |
+ assertEquals({value: 1, done: false}, iter.next()); |
+ assertEquals({value: 2, done: false}, iter.next()); |
+ assertEquals({value: 3, done: false}, iter.next()); |
+ assertEquals({value: undefined, done: true}, iter.next()); |
+ assertEquals({value: undefined, done: true}, iter.next()); |
+})(); |
+ |
+ |
+(function TestMapIteratorEntries() { |
+ var m = new Map; |
+ m.set(1, 11); |
+ m.set(2, 22); |
+ m.set(3, 33); |
+ var iter = m.entries(); |
+ |
+ assertEquals({value: [1, 11], done: false}, iter.next()); |
+ assertEquals({value: [2, 22], done: false}, iter.next()); |
+ assertEquals({value: [3, 33], done: false}, iter.next()); |
+ assertEquals({value: undefined, done: true}, iter.next()); |
+ assertEquals({value: undefined, done: true}, iter.next()); |
+})(); |
+ |
+ |
+(function TestMapInvalidReceiver() { |
+ assertThrows(function() { |
+ Map.prototype.values.call({}); |
+ }, TypeError); |
+ assertThrows(function() { |
+ Map.prototype.keys.call({}); |
+ }, TypeError); |
+ assertThrows(function() { |
+ Map.prototype.entries.call({}); |
+ }, TypeError); |
+})(); |
+ |
+ |
+(function TestMapIteratorInvalidReceiver() { |
+ var iter = new Map().values(); |
+ assertThrows(function() { |
+ iter.next.call({}); |
+ }, TypeError); |
+})(); |