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

Side by Side Diff: test/mjsunit/harmony/array-find.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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/es6/collections.js ('k') | test/mjsunit/harmony/array-findindex.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 elementAt: function(key) { 230 elementAt: function(key) {
231 return this[key]; 231 return this[key];
232 } 232 }
233 }; 233 };
234 Array.prototype.push.apply(thisArg, ["c", "b", "a"]); 234 Array.prototype.push.apply(thisArg, ["c", "b", "a"]);
235 235
236 found = ["a", "b", "c"].find(function(val, key) { 236 found = ["a", "b", "c"].find(function(val, key) {
237 return this.elementAt(key) === val; 237 return this.elementAt(key) === val;
238 }, thisArg); 238 }, thisArg);
239 assertEquals("b", found); 239 assertEquals("b", found);
240
241 // Create a new object in each function call when receiver is a
242 // primitive value. See ECMA-262, Annex C.
243 a = [];
244 [1, 2].find(function() { a.push(this) }, "");
245 assertTrue(a[0] !== a[1]);
246
247 // Do not create a new object otherwise.
248 a = [];
249 [1, 2].find(function() { a.push(this) }, {});
250 assertEquals(a[0], a[1]);
251
252 // In strict mode primitive values should not be coerced to an object.
253 a = [];
254 [1, 2].find(function() { 'use strict'; a.push(this); }, "");
255 assertEquals("", a[0]);
256 assertEquals(a[0], a[1]);
257
240 })(); 258 })();
241 259
242 // Test exceptions 260 // Test exceptions
243 assertThrows('Array.prototype.find.call(null, function() { })', 261 assertThrows('Array.prototype.find.call(null, function() { })',
244 TypeError); 262 TypeError);
245 assertThrows('Array.prototype.find.call(undefined, function() { })', 263 assertThrows('Array.prototype.find.call(undefined, function() { })',
246 TypeError); 264 TypeError);
247 assertThrows('Array.prototype.find.apply(null, function() { }, [])', 265 assertThrows('Array.prototype.find.apply(null, function() { }, [])',
248 TypeError); 266 TypeError);
249 assertThrows('Array.prototype.find.apply(undefined, function() { }, [])', 267 assertThrows('Array.prototype.find.apply(undefined, function() { }, [])',
(...skipping 21 matching lines...) Expand all
271 289
272 assertThrows('Array.prototype.find.apply({}, null, [])', TypeError); 290 assertThrows('Array.prototype.find.apply({}, null, [])', TypeError);
273 assertThrows('Array.prototype.find.apply({}, undefined, [])', TypeError); 291 assertThrows('Array.prototype.find.apply({}, undefined, [])', TypeError);
274 assertThrows('Array.prototype.find.apply({}, 0, [])', TypeError); 292 assertThrows('Array.prototype.find.apply({}, 0, [])', TypeError);
275 assertThrows('Array.prototype.find.apply({}, true, [])', TypeError); 293 assertThrows('Array.prototype.find.apply({}, true, [])', TypeError);
276 assertThrows('Array.prototype.find.apply({}, false, [])', TypeError); 294 assertThrows('Array.prototype.find.apply({}, false, [])', TypeError);
277 assertThrows('Array.prototype.find.apply({}, "", [])', TypeError); 295 assertThrows('Array.prototype.find.apply({}, "", [])', TypeError);
278 assertThrows('Array.prototype.find.apply({}, {}, [])', TypeError); 296 assertThrows('Array.prototype.find.apply({}, {}, [])', TypeError);
279 assertThrows('Array.prototype.find.apply({}, [], [])', TypeError); 297 assertThrows('Array.prototype.find.apply({}, [], [])', TypeError);
280 assertThrows('Array.prototype.find.apply({}, /\d+/, [])', TypeError); 298 assertThrows('Array.prototype.find.apply({}, /\d+/, [])', TypeError);
OLDNEW
« no previous file with comments | « test/mjsunit/es6/collections.js ('k') | test/mjsunit/harmony/array-findindex.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698