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

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: Apply same changes to MapForEach and SetForEach 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 unified diff | Download patch | Annotate | Revision Log
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 primitive valu e.
242 a = new Array();
243 [1,2].find(function() { a.push(this) }, "");
244 assertTrue(a[0] !== a[1]);
245
246 // Do not create a new object in each function call when receiver is a primiti ve value.
wingo 2014/09/15 09:12:21 80 column limit.
247 a = new Array();
248 [1,2].find(function() { a.push(this) }, {});
249 assertFalse(a[0] !== a[1]);
250
240 })(); 251 })();
241 252
242 // Test exceptions 253 // Test exceptions
243 assertThrows('Array.prototype.find.call(null, function() { })', 254 assertThrows('Array.prototype.find.call(null, function() { })',
244 TypeError); 255 TypeError);
245 assertThrows('Array.prototype.find.call(undefined, function() { })', 256 assertThrows('Array.prototype.find.call(undefined, function() { })',
246 TypeError); 257 TypeError);
247 assertThrows('Array.prototype.find.apply(null, function() { }, [])', 258 assertThrows('Array.prototype.find.apply(null, function() { }, [])',
248 TypeError); 259 TypeError);
249 assertThrows('Array.prototype.find.apply(undefined, function() { }, [])', 260 assertThrows('Array.prototype.find.apply(undefined, function() { }, [])',
(...skipping 21 matching lines...) Expand all
271 282
272 assertThrows('Array.prototype.find.apply({}, null, [])', TypeError); 283 assertThrows('Array.prototype.find.apply({}, null, [])', TypeError);
273 assertThrows('Array.prototype.find.apply({}, undefined, [])', TypeError); 284 assertThrows('Array.prototype.find.apply({}, undefined, [])', TypeError);
274 assertThrows('Array.prototype.find.apply({}, 0, [])', TypeError); 285 assertThrows('Array.prototype.find.apply({}, 0, [])', TypeError);
275 assertThrows('Array.prototype.find.apply({}, true, [])', TypeError); 286 assertThrows('Array.prototype.find.apply({}, true, [])', TypeError);
276 assertThrows('Array.prototype.find.apply({}, false, [])', TypeError); 287 assertThrows('Array.prototype.find.apply({}, false, [])', TypeError);
277 assertThrows('Array.prototype.find.apply({}, "", [])', TypeError); 288 assertThrows('Array.prototype.find.apply({}, "", [])', TypeError);
278 assertThrows('Array.prototype.find.apply({}, {}, [])', TypeError); 289 assertThrows('Array.prototype.find.apply({}, {}, [])', TypeError);
279 assertThrows('Array.prototype.find.apply({}, [], [])', TypeError); 290 assertThrows('Array.prototype.find.apply({}, [], [])', TypeError);
280 assertThrows('Array.prototype.find.apply({}, /\d+/, [])', TypeError); 291 assertThrows('Array.prototype.find.apply({}, /\d+/, [])', TypeError);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698