[Streams API] Fix style issues
authorcalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2015 15:45:21 +0000 (15:45 +0000)
committercalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2015 15:45:21 +0000 (15:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151089

Reviewed by Youenn Fablet.

Inlined some things, converted var into let and const, removed some undefined parameters and returns, added
missing "use strict" clauses and other minor style changes.

Internal rework, no new tests needed.

* Modules/streams/ReadableStream.js:
(initializeReadableStream):
* Modules/streams/ReadableStreamController.js:
(enqueue):
(error):
(close):
* Modules/streams/ReadableStreamInternals.js:
(teeReadableStream):
(teeReadableStreamPullFunction):
(teeReadableStreamBranch2CancelFunction):
(errorReadableStream):
(finishClosingReadableStream):
(closeReadableStreamReader):
(enqueueInReadableStream):
(readFromReadableStreamReader):
* Modules/streams/ReadableStreamReader.js:
(releaseLock):
* Modules/streams/StreamInternals.js:
(invokeOrNoop):
(promiseInvokeOrNoop):
(promiseInvokeOrFallbackOrNoop):
(validateAndNormalizeQueuingStrategy):
(newQueue):
(dequeueValue):
(enqueueValueWithSize):
(peekQueueValue):
* Modules/streams/WritableStream.js:
(initializeWritableStream):
(abort):
(close):
* Modules/streams/WritableStreamInternals.js:
(syncWritableStreamStateWithQueue):
(errorWritableStream):
(callOrScheduleWritableStreamAdvanceQueue):
(writableStreamAdvanceQueue):
(closeWritableStream): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/streams/ReadableStream.js
Source/WebCore/Modules/streams/ReadableStreamController.js
Source/WebCore/Modules/streams/ReadableStreamInternals.js
Source/WebCore/Modules/streams/ReadableStreamReader.js
Source/WebCore/Modules/streams/StreamInternals.js
Source/WebCore/Modules/streams/WritableStream.js
Source/WebCore/Modules/streams/WritableStreamInternals.js

index 6a37c25..a792887 100644 (file)
@@ -1,3 +1,52 @@
+2015-11-10  Xabier Rodriguez Calvar  <calvaris@igalia.com>
+
+        [Streams API] Fix style issues
+        https://bugs.webkit.org/show_bug.cgi?id=151089
+
+        Reviewed by Youenn Fablet.
+
+        Inlined some things, converted var into let and const, removed some undefined parameters and returns, added
+        missing "use strict" clauses and other minor style changes.
+
+        Internal rework, no new tests needed.
+
+        * Modules/streams/ReadableStream.js:
+        (initializeReadableStream):
+        * Modules/streams/ReadableStreamController.js:
+        (enqueue):
+        (error):
+        (close):
+        * Modules/streams/ReadableStreamInternals.js:
+        (teeReadableStream):
+        (teeReadableStreamPullFunction):
+        (teeReadableStreamBranch2CancelFunction):
+        (errorReadableStream):
+        (finishClosingReadableStream):
+        (closeReadableStreamReader):
+        (enqueueInReadableStream):
+        (readFromReadableStreamReader):
+        * Modules/streams/ReadableStreamReader.js:
+        (releaseLock):
+        * Modules/streams/StreamInternals.js:
+        (invokeOrNoop):
+        (promiseInvokeOrNoop):
+        (promiseInvokeOrFallbackOrNoop):
+        (validateAndNormalizeQueuingStrategy):
+        (newQueue):
+        (dequeueValue):
+        (enqueueValueWithSize):
+        (peekQueueValue):
+        * Modules/streams/WritableStream.js:
+        (initializeWritableStream):
+        (abort):
+        (close):
+        * Modules/streams/WritableStreamInternals.js:
+        (syncWritableStreamStateWithQueue):
+        (errorWritableStream):
+        (callOrScheduleWritableStreamAdvanceQueue):
+        (writableStreamAdvanceQueue):
+        (closeWritableStream): Deleted.
+
 2015-11-10  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix scrollbars/custom-scrollbar-appearance-property.html after r191991.
index ea423d8..c110f62 100644 (file)
@@ -54,8 +54,8 @@ function initializeReadableStream(underlyingSource, strategy)
     this.@controller = new @ReadableStreamController(this);
     this.@strategy = @validateAndNormalizeQueuingStrategy(strategy.size, strategy.highWaterMark);
 
-    var result = @invokeOrNoop(underlyingSource, "start", [this.@controller]);
-    var _this = this;
+    const result = @invokeOrNoop(underlyingSource, "start", [this.@controller]);
+    const _this = this;
     @Promise.prototype.@then.@call(@Promise.@resolve(result), function() {
         _this.@started = true;
         @requestReadableStreamPull(_this);
index 0d9981b..9c8c34e 100644 (file)
@@ -32,14 +32,14 @@ function enqueue(chunk)
     if (!@isReadableStreamController(this))
         throw new @TypeError("Function should be called on a ReadableStreamController");
 
-    var stream = this.@controlledReadableStream;
+    const stream = this.@controlledReadableStream;
     if (stream.@state === @streamErrored)
         throw stream.@storedError;
 
     if (stream.@closeRequested)
         throw new @TypeError("ReadableStream is requested to close");
 
-    return @enqueueInReadableStream(stream, chunk)
+    return @enqueueInReadableStream(stream, chunk);
 }
 
 function error(error)
@@ -49,7 +49,7 @@ function error(error)
     if (!@isReadableStreamController(this))
         throw new @TypeError("Function should be called on a ReadableStreamController");
 
-    var stream = this.@controlledReadableStream;
+    const stream = this.@controlledReadableStream;
     if (stream.@state !== @streamReadable)
         throw new @TypeError("ReaableStream is not readable");
 
@@ -63,7 +63,7 @@ function close()
     if (!@isReadableStreamController(this))
         throw new @TypeError("Function should be called on a ReadableStreamController");
 
-    var stream = this.@controlledReadableStream;
+    const stream = this.@controlledReadableStream;
     if (stream.@closeRequested)
         throw new @TypeError("ReadableStream is already requested to close");
 
index 9b26080..d591c82 100644 (file)
@@ -79,9 +79,9 @@ function teeReadableStream(stream, shouldClone)
     @assert(@isReadableStream(stream));
     @assert(typeof(shouldClone) === "boolean");
 
-    let reader = stream.getReader();
+    const reader = stream.getReader();
 
-    let teeState = {
+    const teeState = {
         closedOrErrored: false,
         canceled1: false,
         canceled2: false,
@@ -91,20 +91,16 @@ function teeReadableStream(stream, shouldClone)
 
     teeState.cancelPromiseCapability = @newPromiseCapability(@InternalPromise);
 
-    let pullFunction = @teeReadableStreamPullFunction(teeState, reader, shouldClone);
+    const pullFunction = @teeReadableStreamPullFunction(teeState, reader, shouldClone);
 
-    let underlyingSource1 = {
+    const branch1 = new ReadableStream({
         "pull": pullFunction,
         "cancel": @teeReadableStreamBranch1CancelFunction(teeState, stream)
-    };
-
-    let underlyingSource2 = {
+    });
+    const branch2 = new ReadableStream({
         "pull": pullFunction,
         "cancel": @teeReadableStreamBranch2CancelFunction(teeState, stream)
-    };
-
-    let branch1 = new ReadableStream(underlyingSource1);
-    let branch2 = new ReadableStream(underlyingSource2);
+    });
 
     @Promise.prototype.@catch.@call(reader.closed, function(e) {
         if (teeState.closedOrErrored)
@@ -123,6 +119,8 @@ function teeReadableStream(stream, shouldClone)
 
 function teeReadableStreamPullFunction(teeState, reader, shouldClone)
 {
+    "use strict";
+
     return function() {
         @Promise.prototype.@then.@call(reader.read(), function(result) {
             if (result.done && !teeState.closedOrErrored) {
@@ -146,6 +144,8 @@ function teeReadableStreamPullFunction(teeState, reader, shouldClone)
 
 function teeReadableStreamBranch1CancelFunction(teeState, stream)
 {
+    "use strict";
+
     return function(r) {
         teeState.canceled1 = true;
         teeState.reason1 = r;
@@ -160,6 +160,8 @@ function teeReadableStreamBranch1CancelFunction(teeState, stream)
 
 function teeReadableStreamBranch2CancelFunction(teeState, stream)
 {
+    "use strict";
+
     return function(r) {
         teeState.canceled2 = true;
         teeState.reason2 = r;
@@ -204,10 +206,10 @@ function errorReadableStream(stream, error)
 
     if (!stream.@reader)
         return;
-    var reader = stream.@reader;
+    const reader = stream.@reader;
 
-    var requests = reader.@readRequests;
-    for (var index = 0, length = requests.length; index < length; ++index)
+    const requests = reader.@readRequests;
+    for (let index = 0, length = requests.length; index < length; ++index)
         requests[index].@reject.@call(undefined, error);
     reader.@readRequests = [];
 
@@ -238,7 +240,7 @@ function requestReadableStreamPull(stream)
 
     stream.@pulling = true;
 
-    var promise = @promiseInvokeOrNoop(stream.@underlyingSource, "pull", [stream.@controller]);
+    const promise = @promiseInvokeOrNoop(stream.@underlyingSource, "pull", [stream.@controller]);
     @Promise.prototype.@then.@call(promise, function() {
         stream.@pulling = false;
         if (stream.@pullAgain) {
@@ -292,7 +294,7 @@ function finishClosingReadableStream(stream)
 
     @assert(stream.@state ===  @streamReadable);
     stream.@state = @streamClosed;
-    var reader = stream.@reader;
+    const reader = stream.@reader;
     if (reader)
         @closeReadableStreamReader(reader);
 }
@@ -314,13 +316,13 @@ function closeReadableStreamReader(reader)
 {
     "use strict";
 
-    var requests = reader.@readRequests;
-    for (var index = 0, length = requests.length; index < length; ++index)
+    const requests = reader.@readRequests;
+    for (let index = 0, length = requests.length; index < length; ++index)
         requests[index].@resolve.@call(undefined, {value:undefined, done: true});
     reader.@readRequests = [];
     @releaseReadableStreamReader(reader);
     reader.@state = @streamClosed;
-    reader.@closedPromiseCapability.@resolve.@call(undefined);
+    reader.@closedPromiseCapability.@resolve.@call();
 }
 
 function enqueueInReadableStream(stream, chunk)
@@ -330,18 +332,18 @@ function enqueueInReadableStream(stream, chunk)
     @assert(!stream.@closeRequested);
     @assert(stream.@state !== @streamErrored);
     if (stream.@state === @streamClosed)
-        return undefined;
+        return;
     if (@isReadableStreamLocked(stream) && stream.@reader.@readRequests.length) {
         stream.@reader.@readRequests.shift().@resolve.@call(undefined, {value: chunk, done: false});
         @requestReadableStreamPull(stream);
         return;
     }
     try {
-        var size = 1;
+        let size = 1;
         if (stream.@strategy.size) {
             size = Number(stream.@strategy.size(chunk));
             if (Number.isNaN(size) || size === +Infinity || size < 0)
-                throw new RangeError("Chunk size is not valid");
+                throw new @RangeError("Chunk size is not valid");
         }
         @enqueueValueWithSize(stream.@queue, chunk, size);
     }
@@ -362,16 +364,16 @@ function readFromReadableStreamReader(reader)
         return @Promise.@reject(reader.@storedError);
     @assert(!!reader.@ownerReadableStream);
     @assert(reader.@ownerReadableStream.@state === @streamReadable);
-    var stream = reader.@ownerReadableStream;
+    const stream = reader.@ownerReadableStream;
     if (stream.@queue.content.length) {
-        var chunk = @dequeueValue(stream.@queue);
+        const chunk = @dequeueValue(stream.@queue);
         if (!stream.@closeRequested)
             @requestReadableStreamPull(stream);
         else if (!stream.@queue.content.length)
             @finishClosingReadableStream(stream);
         return @Promise.@resolve({value: chunk, done: false});
     }
-    var readPromiseCapability = @newPromiseCapability(@Promise);
+    const readPromiseCapability = @newPromiseCapability(@Promise);
     reader.@readRequests.push(readPromiseCapability);
     @requestReadableStreamPull(stream);
     return readPromiseCapability.@promise;
index 71e10e6..7a8e63e 100644 (file)
@@ -64,7 +64,7 @@ function releaseLock()
          return;
 
     if (this.@readRequests.length)
-        throw new @TypeError();
+        throw new @TypeError("There are still pending read requests, cannot release the lock");
 
     @closeReadableStreamReader(this);
 }
index cbc1b21..fcd8c99 100644 (file)
@@ -31,7 +31,7 @@ function invokeOrNoop(object, key, args)
 {
     "use strict";
 
-    var method = object[key];
+    const method = object[key];
     if (typeof method === "undefined")
         return;
     return method.@apply(object, args);
@@ -42,11 +42,10 @@ function promiseInvokeOrNoop(object, key, args)
     "use strict";
 
     try {
-        var method = object[key];
+        const method = object[key];
         if (typeof method === "undefined")
             return @Promise.@resolve();
-        var result = method.@apply(object, args);
-        return @Promise.@resolve(result);
+        return @Promise.@resolve(method.@apply(object, args));
     }
     catch(error) {
         return @Promise.@reject(error);
@@ -62,8 +61,7 @@ function promiseInvokeOrFallbackOrNoop(object, key1, args1, key2, args2)
         const method = object[key1];
         if (typeof method === "undefined")
             return @promiseInvokeOrNoop(object, key2, args2);
-        const result = method.@apply(object, args1);
-        return @Promise.@resolve(result);
+        return @Promise.@resolve(method.@apply(object, args1));
     }
     catch(error) {
         return @Promise.@reject(error);
@@ -77,7 +75,7 @@ function validateAndNormalizeQueuingStrategy(size, highWaterMark)
     if (size !== undefined && typeof size !== "function")
         throw new @TypeError("size parameter must be a function");
 
-    var normalizedStrategy = { };
+    const normalizedStrategy = { };
 
     normalizedStrategy.size = size;
     normalizedStrategy.highWaterMark = Number(highWaterMark);
@@ -92,6 +90,8 @@ function validateAndNormalizeQueuingStrategy(size, highWaterMark)
 
 function newQueue()
 {
+    "use strict";
+
     return { content: [], size: 0 };
 }
 
@@ -99,24 +99,26 @@ function dequeueValue(queue)
 {
     "use strict";
 
-    var record = queue.content.shift();
+    const record = queue.content.shift();
     queue.size -= record.size;
     return record.value;
 }
 
 function enqueueValueWithSize(queue, value, size)
 {
+    "use strict";
+
     size = Number(size);
     if (Number.isNaN(size) || !Number.isFinite(size) || size < 0)
         throw new @RangeError("size has an incorrect value");
     queue.content.push({ value: value, size: size });
     queue.size += size;
-
-    return undefined;
 }
 
 function peekQueueValue(queue)
 {
+    "use strict";
+
     @assert(queue.content.length > 0);
 
     return queue.content[0].value;
index f55fe7d..239078a 100644 (file)
@@ -53,10 +53,9 @@ function initializeWritableStream(underlyingSink, strategy)
 
     @syncWritableStreamStateWithQueue(this);
 
-    var error = @errorWritableStream.bind(this);
-    var startResult = @invokeOrNoop(underlyingSink, "start", [error]);
-    this.@startedPromise = @Promise.@resolve(startResult);
-    var _this = this;
+    const error = @errorWritableStream.bind(this);
+    this.@startedPromise = @Promise.@resolve(@invokeOrNoop(underlyingSink, "start", [error]));
+    const _this = this;
     @Promise.prototype.@then.@call(this.@startedPromise, function() {
         _this.@started = true;
         _this.@startedPromise = undefined;
@@ -78,7 +77,7 @@ function abort(reason)
     if (this.@state === @streamErrored)
         return @Promise.@reject(this.@storedError);
 
-    @errorWritableStream.@apply(this, [reason]);
+    @errorWritableStream.@call(this, reason);
 
     const sinkAbortPromise = @promiseInvokeOrFallbackOrNoop(this.@underlyingSink, "abort", [reason], "close", []);
 
@@ -99,7 +98,7 @@ function close()
         return @Promise.@reject(this.@storedError);
 
     if (this.@state === @streamWaiting)
-        this.@readyPromiseCapability.@resolve.@call(undefined, undefined);
+        this.@readyPromiseCapability.@resolve.@call();
 
     this.@state = @streamClosing;
     @enqueueValueWithSize(this.@queue, "close", 0);
index b57ebaf..429d587 100644 (file)
@@ -50,7 +50,7 @@ function syncWritableStreamStateWithQueue(stream)
     }
     if (!shouldApplyBackpressure && stream.@state === @streamWaiting) {
         stream.@state = @streamWritable;
-        stream.@readyPromiseCapability.@resolve.@call(undefined, undefined);
+        stream.@readyPromiseCapability.@resolve.@call();
     }
 }
 
@@ -59,34 +59,35 @@ function errorWritableStream(e)
     "use strict";
 
     if (this.@state === @streamClosed || this.@state === @streamErrored)
-        return undefined;
+        return;
     while (this.@queue.content.length > 0) {
-        var writeRecord = @dequeueValue(this.@queue);
+        const writeRecord = @dequeueValue(this.@queue);
         if (writeRecord !== "close")
             writeRecord.promiseCapability.@reject.@call(undefined, e);
     }
     this.@storedError = e;
     if (this.@state === @streamWaiting)
-        this.@readyPromiseCapability.@resolve.@call(undefined, undefined);
+        this.@readyPromiseCapability.@resolve.@call();
     this.@closedPromiseCapability.@reject.@call(undefined, e);
     this.@state = @streamErrored;
-    return undefined;
 }
 
 function callOrScheduleWritableStreamAdvanceQueue(stream)
 {
+    "use strict";
+
     if (!stream.@started)
         @Promise.prototype.@then.@call(stream.@startedPromise, function() { @writableStreamAdvanceQueue(stream); });
     else
         @writableStreamAdvanceQueue(stream);
-
-    return undefined;
 }
 
 function writableStreamAdvanceQueue(stream)
 {
+    "use strict";
+
     if (stream.@queue.content.length === 0 || stream.@writing)
-        return undefined;
+        return;
 
     const writeRecord = @peekQueueValue(stream.@queue);
     if (writeRecord === "close") {
@@ -94,7 +95,7 @@ function writableStreamAdvanceQueue(stream)
         @dequeueValue(stream.@queue);
         @assert(stream.@queue.content.length === 0);
         @closeWritableStream(stream);
-        return undefined;
+        return;
     }
 
     stream.@writing = true;
@@ -103,7 +104,7 @@ function writableStreamAdvanceQueue(stream)
             if (stream.@state === @streamErrored)
                 return;
             stream.@writing = false;
-            writeRecord.promiseCapability.@resolve.@call(undefined, undefined);
+            writeRecord.promiseCapability.@resolve.@call();
             @dequeueValue(stream.@queue);
             @syncWritableStreamStateWithQueue(stream);
             @writableStreamAdvanceQueue(stream);
@@ -112,25 +113,23 @@ function writableStreamAdvanceQueue(stream)
             @errorWritableStream.@apply(stream, [r]);
         }
     );
-
-    return undefined;
 }
 
 function closeWritableStream(stream)
 {
+    "use strict";
+
     @assert(stream.@state === @streamClosing);
     @Promise.prototype.@then.@call(@promiseInvokeOrNoop(stream.@underlyingSink, "close"),
         function() {
             if (stream.@state === @streamErrored)
                 return;
             @assert(stream.@state === @streamClosing);
-            stream.@closedPromiseCapability.@resolve.@call(undefined, undefined);
+            stream.@closedPromiseCapability.@resolve.@call();
             stream.@state = @streamClosed;
         },
         function(r) {
             @errorWritableStream.@apply(stream, [r]);
         }
     );
-
-    return undefined;
 }