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

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

Issue 1186733002: Add %TypedArray% to proto chain (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: changes from arv's review 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 | « test/mjsunit/harmony/sharedarraybuffer.js ('k') | test/mjsunit/harmony/typedarrays-of.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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 TestSlice(10, 100, 0.01, 10.96); 114 TestSlice(10, 100, 0.01, 10.96);
115 115
116 TestSlice(10, 100, 90); 116 TestSlice(10, 100, 90);
117 TestSlice(10, 100, -10); 117 TestSlice(10, 100, -10);
118 } 118 }
119 119
120 TestArrayBufferSlice(); 120 TestArrayBufferSlice();
121 121
122 // Typed arrays 122 // Typed arrays
123 123
124 function getPropertyDescriptor(object, field, expectedDepth) {
125 for (var depth = 0; depth < expectedDepth; depth++) {
126 assertFalse(Object.hasOwnProperty(object, field));
127 object = object.__proto__;
128 }
129 return Object.getOwnPropertyDescriptor(object, field);
130 }
131
124 function TestTypedArray(constr, elementSize, typicalElement) { 132 function TestTypedArray(constr, elementSize, typicalElement) {
125 assertSame(elementSize, constr.BYTES_PER_ELEMENT); 133 assertSame(elementSize, constr.BYTES_PER_ELEMENT);
126 134
127 var ab = new ArrayBuffer(256*elementSize); 135 var ab = new ArrayBuffer(256*elementSize);
128 136
129 var a0 = new constr(30); 137 var a0 = new constr(30);
130 assertEquals("[object " + constr.name + "]", 138 assertEquals("[object " + constr.name + "]",
131 Object.prototype.toString.call(a0)); 139 Object.prototype.toString.call(a0));
132 140
133 assertTrue(ArrayBuffer.isView(a0)); 141 assertTrue(ArrayBuffer.isView(a0));
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 270
263 var aNoParam = new constr(); 271 var aNoParam = new constr();
264 assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT); 272 assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT);
265 assertSame(0, aNoParam.length); 273 assertSame(0, aNoParam.length);
266 assertSame(0, aNoParam.byteLength); 274 assertSame(0, aNoParam.byteLength);
267 assertSame(0, aNoParam.byteOffset); 275 assertSame(0, aNoParam.byteOffset);
268 276
269 var a = new constr(ab, 64*elementSize, 128); 277 var a = new constr(ab, 64*elementSize, 128);
270 assertEquals("[object " + constr.name + "]", 278 assertEquals("[object " + constr.name + "]",
271 Object.prototype.toString.call(a)); 279 Object.prototype.toString.call(a));
272 var desc = Object.getOwnPropertyDescriptor( 280 var desc = getPropertyDescriptor(constr.prototype, Symbol.toStringTag, 1);
273 constr.prototype, Symbol.toStringTag);
274 assertTrue(desc.configurable); 281 assertTrue(desc.configurable);
275 assertFalse(desc.enumerable); 282 assertFalse(desc.enumerable);
276 assertFalse(!!desc.writable); 283 assertFalse(!!desc.writable);
277 assertFalse(!!desc.set); 284 assertFalse(!!desc.set);
278 assertEquals("function", typeof desc.get); 285 assertEquals("function", typeof desc.get);
279 286
280 // Test that the constructor can be called with an iterable 287 // Test that the constructor can be called with an iterable
281 function* gen() { for (var i = 0; i < 10; i++) yield i; } 288 function* gen() { for (var i = 0; i < 10; i++) yield i; }
282 var genArr = new constr(gen()); 289 var genArr = new constr(gen());
283 assertEquals(10, genArr.length); 290 assertEquals(10, genArr.length);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 Uint16Array, 417 Uint16Array,
411 Int16Array, 418 Int16Array,
412 Uint32Array, 419 Uint32Array,
413 Int32Array, 420 Int32Array,
414 Uint8ClampedArray, 421 Uint8ClampedArray,
415 Float32Array, 422 Float32Array,
416 Float64Array]; 423 Float64Array];
417 424
418 function TestPropertyTypeChecks(constructor) { 425 function TestPropertyTypeChecks(constructor) {
419 function CheckProperty(name) { 426 function CheckProperty(name) {
420 var d = Object.getOwnPropertyDescriptor(constructor.prototype, name); 427 var d = getPropertyDescriptor(constructor.prototype, name, 1);
421 var o = {}; 428 var o = {};
422 assertThrows(function() {d.get.call(o);}, TypeError); 429 assertThrows(function() {d.get.call(o);}, TypeError);
423 for (var i = 0; i < typedArrayConstructors.length; i++) { 430 for (var i = 0; i < typedArrayConstructors.length; i++) {
424 var ctor = typedArrayConstructors[i]; 431 var ctor = typedArrayConstructors[i];
425 var a = new ctor(10); 432 var a = new ctor(10);
426 if (ctor === constructor) { 433 d.get.call(a); // shouldn't throw, even from a different type
427 d.get.call(a); // shouldn't throw
428 } else {
429 assertThrows(function() {d.get.call(a);}, TypeError);
430 }
431 } 434 }
432 } 435 }
433 436
434 CheckProperty("buffer"); 437 CheckProperty("buffer");
435 CheckProperty("byteOffset"); 438 CheckProperty("byteOffset");
436 CheckProperty("byteLength"); 439 CheckProperty("byteLength");
437 CheckProperty("length"); 440 CheckProperty("length");
438 } 441 }
439 442
440 for(i = 0; i < typedArrayConstructors.length; i++) { 443 for(i = 0; i < typedArrayConstructors.length; i++) {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 TestArbitrary(new ArrayBuffer(256)); 752 TestArbitrary(new ArrayBuffer(256));
750 for(i = 0; i < typedArrayConstructors.length; i++) { 753 for(i = 0; i < typedArrayConstructors.length; i++) {
751 TestArbitrary(new typedArrayConstructors[i](10)); 754 TestArbitrary(new typedArrayConstructors[i](10));
752 } 755 }
753 TestArbitrary(new DataView(new ArrayBuffer(256))); 756 TestArbitrary(new DataView(new ArrayBuffer(256)));
754 757
755 758
756 // Test direct constructor call 759 // Test direct constructor call
757 assertThrows(function() { ArrayBuffer(); }, TypeError); 760 assertThrows(function() { ArrayBuffer(); }, TypeError);
758 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); 761 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError);
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/sharedarraybuffer.js ('k') | test/mjsunit/harmony/typedarrays-of.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698