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

Side by Side Diff: test/mjsunit/harmony/typedarrays.js

Issue 1181903003: Allow TypedArrays to be initialized with iterables (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixes from arv's comments Created 5 years, 6 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
« no previous file with comments | « src/typedarray.js ('k') | no next file » | 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 var a = new constr(ab, 64*elementSize, 128); 269 var a = new constr(ab, 64*elementSize, 128);
270 assertEquals("[object " + constr.name + "]", 270 assertEquals("[object " + constr.name + "]",
271 Object.prototype.toString.call(a)); 271 Object.prototype.toString.call(a));
272 var desc = Object.getOwnPropertyDescriptor( 272 var desc = Object.getOwnPropertyDescriptor(
273 constr.prototype, Symbol.toStringTag); 273 constr.prototype, Symbol.toStringTag);
274 assertTrue(desc.configurable); 274 assertTrue(desc.configurable);
275 assertFalse(desc.enumerable); 275 assertFalse(desc.enumerable);
276 assertFalse(!!desc.writable); 276 assertFalse(!!desc.writable);
277 assertFalse(!!desc.set); 277 assertFalse(!!desc.set);
278 assertEquals("function", typeof desc.get); 278 assertEquals("function", typeof desc.get);
279
280 // Test that the constructor can be called with an iterable
281 function* gen() { for (var i = 0; i < 10; i++) yield i; }
282 var genArr = new constr(gen());
283 assertEquals(10, genArr.length);
284 assertEquals(0, genArr[0]);
285 assertEquals(9, genArr[9]);
286 // Arrays can be converted to TypedArrays
287 genArr = new constr([1, 2, 3]);
288 assertEquals(3, genArr.length);
289 assertEquals(1, genArr[0]);
290 assertEquals(3, genArr[2]);
291 // Redefining Array.prototype[Symbol.iterator] still works
292 var arrayIterator = Array.prototype[Symbol.iterator];
293 Array.prototype[Symbol.iterator] = gen;
294 genArr = new constr([1, 2, 3]);
295 assertEquals(10, genArr.length);
296 assertEquals(0, genArr[0]);
297 assertEquals(9, genArr[9]);
298 Array.prototype[Symbol.iterator] = arrayIterator;
299 // Other array-like things can be made into a TypedArray
300 var myObject = { 0: 5, 1: 6, length: 2 };
301 genArr = new constr(myObject);
302 assertEquals(2, genArr.length);
303 assertEquals(5, genArr[0]);
304 assertEquals(6, genArr[1]);
305 // Iterator takes precedence over array-like, and the property
306 // is read only once.
307 var iteratorReadCount = 0;
308 Object.defineProperty(myObject, Symbol.iterator, {
309 get: function() { iteratorReadCount++; return gen; }
310 });
311 genArr = new constr(myObject);
312 assertEquals(10, genArr.length);
313 assertEquals(0, genArr[0]);
314 assertEquals(9, genArr[9]);
315 assertEquals(1, iteratorReadCount);
279 } 316 }
280 317
281 TestTypedArray(Uint8Array, 1, 0xFF); 318 TestTypedArray(Uint8Array, 1, 0xFF);
282 TestTypedArray(Int8Array, 1, -0x7F); 319 TestTypedArray(Int8Array, 1, -0x7F);
283 TestTypedArray(Uint16Array, 2, 0xFFFF); 320 TestTypedArray(Uint16Array, 2, 0xFFFF);
284 TestTypedArray(Int16Array, 2, -0x7FFF); 321 TestTypedArray(Int16Array, 2, -0x7FFF);
285 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF); 322 TestTypedArray(Uint32Array, 4, 0xFFFFFFFF);
286 TestTypedArray(Int32Array, 4, -0x7FFFFFFF); 323 TestTypedArray(Int32Array, 4, -0x7FFFFFFF);
287 TestTypedArray(Float32Array, 4, 0.5); 324 TestTypedArray(Float32Array, 4, 0.5);
288 TestTypedArray(Float64Array, 8, 0.5); 325 TestTypedArray(Float64Array, 8, 0.5);
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 TestArbitrary(new ArrayBuffer(256)); 749 TestArbitrary(new ArrayBuffer(256));
713 for(i = 0; i < typedArrayConstructors.length; i++) { 750 for(i = 0; i < typedArrayConstructors.length; i++) {
714 TestArbitrary(new typedArrayConstructors[i](10)); 751 TestArbitrary(new typedArrayConstructors[i](10));
715 } 752 }
716 TestArbitrary(new DataView(new ArrayBuffer(256))); 753 TestArbitrary(new DataView(new ArrayBuffer(256)));
717 754
718 755
719 // Test direct constructor call 756 // Test direct constructor call
720 assertThrows(function() { ArrayBuffer(); }, TypeError); 757 assertThrows(function() { ArrayBuffer(); }, TypeError);
721 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); 758 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError);
OLDNEW
« no previous file with comments | « src/typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698