| 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, 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 | |
| 132 function TestTypedArray(constr, elementSize, typicalElement) { | 124 function TestTypedArray(constr, elementSize, typicalElement) { |
| 133 assertSame(elementSize, constr.BYTES_PER_ELEMENT); | 125 assertSame(elementSize, constr.BYTES_PER_ELEMENT); |
| 134 | 126 |
| 135 var ab = new ArrayBuffer(256*elementSize); | 127 var ab = new ArrayBuffer(256*elementSize); |
| 136 | 128 |
| 137 var a0 = new constr(30); | 129 var a0 = new constr(30); |
| 138 assertEquals("[object " + constr.name + "]", | 130 assertEquals("[object " + constr.name + "]", |
| 139 Object.prototype.toString.call(a0)); | 131 Object.prototype.toString.call(a0)); |
| 140 | 132 |
| 141 assertTrue(ArrayBuffer.isView(a0)); | 133 assertTrue(ArrayBuffer.isView(a0)); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 262 |
| 271 var aNoParam = new constr(); | 263 var aNoParam = new constr(); |
| 272 assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT); | 264 assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT); |
| 273 assertSame(0, aNoParam.length); | 265 assertSame(0, aNoParam.length); |
| 274 assertSame(0, aNoParam.byteLength); | 266 assertSame(0, aNoParam.byteLength); |
| 275 assertSame(0, aNoParam.byteOffset); | 267 assertSame(0, aNoParam.byteOffset); |
| 276 | 268 |
| 277 var a = new constr(ab, 64*elementSize, 128); | 269 var a = new constr(ab, 64*elementSize, 128); |
| 278 assertEquals("[object " + constr.name + "]", | 270 assertEquals("[object " + constr.name + "]", |
| 279 Object.prototype.toString.call(a)); | 271 Object.prototype.toString.call(a)); |
| 280 var desc = getPropertyDescriptor(constr.prototype, Symbol.toStringTag, 1); | 272 var desc = Object.getOwnPropertyDescriptor( |
| 273 constr.prototype, Symbol.toStringTag); |
| 281 assertTrue(desc.configurable); | 274 assertTrue(desc.configurable); |
| 282 assertFalse(desc.enumerable); | 275 assertFalse(desc.enumerable); |
| 283 assertFalse(!!desc.writable); | 276 assertFalse(!!desc.writable); |
| 284 assertFalse(!!desc.set); | 277 assertFalse(!!desc.set); |
| 285 assertEquals("function", typeof desc.get); | 278 assertEquals("function", typeof desc.get); |
| 286 | 279 |
| 287 // Test that the constructor can be called with an iterable | 280 // Test that the constructor can be called with an iterable |
| 288 function* gen() { for (var i = 0; i < 10; i++) yield i; } | 281 function* gen() { for (var i = 0; i < 10; i++) yield i; } |
| 289 var genArr = new constr(gen()); | 282 var genArr = new constr(gen()); |
| 290 assertEquals(10, genArr.length); | 283 assertEquals(10, genArr.length); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 Uint16Array, | 410 Uint16Array, |
| 418 Int16Array, | 411 Int16Array, |
| 419 Uint32Array, | 412 Uint32Array, |
| 420 Int32Array, | 413 Int32Array, |
| 421 Uint8ClampedArray, | 414 Uint8ClampedArray, |
| 422 Float32Array, | 415 Float32Array, |
| 423 Float64Array]; | 416 Float64Array]; |
| 424 | 417 |
| 425 function TestPropertyTypeChecks(constructor) { | 418 function TestPropertyTypeChecks(constructor) { |
| 426 function CheckProperty(name) { | 419 function CheckProperty(name) { |
| 427 var d = getPropertyDescriptor(constructor.prototype, name, 1); | 420 var d = Object.getOwnPropertyDescriptor(constructor.prototype, name); |
| 428 var o = {}; | 421 var o = {}; |
| 429 assertThrows(function() {d.get.call(o);}, TypeError); | 422 assertThrows(function() {d.get.call(o);}, TypeError); |
| 430 for (var i = 0; i < typedArrayConstructors.length; i++) { | 423 for (var i = 0; i < typedArrayConstructors.length; i++) { |
| 431 var ctor = typedArrayConstructors[i]; | 424 var ctor = typedArrayConstructors[i]; |
| 432 var a = new ctor(10); | 425 var a = new ctor(10); |
| 433 d.get.call(a); // shouldn't throw, even from a different type | 426 if (ctor === constructor) { |
| 427 d.get.call(a); // shouldn't throw |
| 428 } else { |
| 429 assertThrows(function() {d.get.call(a);}, TypeError); |
| 430 } |
| 434 } | 431 } |
| 435 } | 432 } |
| 436 | 433 |
| 437 CheckProperty("buffer"); | 434 CheckProperty("buffer"); |
| 438 CheckProperty("byteOffset"); | 435 CheckProperty("byteOffset"); |
| 439 CheckProperty("byteLength"); | 436 CheckProperty("byteLength"); |
| 440 CheckProperty("length"); | 437 CheckProperty("length"); |
| 441 } | 438 } |
| 442 | 439 |
| 443 for(i = 0; i < typedArrayConstructors.length; i++) { | 440 for(i = 0; i < typedArrayConstructors.length; i++) { |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 TestArbitrary(new ArrayBuffer(256)); | 749 TestArbitrary(new ArrayBuffer(256)); |
| 753 for(i = 0; i < typedArrayConstructors.length; i++) { | 750 for(i = 0; i < typedArrayConstructors.length; i++) { |
| 754 TestArbitrary(new typedArrayConstructors[i](10)); | 751 TestArbitrary(new typedArrayConstructors[i](10)); |
| 755 } | 752 } |
| 756 TestArbitrary(new DataView(new ArrayBuffer(256))); | 753 TestArbitrary(new DataView(new ArrayBuffer(256))); |
| 757 | 754 |
| 758 | 755 |
| 759 // Test direct constructor call | 756 // Test direct constructor call |
| 760 assertThrows(function() { ArrayBuffer(); }, TypeError); | 757 assertThrows(function() { ArrayBuffer(); }, TypeError); |
| 761 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); | 758 assertThrows(function() { DataView(new ArrayBuffer()); }, TypeError); |
| OLD | NEW |