Changeset 194035 in webkit
- Timestamp:
- Dec 14, 2015 9:27:27 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r194033 r194035 1 2015-12-14 Youenn Fablet <youenn.fablet@crf.canon.fr> 2 3 [Streams API] Directly use @then as much as possible 4 https://bugs.webkit.org/show_bug.cgi?id=151631 5 6 Reviewed by Darin Adler. 7 8 Moved from @Promise.prototype.@then.@call(promise,...) to promise.@then.(...) 9 for promise objects that are not exposed to user scripts. 10 11 Updated promiseInvokeXX stream utility functions to ensure that returned promise always has a @then. 12 This allows improving the readability of code calling promiseInvokeXX functions. 13 Changed invokeOrNoop to promiseInvokeOrNoopNoCatch as invokeOrNoop 14 result is always wrapped as a promise using Promise.resolve. 15 16 No change in behavior. 17 18 * Modules/streams/ReadableStream.js: 19 (initializeReadableStream): 20 * Modules/streams/ReadableStreamInternals.js: 21 (teeReadableStream): 22 (teeReadableStreamBranch2CancelFunction): 23 (cancelReadableStream): 24 * Modules/streams/StreamInternals.js: 25 (shieldingPromiseResolve): introduced this routine to ensure the returned promise has a @then property. 26 (promiseInvokeOrNoopNoCatch): 27 (promiseInvokeOrNoop): 28 (promiseInvokeOrFallbackOrNoop): 29 * Modules/streams/WritableStream.js: 30 (initializeWritableStream): 31 (abort): 32 * Modules/streams/WritableStreamInternals.js: 33 (callOrScheduleWritableStreamAdvanceQueue): 34 1 35 2015-12-14 Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr> 2 36 -
trunk/Source/WebCore/Modules/streams/ReadableStream.js
r193832 r194035 56 56 this.@strategy = @validateAndNormalizeQueuingStrategy(strategy.size, strategy.highWaterMark); 57 57 58 const result = @invokeOrNoop(underlyingSource, "start", [this.@controller]); 59 @Promise.prototype.@then.@call(@Promise.@resolve(result), () => { 58 @promiseInvokeOrNoopNoCatch(underlyingSource, "start", [this.@controller]).@then(() => { 60 59 this.@started = true; 61 60 @requestReadableStreamPull(this); … … 105 104 "use strict"; 106 105 107 // We are not shielding against methods and attributes of the reader and destination as those objects don't have to 108 // be necessarily ReadableStreamReader and WritableStream. 106 // FIXME: rewrite pipeTo so as to require to have 'this' as a ReadableStream and destination be a WritableStream. 107 // See https://github.com/whatwg/streams/issues/407. 108 // We should shield the pipeTo implementation at the same time. 109 109 110 110 const preventClose = @isObject(options) && !!options.preventClose; -
trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js
r193899 r194035 97 97 }); 98 98 99 @Promise.prototype.@then.@call(reader.closed,undefined, function(e) {99 reader.@closedPromiseCapability.@promise.@then(undefined, function(e) { 100 100 if (teeState.closedOrErrored) 101 101 return; … … 147 147 teeState.reason1 = r; 148 148 if (teeState.canceled2) { 149 @ Promise.prototype.@then.@call(@cancelReadableStream(stream, [teeState.reason1, teeState.reason2]),150 151 149 @cancelReadableStream(stream, [teeState.reason1, teeState.reason2]).@then( 150 teeState.cancelPromiseCapability.@resolve, 151 teeState.cancelPromiseCapability.@reject); 152 152 } 153 153 return teeState.cancelPromiseCapability.@promise; … … 163 163 teeState.reason2 = r; 164 164 if (teeState.canceled1) { 165 @ Promise.prototype.@then.@call(@cancelReadableStream(stream, [teeState.reason1, teeState.reason2]),166 167 165 @cancelReadableStream(stream, [teeState.reason1, teeState.reason2]).@then( 166 teeState.cancelPromiseCapability.@resolve, 167 teeState.cancelPromiseCapability.@reject); 168 168 } 169 169 return teeState.cancelPromiseCapability.@promise; … … 235 235 stream.@pulling = true; 236 236 237 const promise = @promiseInvokeOrNoop(stream.@underlyingSource, "pull", [stream.@controller]); 238 @Promise.prototype.@then.@call(promise, function() { 237 @promiseInvokeOrNoop(stream.@underlyingSource, "pull", [stream.@controller]).@then(function() { 239 238 stream.@pulling = false; 240 239 if (stream.@pullAgain) { … … 274 273 stream.@queue = @newQueue(); 275 274 @finishClosingReadableStream(stream); 276 return @ Promise.prototype.@then.@call(@promiseInvokeOrNoop(stream.@underlyingSource, "cancel", [reason]),function() { });275 return @promiseInvokeOrNoop(stream.@underlyingSource, "cancel", [reason]).@then(function() { }); 277 276 } 278 277 -
trunk/Source/WebCore/Modules/streams/StreamInternals.js
r193899 r194035 28 28 // @internal 29 29 30 function invokeOrNoop(object, key, args) 30 function shieldingPromiseResolve(result) 31 { 32 const promise = @Promise.@resolve(result); 33 if (promise.@then === undefined) 34 promise.@then = @Promise.prototype.@then; 35 return promise; 36 } 37 38 function promiseInvokeOrNoopNoCatch(object, key, args) 31 39 { 32 40 "use strict"; 33 41 34 42 const method = object[key]; 35 if ( typeof method === "undefined")36 return ;37 return method.@apply(object, args);43 if (method === undefined) 44 return @Promise.@resolve(); 45 return @shieldingPromiseResolve(method.@apply(object, args)); 38 46 } 39 47 … … 43 51 44 52 try { 45 const method = object[key]; 46 if (typeof method === "undefined") 47 return @Promise.@resolve(); 48 return @Promise.@resolve(method.@apply(object, args)); 53 return @promiseInvokeOrNoopNoCatch(object, key, args); 49 54 } 50 55 catch(error) { … … 60 65 try { 61 66 const method = object[key1]; 62 if ( typeof method === "undefined")63 return @promiseInvokeOrNoop (object, key2, args2);64 return @ Promise.@resolve(method.@apply(object, args1));67 if (method === undefined) 68 return @promiseInvokeOrNoopNoCatch(object, key2, args2); 69 return @shieldingPromiseResolve(method.@apply(object, args1)); 65 70 } 66 71 catch(error) { -
trunk/Source/WebCore/Modules/streams/WritableStream.js
r192878 r194035 57 57 @errorWritableStream(this, e); 58 58 }; 59 this.@startedPromise = @ Promise.@resolve(@invokeOrNoop(underlyingSink, "start", [errorFunction]));60 @Promise.prototype.@then.@call(this.@startedPromise,() => {59 this.@startedPromise = @promiseInvokeOrNoopNoCatch(underlyingSink, "start", [errorFunction]); 60 this.@startedPromise.@then(() => { 61 61 this.@started = true; 62 62 this.@startedPromise = undefined; … … 81 81 @errorWritableStream(this, reason); 82 82 83 const sinkAbortPromise = @promiseInvokeOrFallbackOrNoop(this.@underlyingSink, "abort", [reason], "close", []); 84 85 return @Promise.prototype.@then.@call(sinkAbortPromise, function() { }); 83 return @promiseInvokeOrFallbackOrNoop(this.@underlyingSink, "abort", [reason], "close", []).@then(function() { }); 86 84 } 87 85 -
trunk/Source/WebCore/Modules/streams/WritableStreamInternals.js
r192878 r194035 78 78 79 79 if (!stream.@started) 80 @Promise.prototype.@then.@call(stream.@startedPromise,function() { @writableStreamAdvanceQueue(stream); });80 stream.@startedPromise.@then(function() { @writableStreamAdvanceQueue(stream); }); 81 81 else 82 82 @writableStreamAdvanceQueue(stream); … … 100 100 101 101 stream.@writing = true; 102 @ Promise.prototype.@then.@call(@promiseInvokeOrNoop(stream.@underlyingSink, "write", [writeRecord.chunk]),102 @promiseInvokeOrNoop(stream.@underlyingSink, "write", [writeRecord.chunk]).@then( 103 103 function() { 104 104 if (stream.@state === @streamErrored) … … 121 121 122 122 @assert(stream.@state === @streamClosing); 123 @ Promise.prototype.@then.@call(@promiseInvokeOrNoop(stream.@underlyingSink, "close"),123 @promiseInvokeOrNoop(stream.@underlyingSink, "close").@then( 124 124 function() { 125 125 if (stream.@state === @streamErrored)
Note: See TracChangeset
for help on using the changeset viewer.