OLD | NEW |
(Empty) | |
| 1 'use strict'; |
| 2 |
| 3 if (self.importScripts) { |
| 4 self.importScripts('/resources/testharness.js'); |
| 5 } |
| 6 |
| 7 test(function() { |
| 8 var theError = new Error('a unique string'); |
| 9 |
| 10 assert_throws(theError, function() { |
| 11 new ReadableStream({}, { |
| 12 get size() { |
| 13 throw theError; |
| 14 }, |
| 15 highWaterMark: 5 |
| 16 }); |
| 17 }, 'construction should re-throw the error'); |
| 18 }, 'Readable stream: throwing strategy.size getter'); |
| 19 |
| 20 var test1 = async_test('Readable stream: throwing strategy.size method'); |
| 21 test1.step(function() { |
| 22 var theError = new Error('a unique string'); |
| 23 var rs = new ReadableStream( |
| 24 { |
| 25 start: function(c) { |
| 26 assert_throws(theError, function() { c.enqueue('a'); }, 'enqueue
should throw the error'); |
| 27 } |
| 28 }, |
| 29 { |
| 30 size: function() { |
| 31 throw theError; |
| 32 }, |
| 33 highWaterMark: 5 |
| 34 } |
| 35 ); |
| 36 |
| 37 rs.getReader().closed.catch(test1.step_func(function(e) { |
| 38 assert_equals(e, theError, 'closed should reject with the error'); |
| 39 test1.done(); |
| 40 })) |
| 41 }); |
| 42 |
| 43 test(function() { |
| 44 var theError = new Error('a unique string'); |
| 45 |
| 46 assert_throws(theError, function() { |
| 47 new ReadableStream({}, { |
| 48 size: function() { |
| 49 return 1; |
| 50 }, |
| 51 get highWaterMark() { |
| 52 throw theError; |
| 53 } |
| 54 }); |
| 55 }, 'construction should re-throw the error'); |
| 56 }, 'Readable stream: throwing strategy.highWaterMark getter'); |
| 57 |
| 58 test(function() { |
| 59 for (var highWaterMark of [-1, -Infinity]) { |
| 60 assert_throws(new RangeError(), function() { |
| 61 new ReadableStream({}, { |
| 62 size: function() { |
| 63 return 1; |
| 64 }, |
| 65 highWaterMark |
| 66 }); |
| 67 }, 'construction should throw a RangeError for ' + highWaterMark); |
| 68 } |
| 69 |
| 70 for (var highWaterMark of [NaN, 'foo', {}]) { |
| 71 assert_throws(new TypeError(), function() { |
| 72 new ReadableStream({}, { |
| 73 size: function() { |
| 74 return 1; |
| 75 }, |
| 76 highWaterMark |
| 77 }); |
| 78 }, 'construction should throw a TypeError for ' + highWaterMark); |
| 79 } |
| 80 }, 'Readable stream: invalid strategy.highWaterMark'); |
| 81 |
| 82 var test2 = async_test('Readable stream: invalid strategy.size return value'); |
| 83 test2.step(function() { |
| 84 var numberOfCalls = 0; |
| 85 var elements = [NaN, -Infinity, +Infinity, -1]; |
| 86 var theErrors = []; |
| 87 for (var i = 0; i < elements.length; i++) { |
| 88 var rs = new ReadableStream({ |
| 89 start: function(c) { |
| 90 try { |
| 91 c.enqueue('hi'); |
| 92 assert_unreached('enqueue didn\'t throw'); |
| 93 } catch (error) { |
| 94 assert_equals(error.name, 'RangeError', 'enqueue should thro
w a RangeError for ' + elements[i]); |
| 95 theErrors[i] = error; |
| 96 } |
| 97 } |
| 98 }, |
| 99 { |
| 100 size: function() { |
| 101 return elements[i]; |
| 102 }, |
| 103 highWaterMark: 5 |
| 104 }); |
| 105 |
| 106 var catchFunction = function(i, e) { |
| 107 assert_equals(e, theErrors[i], 'closed should reject with the error
for ' + elements[i]); |
| 108 if (++numberOfCalls === elements.length) { |
| 109 test2.done(); |
| 110 } |
| 111 }; |
| 112 |
| 113 rs.getReader().closed.catch(test2.step_func(catchFunction.bind(this, i))
); |
| 114 } |
| 115 }); |
| 116 |
| 117 done(); |
OLD | NEW |