[Streams API] Synced bad strategy test with reference implementation
authorcalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Jun 2015 09:27:49 +0000 (09:27 +0000)
committercalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Jun 2015 09:27:49 +0000 (09:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146411

Reviewed by Darin Adler.

Source/WebCore:

Current tests cover the case.

* bindings/js/ReadableJSStream.cpp:
(WebCore::ReadableJSStream::retrieveChunkSize): Check for negative size then running the JavaScript function.

LayoutTests:

* streams/reference-implementation/bad-strategies-expected.txt:
* streams/reference-implementation/bad-strategies.html: There are three tests that are merged into one and a
fourth check is added. Updated expectations accordingly.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@186112 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/streams/reference-implementation/bad-strategies-expected.txt
LayoutTests/streams/reference-implementation/bad-strategies.html
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/ReadableJSStream.cpp

index f56310d..0f6915f 100644 (file)
@@ -1,3 +1,14 @@
+2015-06-30  Youenn Fablet  <youenn.fablet@crf.canon.fr> and Xabier Rodriguez Calvar  <calvaris@igalia.com>
+
+        [Streams API] Synced bad strategy test with reference implementation
+        https://bugs.webkit.org/show_bug.cgi?id=146411
+
+        Reviewed by Darin Adler.
+
+        * streams/reference-implementation/bad-strategies-expected.txt:
+        * streams/reference-implementation/bad-strategies.html: There are three tests that are merged into one and a
+        fourth check is added. Updated expectations accordingly.
+
 2015-06-29  Ryosuke Niwa  <rniwa@webkit.org>
 
         Another rebaseline after r186086.
index c86d384..2bc8cd4 100644 (file)
@@ -4,7 +4,5 @@ PASS Readable stream: throwing strategy.size method
 PASS Readable stream: throwing strategy.highWaterMark getter 
 PASS Readable stream: invalid strategy.highWaterMark 
 PASS Readable stream: negative strategy.highWaterMark 
-PASS Readable stream: strategy.size returning NaN 
-PASS Readable stream: strategy.size returning -Infinity 
-PASS Readable stream: strategy.size returning +Infinity 
+PASS Readable stream: invalid strategy.size return value 
 
index bfdadb5..dca48e0 100644 (file)
@@ -88,99 +88,38 @@ test(function() {
     }, 'construction should throw a RangeError');
 }, 'Readable stream: negative strategy.highWaterMark');
 
-var test2 = async_test('Readable stream: strategy.size returning NaN');
+var test2 = async_test('Readable stream: invalid strategy.size return value');
 test2.step(function() {
-    var theError;
-    var startCalled = false;
-    var rs = new ReadableStream(
-        {
+    var numberOfCalls = 0;
+    var elements = [NaN, -Infinity, +Infinity, -1];
+    var theError = [];
+    for (var i = 0; i < elements.length; i++) {
+        var rs = new ReadableStream({
             start: function(c) {
                 try {
                     c.enqueue('hi');
                     assert_unreached('enqueue didn\'t throw');
                 } catch (error) {
-                    startCalled = true;
-                    assert_equals(error.constructor, RangeError, 'enqueue should throw a RangeError');
-                    theError = error;
+                    assert_throws(new RangeError(), function() { throw error; }, 'enqueue should throw a RangeError for ' + elements[i]);
+                    theError[i] = error;
                 }
             }
         },
         {
             size: function() {
-                return NaN;
+                return elements[i];
             },
             highWaterMark: 5
-        }
-    );
-
-    rs.getReader().closed.catch(test2.step_func(function(e) {
-        assert_equals(e, theError, 'closed should reject with the error');
-        assert_true(startCalled);
-        test2.done();
-    }));
-});
-
-var test3 = async_test('Readable stream: strategy.size returning -Infinity');
-test3.step(function() {
-    var theError;
-    var startCalled = false;
-    var rs = new ReadableStream(
-        {
-            start: function(c) {
-                try {
-                    c.enqueue('hi');
-                    assert_unreached('enqueue didn\'t throw');
-                } catch (error) {
-                    startCalled = true;
-                    assert_equals(error.constructor, RangeError, 'enqueue should throw a RangeError');
-                    theError = error;
-                }
-            }
-        },
-        {
-            size: function() {
-                return -Infinity;
-            },
-            highWaterMark: 5
-        }
-    );
-
-    rs.getReader().closed.catch(test3.step_func(function(e) {
-        assert_equals(e, theError, 'closed should reject with the error');
-        assert_true(startCalled);
-        test3.done();
-    }));
-});
+        });
 
-var test4 = async_test('Readable stream: strategy.size returning +Infinity');
-test4.step(function() {
-    var theError;
-    var startCalled = false;
-    var rs = new ReadableStream(
-        {
-            start: function(c) {
-                try {
-                    c.enqueue('hi');
-                    assert_unreached('enqueue didn\'t throw');
-                } catch (error) {
-                    startCalled = true;
-                    assert_equals(error.constructor, RangeError, 'enqueue should throw a RangeError');
-                    theError = error;
-                }
+        var catchFunction = function(i, e) {
+            assert_equals(e, theError[i], 'closed should reject with the error for ' + elements[i]);
+            if (++numberOfCalls, elements.length) {
+                test2.done();
             }
-        },
-        {
-            size: function() {
-                return +Infinity;
-            },
-            highWaterMark: 5
-        }
-    );
+        };
 
-    rs.getReader().closed.catch(test4.step_func(function(e) {
-        assert_equals(e, theError, 'closed should reject with the error');
-        assert_true(startCalled);
-        test4.done();
-    }));
+        rs.getReader().closed.catch(test2.step_func(catchFunction.bind(this, i)));
+    }
 });
 </script>
index 87f5f2f..6790ce3 100644 (file)
@@ -1,3 +1,15 @@
+2015-06-30  Youenn Fablet  <youenn.fablet@crf.canon.fr> and Xabier Rodriguez Calvar  <calvaris@igalia.com>
+
+        [Streams API] Synced bad strategy test with reference implementation
+        https://bugs.webkit.org/show_bug.cgi?id=146411
+
+        Reviewed by Darin Adler.
+
+        Current tests cover the case.
+
+        * bindings/js/ReadableJSStream.cpp:
+        (WebCore::ReadableJSStream::retrieveChunkSize): Check for negative size then running the JavaScript function.
+
 2015-06-30  Youenn Fablet  <youenn.fablet@crf.canon.fr>
 
         [Streams API] Remove ReadableStream.getReader() custom binding
index ff18a2f..a7d21b2 100644 (file)
@@ -379,7 +379,7 @@ double ReadableJSStream::retrieveChunkSize(ExecState& state, JSValue chunk)
     if (state.hadException())
         return 0;
 
-    if (!std::isfinite(size)) {
+    if (!std::isfinite(size) || size < 0) {
         throwVMError(&state, createRangeError(&state, ASCIILiteral("Incorrect double value")));
         return 0;
     }