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

Unified Diff: test/mjsunit/array-iteration.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: Remove unnecessary is_null_or_undefined check Created 6 years, 3 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 | « src/macros.py ('k') | test/mjsunit/es6/collections.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/array-iteration.js
diff --git a/test/mjsunit/array-iteration.js b/test/mjsunit/array-iteration.js
index d11f984bee43be0a7e54794c52d2e05421bd74bb..1acffbf8cd8476f66ab64f4b9382cd5333e3fd93 100644
--- a/test/mjsunit/array-iteration.js
+++ b/test/mjsunit/array-iteration.js
@@ -68,6 +68,22 @@
assertEquals(3, count);
for (var i in a) assertEquals(2, a[i]);
+ // Create a new object in each function call when receiver is a
+ // primitive value. See ECMA-262, Annex C.
+ a = [];
+ [1, 2].filter(function() { a.push(this) }, "");
+ assertTrue(a[0] !== a[1]);
+
+ // Do not create a new object otherwise.
+ a = [];
+ [1, 2].filter(function() { a.push(this) }, {});
+ assertFalse(a[0] !== a[1]);
arv (Not doing code reviews) 2014/10/14 15:55:33 assertEquals
+
+ // In strict mode primitive values should not be coerced to an object.
+ a = [];
+ [1, 2].filter(function() { 'use strict'; a.push(this); }, "");
+ assertTrue(a[0] === "" && a[0] === a[1]);
arv (Not doing code reviews) 2014/10/14 15:55:33 assertEquals(a[0], a[1]); assertEquals(a[0], "");
+
})();
@@ -109,6 +125,22 @@
a.forEach(function(n) { count++; });
assertEquals(1, count);
+ // Create a new object in each function call when receiver is a
+ // primitive value. See ECMA-262, Annex C.
+ a = [];
+ [1, 2].forEach(function() { a.push(this) }, "");
+ assertTrue(a[0] !== a[1]);
+
+ // Do not create a new object otherwise.
+ a = [];
+ [1, 2].forEach(function() { a.push(this) }, {});
+ assertFalse(a[0] !== a[1]);
arv (Not doing code reviews) 2014/10/14 15:55:33 same here and elsewhere.
+
+ // In strict mode primitive values should not be coerced to an object.
+ a = [];
+ [1, 2].forEach(function() { 'use strict'; a.push(this); }, "");
+ assertTrue(a[0] === "" && a[0] === a[1]);
+
})();
@@ -149,6 +181,22 @@
assertTrue(a.every(function(n) { count++; return n == 2; }));
assertEquals(2, count);
+ // Create a new object in each function call when receiver is a
+ // primitive value. See ECMA-262, Annex C.
+ a = [];
+ [1, 2].every(function() { a.push(this); return true; }, "");
+ assertTrue(a[0] !== a[1]);
+
+ // Do not create a new object otherwise.
+ a = [];
+ [1, 2].every(function() { a.push(this); return true; }, {});
+ assertFalse(a[0] !== a[1]);
+
+ // In strict mode primitive values should not be coerced to an object.
+ a = [];
+ [1, 2].every(function() { 'use strict'; a.push(this); return true; }, "");
+ assertTrue(a[0] === "" && a[0] === a[1]);
+
})();
//
@@ -186,6 +234,22 @@
a = a.map(function(n) { return 2*n; });
for (var i in a) assertEquals(4, a[i]);
+ // Create a new object in each function call when receiver is a
+ // primitive value. See ECMA-262, Annex C.
+ a = [];
+ [1, 2].map(function() { a.push(this) }, "");
+ assertTrue(a[0] !== a[1]);
+
+ // Do not create a new object otherwise.
+ a = [];
+ [1, 2].map(function() { a.push(this) }, {});
+ assertFalse(a[0] !== a[1]);
+
+ // In strict mode primitive values should not be coerced to an object.
+ a = [];
+ [1, 2].map(function() { 'use strict'; a.push(this); }, "");
+ assertTrue(a[0] === "" && a[0] === a[1]);
+
})();
//
@@ -224,4 +288,20 @@
assertTrue(a.some(function(n) { count++; return n == 2; }));
assertEquals(2, count);
+ // Create a new object in each function call when receiver is a
+ // primitive value. See ECMA-262, Annex C.
+ a = [];
+ [1, 2].some(function() { a.push(this) }, "");
+ assertTrue(a[0] !== a[1]);
+
+ // Do not create a new object otherwise.
+ a = [];
+ [1, 2].some(function() { a.push(this) }, {});
+ assertFalse(a[0] !== a[1]);
+
+ // In strict mode primitive values should not be coerced to an object.
+ a = [];
+ [1, 2].some(function() { 'use strict'; a.push(this); }, "");
+ assertTrue(a[0] === "" && a[0] === a[1]);
+
})();
« no previous file with comments | « src/macros.py ('k') | test/mjsunit/es6/collections.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698