Modified: trunk/LayoutTests/streams/reference-implementation/bad-strategies-expected.txt (190158 => 190159)
--- trunk/LayoutTests/streams/reference-implementation/bad-strategies-expected.txt 2015-09-23 10:04:24 UTC (rev 190158)
+++ trunk/LayoutTests/streams/reference-implementation/bad-strategies-expected.txt 2015-09-23 11:03:08 UTC (rev 190159)
@@ -5,4 +5,18 @@
PASS Readable stream: invalid strategy.highWaterMark
PASS Readable stream: negative strategy.highWaterMark
PASS Readable stream: invalid strategy.size return value
+FAIL Writable stream: throwing strategy.size getter assert_throws: construction should re-throw the error function "function () {
+ new WritableStream({}, {
+ ..." threw object "ReferenceError: Can't find variable: WritableStream" ("ReferenceError") expected object "Error: a unique string" ("Error")
+FAIL Writable stream: throwing strategy.size method Can't find variable: WritableStream
+FAIL Writable stream: invalid strategy.size return value Can't find variable: WritableStream
+FAIL Writable stream: throwing strategy.highWaterMark getter assert_throws: construction should re-throw the error function "function () {
+ new WritableStream({}, {
+ ..." threw object "ReferenceError: Can't find variable: WritableStream" ("ReferenceError") expected object "Error: a unique string" ("Error")
+FAIL Writable stream: invalid strategy.highWaterMark assert_throws: construction should throw a RangeError for -1 function "function () {
+ new WritableStream({}, {
+ ..." threw object "ReferenceError: Can't find variable: WritableStream" ("ReferenceError") expected object "RangeError" ("RangeError")
+FAIL Writable stream: negative strategy.highWaterMark assert_throws: construction should throw a RangeError function "function () {
+ new WritableStream({}, {
+ ..." threw object "ReferenceError: Can't find variable: WritableStream" ("ReferenceError") expected object "RangeError" ("RangeError")
Modified: trunk/LayoutTests/streams/reference-implementation/bad-strategies.html (190158 => 190159)
--- trunk/LayoutTests/streams/reference-implementation/bad-strategies.html 2015-09-23 10:04:24 UTC (rev 190158)
+++ trunk/LayoutTests/streams/reference-implementation/bad-strategies.html 2015-09-23 11:03:08 UTC (rev 190159)
@@ -122,4 +122,133 @@
rs.getReader().closed.catch(test2.step_func(catchFunction.bind(this, i)));
}
});
+
+test(function() {
+ var theError = new Error('a unique string');
+
+ assert_throws(theError, function() {
+ new WritableStream({}, {
+ get size() {
+ throw theError;
+ },
+ highWaterMark: 5
+ });
+ }, 'construction should re-throw the error');
+}, 'Writable stream: throwing strategy.size getter');
+
+var test3 = async_test('Writable stream: throwing strategy.size method');
+test3.step(function() {
+ var theError = new Error('a unique string');
+ var writeCalled = false;
+ var ws = new WritableStream({ },
+ {
+ size: function() {
+ throw theError;
+ },
+ highWaterMark: 5
+ }
+ ); // Initial construction should not throw.
+
+ ws.write('a').then(
+ test3.step_func(function() { assert_unreached('write should not fulfill'); }),
+ test3.step_func(function(r) {
+ assert_equals(r, theError, 'write should reject with the thrown error');
+ writeCalled = true;
+ })
+ );
+
+ ws.closed.then(
+ test3.step_func(function() { assert_unreached('closed should not fulfill'); }),
+ test3.step_func(function(r) {
+ assert_equals(r, theError, 'closed should reject with the thrown error');
+ assert_true(writeCalled);
+ test3.done();
+ })
+ );
+});
+
+var test4 = async_test('Writable stream: invalid strategy.size return value');
+test4.step(function() {
+ var numberOfCalls = 0;
+ var elements = [NaN, -Infinity, +Infinity, -1];
+ var theError = [];
+ var numberOfCalls = 0;
+ for (var i = 0; i < elements.length; i++) {
+ var ws = new WritableStream({},
+ {
+ size: function() {
+ return elements[i];
+ },
+ highWaterMark: 5
+ });
+
+ var writeFunction = function(i, r) {
+ assert_throws(new RangeError(), function() { throw r; }, 'write should reject with a RangeError for ' + elements[i]);
+ theError[i] = r;
+ };
+ ws.write('a').then(
+ test4.step_func(function() { assert_unreached('write should not fulfill'); }),
+ test4.step_func(writeFunction.bind(this, i))
+ );
+
+ var catchFunction = function(i, e) {
+ assert_equals(e, theError[i], 'closed should reject with the error for ' + elements[i]);
+ if (++numberOfCalls, elements.length) {
+ test4.done();
+ }
+ };
+
+ ws.closed.catch(test4.step_func(catchFunction.bind(this, i)));
+ }
+});
+
+test(function() {
+ var theError = new Error('a unique string');
+
+ assert_throws(theError, function() {
+ new WritableStream({}, {
+ size: function() {
+ return 1;
+ },
+ get highWaterMark() {
+ throw theError;
+ }
+ });
+ }, 'construction should re-throw the error');
+}, 'Writable stream: throwing strategy.highWaterMark getter');
+
+test(function() {
+ for (var highWaterMark of [-1, -Infinity]) {
+ assert_throws(new RangeError(), function() {
+ new WritableStream({}, {
+ size: function() {
+ return 1;
+ },
+ highWaterMark
+ });
+ }, 'construction should throw a RangeError for ' + highWaterMark);
+ }
+
+ for (var highWaterMark of [NaN, 'foo', {}]) {
+ assert_throws(new TypeError(), function() {
+ new WritableStream({}, {
+ size: function() {
+ return 1;
+ },
+ highWaterMark
+ });
+ }, 'construction should throw a TypeError for ' + highWaterMark);
+ }
+}, 'Writable stream: invalid strategy.highWaterMark');
+
+test(function() {
+ assert_throws(new RangeError(), function() {
+ new WritableStream({}, {
+ size: function() {
+ return 1;
+ },
+ highWaterMark: -1
+ });
+ }, 'construction should throw a RangeError');
+}, 'Writable stream: negative strategy.highWaterMark');
</script>