OLD | NEW |
(Empty) | |
| 1 'use strict'; |
| 2 |
| 3 if (self.importScripts) { |
| 4 self.importScripts('/resources/testharness.js'); |
| 5 } |
| 6 |
| 7 test(() => { |
| 8 |
| 9 const theError = new Error('a unique string'); |
| 10 |
| 11 assert_throws(theError, () => { |
| 12 new ReadableStream({}, { |
| 13 get size() { |
| 14 throw theError; |
| 15 }, |
| 16 highWaterMark: 5 |
| 17 }); |
| 18 }, 'construction should re-throw the error'); |
| 19 |
| 20 }, 'Readable stream: throwing strategy.size getter'); |
| 21 |
| 22 promise_test(t => { |
| 23 |
| 24 const controllerError = { name: 'controller error' }; |
| 25 const thrownError = { name: 'thrown error' }; |
| 26 |
| 27 let controller; |
| 28 const rs = new ReadableStream( |
| 29 { |
| 30 start(c) { |
| 31 controller = c; |
| 32 } |
| 33 }, |
| 34 { |
| 35 size() { |
| 36 controller.error(controllerError); |
| 37 throw thrownError; |
| 38 }, |
| 39 highWaterMark: 5 |
| 40 } |
| 41 ); |
| 42 |
| 43 assert_throws(thrownError, () => controller.enqueue('a'), 'enqueue should re-t
hrow the error'); |
| 44 |
| 45 return promise_rejects(t, controllerError, rs.getReader().closed); |
| 46 |
| 47 }, 'Readable stream: strategy.size errors the stream and then throws'); |
| 48 |
| 49 promise_test(t => { |
| 50 |
| 51 const theError = { name: 'my error' }; |
| 52 |
| 53 let controller; |
| 54 const rs = new ReadableStream( |
| 55 { |
| 56 start(c) { |
| 57 controller = c; |
| 58 } |
| 59 }, |
| 60 { |
| 61 size() { |
| 62 controller.error(theError); |
| 63 return Infinity; |
| 64 }, |
| 65 highWaterMark: 5 |
| 66 } |
| 67 ); |
| 68 |
| 69 assert_throws(new RangeError(), () => controller.enqueue('a'), 'enqueue should
throw a RangeError'); |
| 70 |
| 71 return promise_rejects(t, theError, rs.getReader().closed, 'closed should reje
ct with the error'); |
| 72 |
| 73 }, 'Readable stream: strategy.size errors the stream and then returns Infinity')
; |
| 74 |
| 75 promise_test(() => { |
| 76 |
| 77 const theError = new Error('a unique string'); |
| 78 const rs = new ReadableStream( |
| 79 { |
| 80 start(c) { |
| 81 assert_throws(theError, () => c.enqueue('a'), 'enqueue should throw the
error'); |
| 82 } |
| 83 }, |
| 84 { |
| 85 size() { |
| 86 throw theError; |
| 87 }, |
| 88 highWaterMark: 5 |
| 89 } |
| 90 ); |
| 91 |
| 92 return rs.getReader().closed.catch(e => { |
| 93 assert_equals(e, theError, 'closed should reject with the error'); |
| 94 }); |
| 95 |
| 96 }, 'Readable stream: throwing strategy.size method'); |
| 97 |
| 98 test(() => { |
| 99 |
| 100 const theError = new Error('a unique string'); |
| 101 |
| 102 assert_throws(theError, () => { |
| 103 new ReadableStream({}, { |
| 104 size() { |
| 105 return 1; |
| 106 }, |
| 107 get highWaterMark() { |
| 108 throw theError; |
| 109 } |
| 110 }); |
| 111 }, 'construction should re-throw the error'); |
| 112 |
| 113 }, 'Readable stream: throwing strategy.highWaterMark getter'); |
| 114 |
| 115 test(() => { |
| 116 |
| 117 for (const highWaterMark of [-1, -Infinity, NaN, 'foo', {}]) { |
| 118 assert_throws(new RangeError(), () => { |
| 119 new ReadableStream({}, { |
| 120 size() { |
| 121 return 1; |
| 122 }, |
| 123 highWaterMark |
| 124 }); |
| 125 }, 'construction should throw a RangeError for ' + highWaterMark); |
| 126 } |
| 127 |
| 128 }, 'Readable stream: invalid strategy.highWaterMark'); |
| 129 |
| 130 promise_test(() => { |
| 131 |
| 132 const promises = []; |
| 133 for (const size of [NaN, -Infinity, Infinity, -1]) { |
| 134 let theError; |
| 135 const rs = new ReadableStream( |
| 136 { |
| 137 start(c) { |
| 138 try { |
| 139 c.enqueue('hi'); |
| 140 assert_unreached('enqueue didn\'t throw'); |
| 141 } catch (error) { |
| 142 assert_equals(error.name, 'RangeError', 'enqueue should throw a Rang
eError for ' + size); |
| 143 theError = error; |
| 144 } |
| 145 } |
| 146 }, |
| 147 { |
| 148 size() { |
| 149 return size; |
| 150 }, |
| 151 highWaterMark: 5 |
| 152 } |
| 153 ); |
| 154 |
| 155 promises.push(rs.getReader().closed.catch(e => { |
| 156 assert_equals(e, theError, 'closed should reject with the error for ' + si
ze); |
| 157 })); |
| 158 } |
| 159 |
| 160 return Promise.all(promises); |
| 161 |
| 162 }, 'Readable stream: invalid strategy.size return value'); |
| 163 |
| 164 done(); |
OLD | NEW |