-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WritableStream: clear algorithms once they will no longer be called #940
Changes from 3 commits
a129479
c8fee18
598403a
6f1ac85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -717,7 +717,9 @@ class WritableStreamDefaultController { | |
} | ||
|
||
[AbortSteps](reason) { | ||
return this._abortAlgorithm(reason); | ||
const result = this._abortAlgorithm(reason); | ||
WritableStreamDefaultControllerClearAlgorithms(this); | ||
return result; | ||
} | ||
|
||
[ErrorSteps]() { | ||
|
@@ -798,6 +800,13 @@ function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyi | |
abortAlgorithm, highWaterMark, sizeAlgorithm); | ||
} | ||
|
||
// ClearAlgorithms may be called twice. Erroring the same stream in multiple ways will often result in redundant calls. | ||
function WritableStreamDefaultControllerClearAlgorithms(controller) { | ||
controller._writeAlgorithm = undefined; | ||
controller._closeAlgorithm = undefined; | ||
controller._abortAlgorithm = undefined; | ||
} | ||
|
||
function WritableStreamDefaultControllerClose(controller) { | ||
EnqueueValueWithSize(controller, 'close', 0); | ||
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); | ||
|
@@ -885,6 +894,7 @@ function WritableStreamDefaultControllerProcessClose(controller) { | |
assert(controller._queue.length === 0); | ||
|
||
const sinkClosePromise = controller._closeAlgorithm(); | ||
WritableStreamDefaultControllerClearAlgorithms(controller); | ||
sinkClosePromise.then( | ||
() => { | ||
WritableStreamFinishInFlightClose(stream); | ||
|
@@ -919,6 +929,9 @@ function WritableStreamDefaultControllerProcessWrite(controller, chunk) { | |
WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); | ||
}, | ||
reason => { | ||
if (stream._state === 'writable') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check does not appear in the spec text. I believe it should be removed from the reference implementation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch! Actually this check is required, and I failed to add it to the spec text. Without this check, if a write() rejects while an abort() is already in progress, the abortAlgorithm will be cleared too early and so when the time comes to call the underlying source abort() it will fail. |
||
WritableStreamDefaultControllerClearAlgorithms(controller); | ||
} | ||
WritableStreamFinishInFlightWriteWithError(stream, reason); | ||
} | ||
) | ||
|
@@ -937,6 +950,7 @@ function WritableStreamDefaultControllerError(controller, error) { | |
|
||
assert(stream._state === 'writable'); | ||
|
||
WritableStreamDefaultControllerClearAlgorithms(controller); | ||
WritableStreamStartErroring(stream, error); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: line too long