Modified: trunk/Source/WebCore/ChangeLog (206507 => 206508)
--- trunk/Source/WebCore/ChangeLog 2016-09-28 08:17:55 UTC (rev 206507)
+++ trunk/Source/WebCore/ChangeLog 2016-09-28 09:17:57 UTC (rev 206508)
@@ -1,3 +1,31 @@
+2016-09-28 Romain Bellessort <[email protected]>
+
+ [Streams API] Align cancelReadableStream() with spec
+ https://bugs.webkit.org/show_bug.cgi?id=162556
+
+ Reviewed by Xabier Rodriguez-Calvar.
+
+ Aligned cancelReadableStream() with Streams API. In particular, private cancel() method
+ was added to ReadableStreamDefaultController and function name was replaced by readableStreamCancel().
+ Implementation of cancel() (as well as pull()) is actually made in ReadableStreamInternals.js to
+ avoid creating new function for each controller.
+
+ No change in behaviour.
+
+ * Modules/streams/ReadableStream.js:
+ (cancel): Updated with reference to readableStreamCancel().
+ * Modules/streams/ReadableStreamDefaultReader.js:
+ (cancel): Updated with reference to readableStreamCancel().
+ * Modules/streams/ReadableStreamInternals.js:
+ (privateInitializeReadableStreamDefaultController): Refer to external functions (cancel/pull) to avoid
+ creating new functions.
+ (teeReadableStreamBranch2CancelFunction): Updated with reference to readableStreamCancel().
+ (readableStreamCancel): New name for cancelReadableStream(), behaviour aligned with spec.
+ (readableStreamDefaultControllerCancel): Added to avoid creating new function for each controller.
+ (readableStreamDefaultControllerPull): Added to avoid creating new function for each controller.
+ (readFromReadableStreamDefaultReader): Updated call to pull method to pass controller.
+ * bindings/js/WebCoreBuiltinNames.h: Added "cancel".
+
2016-09-27 Joonghun Park <[email protected]>
[EFL] Fix debug build break since r206481. Unreviewed
Modified: trunk/Source/WebCore/Modules/streams/ReadableStream.js (206507 => 206508)
--- trunk/Source/WebCore/Modules/streams/ReadableStream.js 2016-09-28 08:17:55 UTC (rev 206507)
+++ trunk/Source/WebCore/Modules/streams/ReadableStream.js 2016-09-28 09:17:57 UTC (rev 206508)
@@ -74,7 +74,7 @@
if (@isReadableStreamLocked(this))
return @Promise.@reject(new @TypeError("ReadableStream is locked"));
- return @cancelReadableStream(this, reason);
+ return @readableStreamCancel(this, reason);
}
function getReader(options)
Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultReader.js (206507 => 206508)
--- trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultReader.js 2016-09-28 08:17:55 UTC (rev 206507)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultReader.js 2016-09-28 09:17:57 UTC (rev 206508)
@@ -35,7 +35,7 @@
if (!this.@ownerReadableStream)
return @Promise.@reject(new @TypeError("cancel() called on a reader owned by no readable stream"));
- return @cancelReadableStream(this.@ownerReadableStream, reason);
+ return @readableStreamCancel(this.@ownerReadableStream, reason);
}
function read()
Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js (206507 => 206508)
--- trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js 2016-09-28 08:17:55 UTC (rev 206507)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js 2016-09-28 09:17:57 UTC (rev 206508)
@@ -82,22 +82,9 @@
@readableStreamDefaultControllerError(controller, error);
});
- this.@pull = function() {
- "use strict";
+ this.@cancel = @readableStreamDefaultControllerCancel;
- const stream = controller.@controlledReadableStream;
- if ([email protected]) {
- const chunk = @dequeueValue(controller.@queue);
- if (controller.@closeRequested && [email protected] === 0)
- @closeReadableStream(stream);
- else
- @requestReadableStreamPull(controller);
- return @Promise.@resolve({value: chunk, done: false});
- }
- const pendingPromise = @readableStreamAddReadRequest(stream);
- @requestReadableStreamPull(controller);
- return pendingPromise;
- }
+ this.@pull = @readableStreamDefaultControllerPull;
return this;
}
@@ -206,7 +193,7 @@
teeState.canceled1 = true;
teeState.reason1 = r;
if (teeState.canceled2) {
- @cancelReadableStream(stream, [teeState.reason1, teeState.reason2]).@then(
+ @readableStreamCancel(stream, [teeState.reason1, teeState.reason2]).@then(
teeState.cancelPromiseCapability.@resolve,
teeState.cancelPromiseCapability.@reject);
}
@@ -222,7 +209,7 @@
teeState.canceled2 = true;
teeState.reason2 = r;
if (teeState.canceled1) {
- @cancelReadableStream(stream, [teeState.reason1, teeState.reason2]).@then(
+ @readableStreamCancel(stream, [teeState.reason1, teeState.reason2]).@then(
teeState.cancelPromiseCapability.@resolve,
teeState.cancelPromiseCapability.@reject);
}
@@ -336,7 +323,7 @@
return [email protected] - [email protected];
}
-function cancelReadableStream(stream, reason)
+function readableStreamCancel(stream, reason)
{
"use strict";
@@ -346,18 +333,35 @@
if (stream.@state === @streamErrored)
return @Promise.@reject(stream.@storedError);
@closeReadableStream(stream);
- // FIXME: Fix below, which is a temporary solution to the case where controller is undefined.
- // This issue is due to the fact that in previous version of the spec, cancel was associated
- // to underlyingSource, whereas in new version it is associated to controller. As this patch
- // does not yet fully implement the new version, this solution is used.
- const controller = stream.@readableStreamController;
- var underlyingSource = @undefined;
- if (controller !== @undefined)
- underlyingSource = controller.@underlyingSource;
- return @promiseInvokeOrNoop(underlyingSource, "cancel", [reason]).@then(function() { });
+ return stream.@readableStreamController.@cancel(stream.@readableStreamController, reason).@then(function() { });
}
+function readableStreamDefaultControllerCancel(controller, reason)
+{
+ "use strict";
+ controller.@queue = @newQueue();
+ return @promiseInvokeOrNoop(controller.@underlyingSource, "cancel", [reason]);
+}
+
+function readableStreamDefaultControllerPull(controller)
+{
+ "use strict";
+
+ const stream = controller.@controlledReadableStream;
+ if ([email protected]) {
+ const chunk = @dequeueValue(controller.@queue);
+ if (controller.@closeRequested && [email protected] === 0)
+ @closeReadableStream(stream);
+ else
+ @requestReadableStreamPull(controller);
+ return @Promise.@resolve({value: chunk, done: false});
+ }
+ const pendingPromise = @readableStreamAddReadRequest(stream);
+ @requestReadableStreamPull(controller);
+ return pendingPromise;
+}
+
function readableStreamDefaultControllerClose(controller)
{
"use strict";
@@ -433,7 +437,7 @@
return @Promise.@reject(stream.@storedError);
@assert(stream.@state === @streamReadable);
- return stream.@readableStreamController.@pull();
+ return stream.@readableStreamController.@pull(stream.@readableStreamController);
}
function readableStreamAddReadRequest(stream)
Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (206507 => 206508)
--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h 2016-09-28 08:17:55 UTC (rev 206507)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h 2016-09-28 09:17:57 UTC (rev 206508)
@@ -35,6 +35,7 @@
macro(addTrack) \
macro(appendFromJS) \
macro(body) \
+ macro(cancel) \
macro(cloneForJS) \
macro(closeRequested) \
macro(closedPromiseCapability) \