Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) { | |
|
adamk
2015/06/13 00:49:38
And here.
Maybe I'm missing something as to why t
| |
| 125 var descriptor; | |
| 126 while (descriptor === undefined && object !== Object.prototype) { | |
| 127 descriptor = Object.getOwnPropertyDescriptor(object, field); | |
| 128 object = object.__proto__; | |
| 129 } | |
| 130 return descriptor; | |
| 131 } | |
| 132 | |
| 124 function TestTypedArray(constr, elementSize, typicalElement) { | 133 function TestTypedArray(constr, elementSize, typicalElement) { |
| 125 assertSame(elementSize, constr.BYTES_PER_ELEMENT); | 134 assertSame(elementSize, constr.BYTES_PER_ELEMENT); |
| 126 | 135 |
| 127 var ab = new ArrayBuffer(256*elementSize); | 136 var ab = new ArrayBuffer(256*elementSize); |
| 128 | 137 |
| 129 var a0 = new constr(30); | 138 var a0 = new constr(30); |
| 130 assertEquals("[object " + constr.name + "]", | 139 assertEquals("[object " + constr.name + "]", |
| 131 Object.prototype.toString.call(a0)); | 140 Object.prototype.toString.call(a0)); |
| 132 | 141 |
| 133 assertTrue(ArrayBuffer.isView(a0)); | 142 assertTrue(ArrayBuffer.isView(a0)); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 | 271 |
| 263 var aNoParam = new constr(); | 272 var aNoParam = new constr(); |
| 264 assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT); | 273 assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT); |
| 265 assertSame(0, aNoParam.length); | 274 assertSame(0, aNoParam.length); |
| 266 assertSame(0, aNoParam.byteLength); | 275 assertSame(0, aNoParam.byteLength); |
| 267 assertSame(0, aNoParam.byteOffset); | 276 assertSame(0, aNoParam.byteOffset); |
| 268 | 277 |
| 269 var a = new constr(ab, 64*elementSize, 128); | 278 var a = new constr(ab, 64*elementSize, 128); |
| 270 assertEquals("[object " + constr.name + "]", | 279 assertEquals("[object " + constr.name + "]", |
| 271 Object.prototype.toString.call(a)); | 280 Object.prototype.toString.call(a)); |
| 272 var desc = Object.getOwnPropertyDescriptor( | 281 var desc = GetPropertyDescriptor(constr.prototype, Symbol.toStringTag); |
| 273 constr.prototype, Symbol.toStringTag); | |
| 274 assertTrue(desc.configurable); | 282 assertTrue(desc.configurable); |
| 275 assertFalse(desc.enumerable); | 283 assertFalse(desc.enumerable); |
| 276 assertFalse(!!desc.writable); | 284 assertFalse(!!desc.writable); |
| 277 assertFalse(!!desc.set); | 285 assertFalse(!!desc.set); |
| 278 assertEquals("function", typeof desc.get); | 286 assertEquals("function", typeof desc.get); |
| 279 } | 287 } |
| 280 | 288 |
| 281 TestTypedArray(Uint8Array, 1, 0xFF); | 289 TestTypedArray(Uint8Array, 1, 0xFF); |
| 282 TestTypedArray(Int8Array, 1, -0x7F); | 290 TestTypedArray(Int8Array, 1, -0x7F); |
| 283 TestTypedArray(Uint16Array, 2, 0xFFFF); | 291 TestTypedArray(Uint16Array, 2, 0xFFFF); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 Uint16Array, | 381 Uint16Array, |
| 374 Int16Array, | 382 Int16Array, |
| 375 Uint32Array, | 383 Uint32Array, |
| 376 Int32Array, | 384 Int32Array, |
| 377 Uint8ClampedArray, | 385 Uint8ClampedArray, |
| 378 Float32Array, | 386 Float32Array, |
| 379 Float64Array]; | 387 Float64Array]; |
| 380 | 388 |
| 381 function TestPropertyTypeChecks(constructor) { | 389 function TestPropertyTypeChecks(constructor) { |
| 382 function CheckProperty(name) { | 390 function CheckProperty(name) { |
| 383 var d = Object.getOwnPropertyDescriptor(constructor.prototype, name); | 391 var d = GetPropertyDescriptor(constructor.prototype, name); |
| 384 var o = {}; | 392 var o = {}; |
| 385 assertThrows(function() {d.get.call(o);}, TypeError); | 393 assertThrows(function() {d.get.call(o);}, TypeError); |
| 386 for (var i = 0; i < typedArrayConstructors.length; i++) { | 394 for (var i = 0; i < typedArrayConstructors.length; i++) { |
| 387 var ctor = typedArrayConstructors[i]; | 395 var ctor = typedArrayConstructors[i]; |
| 388 var a = new ctor(10); | 396 var a = new ctor(10); |
| 389 if (ctor === constructor) { | 397 d.get.call(a); // shouldn't throw, even from a different type |
| 390 d.get.call(a); // shouldn't throw | |
| 391 } else { | |
| 392 assertThrows(function() {d.get.call(a);}, TypeError); | |
| 393 } | |
| 394 } | 398 } |
| 395 } | 399 } |
| 396 | 400 |
| 397 CheckProperty("buffer"); | 401 CheckProperty("buffer"); |
| 398 CheckProperty("byteOffset"); | 402 CheckProperty("byteOffset"); |
| 399 CheckProperty("byteLength"); | 403 CheckProperty("byteLength"); |
| 400 CheckProperty("length"); | 404 CheckProperty("length"); |
| 401 } | 405 } |
| 402 | 406 |
| 403 for(i = 0; i < typedArrayConstructors.length; i++) { | 407 for(i = 0; i < typedArrayConstructors.length; i++) { |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 TestArbitrary(new ArrayBuffer(256)); | 716 TestArbitrary(new ArrayBuffer(256)); |
| 713 for(i = 0; i < typedArrayConstructors.length; i++) { | 717 for(i = 0; i < typedArrayConstructors.length; i++) { |
| 714 TestArbitrary(new typedArrayConstructors[i](10)); | 718 TestArbitrary(new typedArrayConstructors[i](10)); |
| 715 } | 719 } |
| 716 TestArbitrary(new DataView(new ArrayBuffer(256))); | 720 TestArbitrary(new DataView(new ArrayBuffer(256))); |
| 717 | 721 |
| 718 | 722 |
| 719 // Test direct constructor call | 723 // Test direct constructor call |
| 720 assertThrows(function() { ArrayBuffer(); }, TypeError); | 724 assertThrows(function() { ArrayBuffer(); }, TypeError); |
| 721 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); | 725 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); |
| OLD | NEW |