Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1062)

Unified Diff: test/mjsunit/es6/collections.js

Issue 553413002: Array.prototype.{every, filter, find, findIndex, forEach, map, some}: Use fresh primitive wrapper f… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed nits from last patch. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/array-iteration.js ('k') | test/mjsunit/harmony/array-find.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/es6/collections.js
diff --git a/test/mjsunit/es6/collections.js b/test/mjsunit/es6/collections.js
index 940c0b9d1fab8a314b071e9d5cd6d50fab4cd41d..94b2aea12b49ef598bd5dbc1d10a79068fab5dcc 100644
--- a/test/mjsunit/es6/collections.js
+++ b/test/mjsunit/es6/collections.js
@@ -691,6 +691,33 @@ for (var i = 9; i >= 0; i--) {
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({});
@@ -998,6 +1025,36 @@ for (var i = 9; i >= 0; i--) {
})();
+(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};
« no previous file with comments | « test/mjsunit/array-iteration.js ('k') | test/mjsunit/harmony/array-find.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698