2014-06-03 00:34:01 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2016-03-11 18:19:05 +00:00
|
|
|
// Flags: --allow-natives-syntax
|
2014-06-03 00:34:01 +00:00
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
function test(f) {
|
2019-04-30 13:39:53 +00:00
|
|
|
%PrepareFunctionForOptimization(f);
|
2017-07-14 05:35:21 +00:00
|
|
|
f();
|
|
|
|
f();
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
|
|
|
|
test(function TestSetIterator() {
|
2014-06-03 00:34:01 +00:00
|
|
|
var s = new Set;
|
|
|
|
var iter = s.values();
|
|
|
|
|
|
|
|
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);
|
2014-10-24 19:28:23 +00:00
|
|
|
|
|
|
|
assertEquals("[object Set Iterator]",
|
|
|
|
Object.prototype.toString.call(iter));
|
|
|
|
assertEquals("Set Iterator", SetIteratorPrototype[Symbol.toStringTag]);
|
|
|
|
var desc = Object.getOwnPropertyDescriptor(
|
|
|
|
SetIteratorPrototype, Symbol.toStringTag);
|
|
|
|
assertTrue(desc.configurable);
|
|
|
|
assertFalse(desc.writable);
|
|
|
|
assertEquals("Set Iterator", desc.value);
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestSetIteratorValues() {
|
2014-06-03 00:34:01 +00:00
|
|
|
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());
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestSetIteratorKeys() {
|
2014-06-30 14:37:07 +00:00
|
|
|
assertEquals(Set.prototype.keys, Set.prototype.values);
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-30 14:37:07 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestSetIteratorEntries() {
|
2014-06-03 00:34:01 +00:00
|
|
|
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());
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestSetIteratorMutations() {
|
2014-06-03 00:34:01 +00:00
|
|
|
var s = new Set;
|
|
|
|
s.add(1);
|
|
|
|
var iter = s.values();
|
|
|
|
assertEquals({value: 1, done: false}, iter.next());
|
|
|
|
s.add(2);
|
|
|
|
s.add(3);
|
|
|
|
s.add(4);
|
|
|
|
s.add(5);
|
|
|
|
assertEquals({value: 2, done: false}, iter.next());
|
|
|
|
s.delete(3);
|
|
|
|
assertEquals({value: 4, done: false}, iter.next());
|
|
|
|
s.delete(5);
|
|
|
|
assertEquals({value: undefined, done: true}, iter.next());
|
|
|
|
s.add(4);
|
|
|
|
assertEquals({value: undefined, done: true}, iter.next());
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestSetIteratorMutations2() {
|
2017-07-10 06:46:56 +00:00
|
|
|
var s = new Set;
|
|
|
|
s.add(1);
|
|
|
|
s.add(2);
|
|
|
|
var i = s.values();
|
|
|
|
assertEquals({value: 1, done: false}, i.next());
|
|
|
|
s.delete(2);
|
|
|
|
s.delete(1);
|
|
|
|
s.add(2);
|
|
|
|
assertEquals({value: 2, done: false}, i.next());
|
|
|
|
assertEquals({value: undefined, done: true}, i.next());
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2017-07-10 06:46:56 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestSetIteratorMutations3() {
|
2017-07-10 06:46:56 +00:00
|
|
|
var s = new Set;
|
|
|
|
s.add(1);
|
|
|
|
s.add(2);
|
|
|
|
var i = s.values();
|
|
|
|
assertEquals({value: 1, done: false}, i.next());
|
|
|
|
s.delete(2);
|
|
|
|
s.delete(1);
|
|
|
|
for (var x = 2; x < 500; ++x) s.add(x);
|
|
|
|
for (var x = 2; x < 500; ++x) s.delete(x);
|
|
|
|
for (var x = 2; x < 1000; ++x) s.add(x);
|
|
|
|
assertEquals({value: 2, done: false}, i.next());
|
|
|
|
for (var x = 1001; x < 2000; ++x) s.add(x);
|
|
|
|
s.delete(3);
|
|
|
|
for (var x = 6; x < 2000; ++x) s.delete(x);
|
|
|
|
assertEquals({value: 4, done: false}, i.next());
|
|
|
|
s.delete(5);
|
|
|
|
assertEquals({value: undefined, done: true}, i.next());
|
|
|
|
s.add(4);
|
|
|
|
assertEquals({value: undefined, done: true}, i.next());
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2017-07-10 06:46:56 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestSetInvalidReceiver() {
|
2014-06-03 00:34:01 +00:00
|
|
|
assertThrows(function() {
|
|
|
|
Set.prototype.values.call({});
|
|
|
|
}, TypeError);
|
|
|
|
assertThrows(function() {
|
|
|
|
Set.prototype.entries.call({});
|
|
|
|
}, TypeError);
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestSetIteratorInvalidReceiver() {
|
2014-06-03 00:34:01 +00:00
|
|
|
var iter = new Set().values();
|
|
|
|
assertThrows(function() {
|
|
|
|
iter.next.call({});
|
|
|
|
});
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestSetIteratorSymbol() {
|
2014-06-03 00:34:01 +00:00
|
|
|
assertEquals(Set.prototype[Symbol.iterator], Set.prototype.values);
|
|
|
|
assertTrue(Set.prototype.hasOwnProperty(Symbol.iterator));
|
|
|
|
assertFalse(Set.prototype.propertyIsEnumerable(Symbol.iterator));
|
|
|
|
|
|
|
|
var iter = new Set().values();
|
|
|
|
assertEquals(iter, iter[Symbol.iterator]());
|
|
|
|
assertEquals(iter[Symbol.iterator].name, '[Symbol.iterator]');
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestMapIterator() {
|
2014-06-03 00:34:01 +00:00
|
|
|
var m = new Map;
|
|
|
|
var iter = m.values();
|
|
|
|
|
|
|
|
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);
|
2014-10-24 19:28:23 +00:00
|
|
|
|
|
|
|
assertEquals("[object Map Iterator]",
|
|
|
|
Object.prototype.toString.call(iter));
|
|
|
|
assertEquals("Map Iterator", MapIteratorPrototype[Symbol.toStringTag]);
|
|
|
|
var desc = Object.getOwnPropertyDescriptor(
|
|
|
|
MapIteratorPrototype, Symbol.toStringTag);
|
|
|
|
assertTrue(desc.configurable);
|
|
|
|
assertFalse(desc.writable);
|
|
|
|
assertEquals("Map Iterator", desc.value);
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestMapIteratorValues() {
|
2014-06-03 00:34:01 +00:00
|
|
|
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());
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestMapIteratorKeys() {
|
2014-06-03 00:34:01 +00:00
|
|
|
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());
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestMapIteratorEntries() {
|
2014-06-03 00:34:01 +00:00
|
|
|
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());
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestMapInvalidReceiver() {
|
2014-06-03 00:34:01 +00:00
|
|
|
assertThrows(function() {
|
|
|
|
Map.prototype.values.call({});
|
|
|
|
}, TypeError);
|
|
|
|
assertThrows(function() {
|
|
|
|
Map.prototype.keys.call({});
|
|
|
|
}, TypeError);
|
|
|
|
assertThrows(function() {
|
|
|
|
Map.prototype.entries.call({});
|
|
|
|
}, TypeError);
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestMapIteratorInvalidReceiver() {
|
2014-06-03 00:34:01 +00:00
|
|
|
var iter = new Map().values();
|
|
|
|
assertThrows(function() {
|
|
|
|
iter.next.call({});
|
|
|
|
}, TypeError);
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|
2014-06-03 00:34:01 +00:00
|
|
|
|
|
|
|
|
2017-07-14 05:35:21 +00:00
|
|
|
test(function TestMapIteratorSymbol() {
|
2014-06-03 00:34:01 +00:00
|
|
|
assertEquals(Map.prototype[Symbol.iterator], Map.prototype.entries);
|
|
|
|
assertTrue(Map.prototype.hasOwnProperty(Symbol.iterator));
|
|
|
|
assertFalse(Map.prototype.propertyIsEnumerable(Symbol.iterator));
|
|
|
|
|
|
|
|
var iter = new Map().values();
|
|
|
|
assertEquals(iter, iter[Symbol.iterator]());
|
|
|
|
assertEquals(iter[Symbol.iterator].name, '[Symbol.iterator]');
|
2017-07-14 05:35:21 +00:00
|
|
|
});
|