()
| 17 | TestArrayBufferTooLarge(); |
| 18 | |
| 19 | function TestArrayBufferTooLarge() { |
| 20 | const LIMIT = 65536; |
| 21 | |
| 22 | // Not too big. |
| 23 | new ArrayBuffer(LIMIT); |
| 24 | // Too big. |
| 25 | assertThrows(() => new ArrayBuffer(LIMIT + 1), RangeError); |
| 26 | |
| 27 | // Not too big. |
| 28 | new Int8Array(LIMIT); |
| 29 | // Too big. |
| 30 | assertThrows(() => new Int8Array(LIMIT + 1), RangeError); |
| 31 | |
| 32 | // Not too big. |
| 33 | new Int16Array(LIMIT / 2); |
| 34 | // Too big. |
| 35 | assertThrows(() => new Int16Array(LIMIT / 2 + 1), RangeError); |
| 36 | |
| 37 | // Not too big. |
| 38 | new Int32Array(LIMIT / 4); |
| 39 | // Too big. |
| 40 | assertThrows(() => new Int32Array(LIMIT / 4 + 1), RangeError); |
| 41 | |
| 42 | // Not too big. |
| 43 | new Float64Array(LIMIT / 8); |
| 44 | // Too big. |
| 45 | assertThrows(() => new Float64Array(LIMIT / 8 + 1), RangeError); |
| 46 | |
| 47 | // Not too big, based on an iterable input. |
| 48 | let array = new Array(LIMIT); |
| 49 | for (i = 0; i < array.length; i++) array[i] = i & 0xff; |
| 50 | |
| 51 | new Int8Array(array); |
| 52 | |
| 53 | // Too big, based on an iterable input. |
| 54 | let big = new Array(LIMIT + 1); |
| 55 | for (i = 0; i < big.length; i++) big[i] = i & 0xff; |
| 56 | |
| 57 | assertThrows(() => new Int8Array(big), RangeError); |
| 58 | |
| 59 | assertThrowsWithMessage("Invalid typed array length", () => { |
| 60 | const int8_array = new Int8Array(LIMIT + 1); |
| 61 | }); |
| 62 | |
| 63 | const int8_array = new Int8Array(LIMIT); |
| 64 | assertThrowsWithMessage("Array buffer allocation failed", () => { |
| 65 | // Outer one is still alive so we can't allocate another. |
| 66 | // 64 is the default of v8_typed_array_max_size_in_heap - below this |
| 67 | // level the mock array buffer allocator is not asked. |
| 68 | int8_slice = new Int8Array(65); |
| 69 | }); |
| 70 | |
| 71 | assertThrowsWithMessage("Array buffer allocation failed", () => { |
| 72 | // Outer one is still alive so we can't allocate another with slice. |
| 73 | int8_slice = int8_array.slice(0, 65); |
| 74 | }); |
| 75 | } |
| 76 |
no test coverage detected