Skip to content

Commit

Permalink
Handle sync errors from calling return()
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Nov 10, 2020
1 parent 2fc060f commit b365e91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 8 additions & 4 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -819,10 +819,14 @@ option. If {{UnderlyingSource/type}} is set to undefined (including via omission
1. Perform ! [$ReadableStreamDefaultControllerEnqueue$](stream.[=ReadableStream/[[controller]]=],
|value|).
1. Let |cancelAlgorithm| be the following steps:
1. Let |returnMethod| be ? [$GetMethod$](|iteratorRecord|.\[[Iterator]], "`return`").
1. If |returnMethod| is undefined, return [=a promise resolved with=] undefined.
1. Let |returnResult| be ? [$Call$](|returnMethod|, |iteratorRecord|.\[[Iterator]]).
1. Return [=a promise resolved with=] |returnResult|.
1. Let |returnMethod| be [$GetMethod$](|iteratorRecord|.\[[Iterator]], "`return`").
1. If |returnMethod| is an abrupt completion, return [=a promise rejected with=]
|returnMethod|.\[[Value]].
1. If |returnMethod|.\[[Value]] is undefined, return [=a promise resolved with=] undefined.
1. Let |returnResult| be [$Call$](|returnMethod|.\[[Value]], |iteratorRecord|.\[[Iterator]]).
1. If |returnResult| is an abrupt completion, return [=a promise rejected with=]
|returnResult|.\[[Value]].
1. Return [=a promise resolved with=] |returnResult|.\[[Value]].
1. Set |stream| to ! [$CreateReadableStream$](|startAlgorithm|, |pullAlgorithm|, |cancelAlgorithm|).
1. Return |stream|.
</div>
Expand Down
14 changes: 12 additions & 2 deletions reference-implementation/lib/ReadableStream-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,21 @@ exports.implementation = class ReadableStreamImpl {
}

function cancelAlgorithm() {
const returnMethod = GetMethod(iteratorRecord.iterator, 'return');
let returnMethod;
try {
returnMethod = GetMethod(iteratorRecord.iterator, 'return');
} catch (e) {
return promiseRejectedWith(e);
}
if (returnMethod === undefined) {
return promiseResolvedWith(undefined);
}
const returnResult = Call(returnMethod, iteratorRecord.iterator);
let returnResult;
try {
returnResult = Call(returnMethod, iteratorRecord.iterator);
} catch (e) {
return promiseRejectedWith(e);
}
return promiseResolvedWith(returnResult);
}

Expand Down

0 comments on commit b365e91

Please sign in to comment.