Skip to content

Commit

Permalink
Bug 1657509 - Always resolve ReadableStream's tee()'s cancel promise …
Browse files Browse the repository at this point in the history
…after the stream closes or errors. r=arai

Seems like the existing step numbers refer to a differently formatted spec. I updated the numbers
where I changed something to match https://streams.spec.whatwg.org/.

Differential Revision: https://phabricator.services.mozilla.com/D109237
  • Loading branch information
evilpie committed Mar 22, 2021
1 parent d581304 commit 108b1f3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 150 deletions.
52 changes: 36 additions & 16 deletions js/src/builtin/streams/ReadableStreamOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,32 +213,38 @@ static bool TeeReaderReadHandler(JSContext* cx, unsigned argc, Value* vp) {
done = doneVal.toBoolean();
}

// Step 12.c.v: If done is true,
if (done) {
// Step 12.c.v.1: If canceled1 is false,
// Step 12.3 close steps

// Step 1: Set reading to false (done unconditionally above).
// Step 2: If canceled1 is false, perform
// ! ReadableStreamDefaultControllerClose(branch1.[[controller]]).
if (!unwrappedTeeState->canceled1()) {
// Step 12.c.v.1.a: Perform
// ! ReadableStreamDefaultControllerClose(
// branch1.[[readableStreamController]]).
Rooted<ReadableStreamDefaultController*> unwrappedBranch1(
cx, unwrappedTeeState->branch1());
if (!ReadableStreamDefaultControllerClose(cx, unwrappedBranch1)) {
return false;
}
}

// Step 12.c.v.2: If canceled2 is false,
// Step 3: If canceled2 is false, perform
// ! ReadableStreamDefaultControllerClose(branch2.[[controller]]).
if (!unwrappedTeeState->canceled2()) {
// Step 12.c.v.2.a: Perform
// ! ReadableStreamDefaultControllerClose(
// branch2.[[readableStreamController]]).
Rooted<ReadableStreamDefaultController*> unwrappedBranch2(
cx, unwrappedTeeState->branch2());
if (!ReadableStreamDefaultControllerClose(cx, unwrappedBranch2)) {
return false;
}
}

// Step 4: Resolve cancelPromise with undefined.
Rooted<PromiseObject*> unwrappedCancelPromise(
cx, unwrappedTeeState->cancelPromise());
MOZ_ASSERT(unwrappedCancelPromise != nullptr);
if (!ResolveUnwrappedPromiseWithUndefined(cx, unwrappedCancelPromise)) {
return false;
}

args.rval().setUndefined();
return true;
}
Expand Down Expand Up @@ -469,9 +475,11 @@ static bool TeeReaderReadHandler(JSContext* cx, unsigned argc, Value* vp) {
return cancelPromise;
}

/**
* Streams spec, 3.4.10. step 18:
* Upon rejection of reader.[[closedPromise]] with reason r,
/*
* https://streams.spec.whatwg.org/#readable-stream-tee
* ReadableStreamTee(stream, cloneForBranch2)
*
* Step 18: Upon rejection of reader.[[closedPromise]] with reason r,
*/
static bool TeeReaderErroredHandler(JSContext* cx, unsigned argc,
JS::Value* vp) {
Expand All @@ -482,22 +490,34 @@ static bool TeeReaderErroredHandler(JSContext* cx, unsigned argc,

Rooted<ReadableStreamDefaultController*> unwrappedBranchController(cx);

// Step 18.a.i: Perform
// Step 18.1: Perform
// ! ReadableStreamDefaultControllerError(
// branch1.[[readableStreamController]], r).
// branch1.[[controller]], r).
unwrappedBranchController = teeState->branch1();
if (!ReadableStreamControllerError(cx, unwrappedBranchController, reason)) {
return false;
}

// Step a.ii: Perform
// Step 18.2: Perform
// ! ReadableStreamDefaultControllerError(
// branch2.[[readableStreamController]], r).
// branch2.[[controller]], r).
unwrappedBranchController = teeState->branch2();
if (!ReadableStreamControllerError(cx, unwrappedBranchController, reason)) {
return false;
}

// Step 18.3: If canceled1 is false or canceled2 is false,
// resolve cancelPromise with undefined.
if (!teeState->canceled1() || !teeState->canceled2()) {
Rooted<PromiseObject*> unwrappedCancelPromise(cx,
teeState->cancelPromise());
MOZ_ASSERT(unwrappedCancelPromise != nullptr);

if (!ResolveUnwrappedPromiseWithUndefined(cx, unwrappedCancelPromise)) {
return false;
}
}

args.rval().setUndefined();
return true;
}
Expand Down
134 changes: 0 additions & 134 deletions testing/web-platform/meta/streams/readable-streams/tee.any.js.ini

This file was deleted.

0 comments on commit 108b1f3

Please sign in to comment.