// (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: --expose-gc --allow-natives-syntax
+// Flags: --expose-gc --allow-natives-syntax --harmony-tostring
function assertSize(expected, collection) {
function TestPrototype(C) {
assertTrue(C.prototype instanceof Object);
assertEquals({
- value: {},
+ value: C.prototype,
writable: false,
enumerable: false,
configurable: false
assertEquals(4950, accumulated);
})();
+
+(function TestSetForEachReceiverAsObject() {
+ var set = new Set(["1", "2"]);
+
+ // Create a new object in each function call when receiver is a
+ // primitive value. See ECMA-262, Annex C.
+ var a = [];
+ set.forEach(function() { a.push(this) }, "");
+ assertTrue(a[0] !== a[1]);
+
+ // Do not create a new object otherwise.
+ a = [];
+ set.forEach(function() { a.push(this); }, {});
+ assertEquals(a[0], a[1]);
+})();
+
+
+(function TestSetForEachReceiverAsObjectInStrictMode() {
+ var set = new Set(["1", "2"]);
+
+ // In strict mode primitive values should not be coerced to an object.
+ var a = [];
+ set.forEach(function() { 'use strict'; a.push(this); }, "");
+ assertTrue(a[0] === "" && a[0] === a[1]);
+})();
+
+
(function TestMapForEachInvalidTypes() {
assertThrows(function() {
Map.prototype.map.forEach.call({});
})();
+(function TestMapForEachReceiverAsObject() {
+ var map = new Map();
+ map.set("key1", "value1");
+ map.set("key2", "value2");
+
+ // Create a new object in each function call when receiver is a
+ // primitive value. See ECMA-262, Annex C.
+ var a = [];
+ map.forEach(function() { a.push(this) }, "");
+ assertTrue(a[0] !== a[1]);
+
+ // Do not create a new object otherwise.
+ a = [];
+ map.forEach(function() { a.push(this); }, {});
+ assertEquals(a[0], a[1]);
+})();
+
+
+(function TestMapForEachReceiverAsObjectInStrictMode() {
+ var map = new Map();
+ map.set("key1", "value1");
+ map.set("key2", "value2");
+
+ // In strict mode primitive values should not be coerced to an object.
+ var a = [];
+ map.forEach(function() { 'use strict'; a.push(this); }, "");
+ assertTrue(a[0] === "" && a[0] === a[1]);
+})();
+
+
// Allows testing iterator-based constructors easily.
var oneAndTwo = new Map();
var k0 = {key: 0};
}
TestMapConstructorIterableValue(Map);
TestMapConstructorIterableValue(WeakMap);
+
+function TestCollectionToString(C) {
+ assertEquals("[object " + C.name + "]",
+ Object.prototype.toString.call(new C()));
+}
+TestCollectionToString(Map);
+TestCollectionToString(Set);
+TestCollectionToString(WeakMap);
+TestCollectionToString(WeakSet);