Bug 1504464 - Part 4: Comment-only changes. r=jwalden

Differential Revision: https://phabricator.services.mozilla.com/D14499

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jason Orendorff 2019-01-14 20:32:31 +00:00
parent 1c0b4e6323
commit 14e641c6a6

View File

@ -838,12 +838,13 @@ MOZ_MUST_USE ReadableStream* CreateReadableStream(
// Step 1: If highWaterMark was not passed, set it to 1 (implicit).
// Step 2: If sizeAlgorithm was not passed, set it to an algorithm that
// returns 1 (implicit). Step 3: Assert: ! IsNonNegativeNumber(highWaterMark)
// is true.
// returns 1 (implicit).
// Step 3: Assert: ! IsNonNegativeNumber(highWaterMark) is true.
MOZ_ASSERT(highWaterMark >= 0);
// Step 4: Let stream be ObjectCreate(the original value of ReadableStream's
// prototype property). Step 5: Perform ! InitializeReadableStream(stream).
// prototype property).
// Step 5: Perform ! InitializeReadableStream(stream).
Rooted<ReadableStream*> stream(cx, ReadableStream::create(cx, proto));
if (!stream) {
return nullptr;
@ -854,7 +855,6 @@ MOZ_MUST_USE ReadableStream* CreateReadableStream(
// Step 7: Perform ? SetUpReadableStreamDefaultController(stream,
// controller, startAlgorithm, pullAlgorithm, cancelAlgorithm,
// highWaterMark, sizeAlgorithm).
if (!SetUpReadableStreamDefaultController(
cx, stream, sourceAlgorithms, underlyingSource, pullMethod,
cancelMethod, highWaterMark, sizeAlgorithm)) {
@ -899,7 +899,7 @@ MOZ_MUST_USE /* static */ ReadableStream* ReadableStream::create(
}
// Streams spec, 3.3.6. IsReadableStream ( x )
// Using is<T> instead.
// Using UnwrapAndTypeCheck templates instead.
// Streams spec, 3.3.7. IsReadableStreamDisturbed ( stream )
// Using stream->disturbed() instead.
@ -1317,8 +1317,10 @@ inline static MOZ_MUST_USE bool AppendToListAtSlot(
HandleObject obj);
/**
* Streams spec, 3.4.1. ReadableStreamAddReadIntoRequest ( stream, forAuthorCode
* ) Streams spec, 3.4.2. ReadableStreamAddReadRequest ( stream, forAuthorCode )
* Streams spec, 3.4.1.
* ReadableStreamAddReadIntoRequest ( stream, forAuthorCode )
* Streams spec, 3.4.2.
* ReadableStreamAddReadRequest ( stream, forAuthorCode )
*
* Our implementation does not pass around forAuthorCode parameters in the same
* places as the standard, but the effect is the same. See the comment on
@ -1326,8 +1328,9 @@ inline static MOZ_MUST_USE bool AppendToListAtSlot(
*/
static MOZ_MUST_USE JSObject* ReadableStreamAddReadOrReadIntoRequest(
JSContext* cx, Handle<ReadableStream*> unwrappedStream) {
// Step 1: Assert: ! IsReadableStreamBYOBReader(stream.[[reader]]) is true.
// Skipped: handles both kinds of readers.
// Step 1: Assert: ! IsReadableStream{BYOB,Default}Reader(stream.[[reader]])
// is true.
// (Only default readers exist so far.)
Rooted<ReadableStreamReader*> unwrappedReader(
cx, UnwrapReaderFromStream(cx, unwrappedStream));
if (!unwrappedReader) {
@ -1418,7 +1421,7 @@ static MOZ_MUST_USE JSObject* ReadableStreamCancel(
return nullptr;
}
// Step 6: Return the result of transforming sourceCancelPromise by a
// Step 6: Return the result of transforming sourceCancelPromise with a
// fulfillment handler that returns undefined.
RootedAtom funName(cx, cx->names().empty);
RootedFunction returnUndefined(
@ -1493,7 +1496,6 @@ MOZ_MUST_USE bool ReadableStreamCloseInternal(
}
// Step 6: Resolve reader.[[closedPromise]] with undefined.
// Step 7: Return (implicit).
RootedObject closedPromise(cx, unwrappedReader->closedPromise());
if (!cx->compartment()->wrap(cx, &closedPromise)) {
return false;
@ -1583,15 +1585,15 @@ MOZ_MUST_USE bool ReadableStreamErrorInternal(
return false;
}
// Steps 7,8: (Identical in our implementation.)
// Step a: Repeat for each readRequest that is an element of
// reader.[[readRequests]],
// Steps 7-8: (Identical in our implementation.)
// Step 7.a/8.b: Repeat for each read{Into}Request that is an element of
// reader.[[read{Into}Requests]],
Rooted<ListObject*> unwrappedReadRequests(cx, unwrappedReader->requests());
RootedObject readRequest(cx);
RootedValue val(cx);
uint32_t len = unwrappedReadRequests->length();
for (uint32_t i = 0; i < len; i++) {
// Step i: Reject readRequest.[[promise]] with e.
// Step i: Reject read{Into}Request.[[promise]] with e.
val = unwrappedReadRequests->get(i);
readRequest = &val.toObject();
@ -1607,7 +1609,7 @@ MOZ_MUST_USE bool ReadableStreamErrorInternal(
}
}
// Step b: Set reader.[[readRequests]] to a new empty List.
// Step 7.b/8.c: Set reader.[[read{Into}Requests]] to a new empty List.
if (!SetNewList(cx, unwrappedReader, ReadableStreamReader::Slot_Requests)) {
return false;
}
@ -1615,9 +1617,8 @@ MOZ_MUST_USE bool ReadableStreamErrorInternal(
// Step 9: Reject reader.[[closedPromise]] with e.
//
// The closedPromise might have been created in another compartment.
// RejectPromise can deal with wrapped Promise objects, but has to be
// with all arguments in the current compartment, so we do need to wrap
// the Promise.
// RejectPromise can deal with wrapped Promise objects, but all its arguments
// must be same-compartment with cx, so we do need to wrap the Promise.
RootedObject closedPromise(cx, unwrappedReader->closedPromise());
if (!cx->compartment()->wrap(cx, &closedPromise)) {
return false;
@ -1663,11 +1664,11 @@ static MOZ_MUST_USE bool ReadableStreamFulfillReadOrReadIntoRequest(
return false;
}
// Step 2: Let readIntoRequest be the first element of
// reader.[[readIntoRequests]].
// Step 3: Remove readIntoRequest from reader.[[readIntoRequests]], shifting
// all other elements downward (so that the second becomes the first,
// and so on).
// Step 2: Let read{Into}Request be the first element of
// reader.[[read{Into}Requests]].
// Step 3: Remove read{Into}Request from reader.[[read{Into}Requests]],
// shifting all other elements downward (so that the second becomes
// the first, and so on).
Rooted<ListObject*> unwrappedReadIntoRequests(cx,
unwrappedReader->requests());
RootedObject readIntoRequest(
@ -1697,7 +1698,7 @@ static MOZ_MUST_USE bool ReadableStreamFulfillReadOrReadIntoRequest(
*/
static uint32_t ReadableStreamGetNumReadRequests(ReadableStream* stream) {
// Step 1: Return the number of elements in
// stream.[[reader]].[[readRequests]].
// stream.[[reader]].[[read{Into}Requests]].
if (!stream->hasReader()) {
return 0;
}
@ -1724,15 +1725,14 @@ static MOZ_MUST_USE bool ReadableStreamHasDefaultReader(
*result = false;
return true;
}
// Step 3: If ! ReadableStreamDefaultReader(reader) is false, return false.
// Step 4: Return true.
Rooted<ReadableStreamReader*> unwrappedReader(
cx, UnwrapReaderFromStream(cx, unwrappedStream));
if (!unwrappedReader) {
return false;
}
// Step 3: If ! ReadableStreamDefaultReader(reader) is false, return false.
// Step 4: Return true.
*result = unwrappedReader->is<ReadableStreamDefaultReader>();
return true;
}
@ -1794,7 +1794,7 @@ bool ReadableStreamDefaultReader::constructor(JSContext* cx, unsigned argc,
}
// Step 1: If ! IsReadableStream(stream) is false, throw a TypeError
// exception.
// exception.
Rooted<ReadableStream*> unwrappedStream(
cx, UnwrapAndTypeCheckArgument<ReadableStream>(
cx, args, "ReadableStreamDefaultReader constructor", 0));
@ -2164,8 +2164,8 @@ static MOZ_MUST_USE JSObject* ReadableStreamControllerPullSteps(
JSContext* cx, Handle<ReadableStreamController*> unwrappedController);
/**
* Streams spec, 3.7.7. ReadableStreamDefaultReaderRead ( reader [,
* forAuthorCode ] )
* Streams spec, 3.7.7.
* ReadableStreamDefaultReaderRead ( reader [, forAuthorCode ] )
*/
static MOZ_MUST_USE JSObject* ReadableStreamDefaultReaderRead(
JSContext* cx, Handle<ReadableStreamDefaultReader*> unwrappedReader) {
@ -2182,7 +2182,7 @@ static MOZ_MUST_USE JSObject* ReadableStreamDefaultReaderRead(
// Step 4: Set stream.[[disturbed]] to true.
unwrappedStream->setDisturbed();
// Step 5: If stream.[[state]] is "closed", return a new promise resolved with
// Step 5: If stream.[[state]] is "closed", return a promise resolved with
// ! ReadableStreamCreateReadResult(undefined, true, forAuthorCode).
if (unwrappedStream->closed()) {
RootedObject iterResult(
@ -2195,7 +2195,7 @@ static MOZ_MUST_USE JSObject* ReadableStreamDefaultReaderRead(
return PromiseObject::unforgeableResolve(cx, iterResultVal);
}
// Step 6: If stream.[[state]] is "errored", return a new promise rejected
// Step 6: If stream.[[state]] is "errored", return a promise rejected
// with stream.[[storedError]].
if (unwrappedStream->errored()) {
RootedValue storedError(cx, unwrappedStream->storedError());
@ -2220,29 +2220,28 @@ inline static MOZ_MUST_USE bool ReadableStreamControllerCallPullIfNeeded(
JSContext* cx, Handle<ReadableStreamController*> unwrappedController);
/**
* Streams spec, 3.8.3, step 11.a.
* Streams spec, 3.9.11. SetUpReadableStreamDefaultController, step 11
* and
* Streams spec, 3.10.3, step 16.a.
* Streams spec, 3.12.26. SetUpReadableByteStreamController, step 16:
* Upon fulfillment of startPromise, [...]
*/
static bool ControllerStartHandler(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
Rooted<ReadableStreamController*> controller(
cx, TargetFromHandler<ReadableStreamController>(args));
// Step i: Set controller.[[started]] to true.
// Step a: Set controller.[[started]] to true.
controller->setStarted();
// Step ii: Assert: controller.[[pulling]] is false.
// Step b: Assert: controller.[[pulling]] is false.
MOZ_ASSERT(!controller->pulling());
// Step iii: Assert: controller.[[pullAgain]] is false.
// Step c: Assert: controller.[[pullAgain]] is false.
MOZ_ASSERT(!controller->pullAgain());
// Step iv: Perform
// ! ReadableStreamDefaultControllerCallPullIfNeeded(controller).
// or
// Step iv: Perform
// ! ReadableByteStreamControllerCallPullIfNeeded((controller).
// Step d: Perform
// ! ReadableStreamDefaultControllerCallPullIfNeeded(controller)
// (or ReadableByteStreamControllerCallPullIfNeeded(controller)).
if (!ReadableStreamControllerCallPullIfNeeded(cx, controller)) {
return false;
}
@ -2251,9 +2250,10 @@ static bool ControllerStartHandler(JSContext* cx, unsigned argc, Value* vp) {
}
/**
* Streams spec, 3.9.11, step 12.a.
* Streams spec, 3.9.11. SetUpReadableStreamDefaultController, step 12
* and
* Streams spec, 3.12.26, step 17.a.
* Streams spec, 3.12.26. SetUpReadableByteStreamController, step 17:
* Upon rejection of startPromise with reason r, [...]
*/
static bool ControllerStartFailedHandler(JSContext* cx, unsigned argc,
Value* vp) {
@ -2261,10 +2261,9 @@ static bool ControllerStartFailedHandler(JSContext* cx, unsigned argc,
Rooted<ReadableStreamController*> controller(
cx, TargetFromHandler<ReadableStreamController>(args));
// 3.9.11, Step 12.a: Perform
// ! ReadableStreamDefaultControllerError(controller, r).
// 3.12.26, Step 17.a: Perform
// ! ReadableByteStreamControllerError(controller, r).
// Step a: Perform
// ! ReadableStreamDefaultControllerError(controller, r)
// (or ReadableByteStreamControllerError(controller, r)).
if (!ReadableStreamControllerError(cx, controller, args.get(0))) {
return false;
}
@ -2292,8 +2291,6 @@ static MOZ_MUST_USE double ReadableStreamControllerGetDesiredSizeUnchecked(
/**
* Streams spec, 3.8.4.1. get desiredSize
* and
* Streams spec, 3.10.4.2. get desiredSize
*/
static bool ReadableStreamDefaultController_desiredSize(JSContext* cx,
unsigned argc,
@ -2308,7 +2305,7 @@ static bool ReadableStreamDefaultController_desiredSize(JSContext* cx,
return false;
}
// Streams spec, 3.9.8. steps 1-4.
// 3.9.8. ReadableStreamDefaultControllerGetDesiredSize, steps 1-4.
// 3.9.8. Step 1: Let stream be controller.[[controlledReadableStream]].
ReadableStream* unwrappedStream = unwrappedController->stream();
@ -2336,7 +2333,8 @@ static MOZ_MUST_USE bool ReadableStreamDefaultControllerClose(
Handle<ReadableStreamDefaultController*> unwrappedController);
/**
* Unified implementation of step 2 of 3.8.4.2 and steps 2-3 of 3.10.4.3.
* Unified implementation of step 2 of 3.8.4.2 and 3.8.4.3,
* and steps 2-3 of 3.10.4.3.
*/
static MOZ_MUST_USE bool VerifyControllerStateForClosing(
JSContext* cx, Handle<ReadableStreamController*> unwrappedController) {
@ -2380,10 +2378,11 @@ static bool ReadableStreamDefaultController_close(JSContext* cx, unsigned argc,
return false;
}
// Step 4: Perform ! ReadableStreamDefaultControllerClose(this).
// Step 3: Perform ! ReadableStreamDefaultControllerClose(this).
if (!ReadableStreamDefaultControllerClose(cx, unwrappedController)) {
return false;
}
args.rval().setUndefined();
return true;
}
@ -2583,11 +2582,12 @@ static MOZ_MUST_USE JSObject* ReadableStreamControllerCancelSteps(
}
}
// Step 3 of 3.8.5.1, step 4 of 3.10.5.1: Perform
// ! ReadableByteStreamControllerClearAlgorithms(this).
// Step 3 (or 4): Perform
// ! ReadableStreamDefaultControllerClearAlgorithms(this)
// (or ReadableByteStreamControllerClearAlgorithms(this)).
ReadableStreamControllerClearAlgorithms(unwrappedController);
// Step 4 of 3.8.5.1, step 5 of 3.10.5.1: Return result.
// Step 4 (or 5): Return result.
return result;
}
@ -2596,8 +2596,8 @@ inline static MOZ_MUST_USE bool DequeueValue(
MutableHandleValue chunk);
/**
* Streams spec, 3.8.5.2. ReadableStreamDefaultController [[PullSteps]](
* forAuthorCode )
* Streams spec, 3.8.5.2.
* ReadableStreamDefaultController [[PullSteps]]( forAuthorCode )
*/
static JSObject* ReadableStreamDefaultControllerPullSteps(
JSContext* cx,
@ -2614,7 +2614,7 @@ static JSObject* ReadableStreamDefaultControllerPullSteps(
}
if (unwrappedQueue && unwrappedQueue->length() != 0) {
// Step a: Let chunk be ! DequeueValue(this.[[queue]]).
// Step a: Let chunk be ! DequeueValue(this).
RootedValue chunk(cx);
if (!DequeueValue(cx, unwrappedController, &chunk)) {
return nullptr;
@ -2679,7 +2679,7 @@ static JSObject* ReadableStreamDefaultControllerPullSteps(
/**
* Streams spec, 3.9.2 and 3.12.3. step 7:
* Upon fulfillment of pullPromise,
* Upon fulfillment of pullPromise, [...]
*/
static bool ControllerPullHandler(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
@ -2842,22 +2842,20 @@ inline static MOZ_MUST_USE bool ReadableStreamControllerCallPullIfNeeded(
return false;
}
// Step 7: Upon fulfillment of pullPromise, [...]
// Step 8. Upon rejection of pullPromise with reason e, [...]
RootedObject onPullFulfilled(
cx, NewHandler(cx, ControllerPullHandler, wrappedController));
if (!onPullFulfilled) {
return false;
}
RootedObject onPullRejected(
cx, NewHandler(cx, ControllerPullFailedHandler, wrappedController));
if (!onPullRejected) {
return false;
}
return JS::AddPromiseReactions(cx, pullPromise, onPullFulfilled,
onPullRejected);
// Steps 7-8 implemented in functions above.
}
/**
@ -2868,43 +2866,57 @@ inline static MOZ_MUST_USE bool ReadableStreamControllerCallPullIfNeeded(
*/
static bool ReadableStreamControllerShouldCallPull(
ReadableStreamController* unwrappedController) {
// Step 1: Let stream be controller.[[controlledReadableStream]].
// Step 1: Let stream be controller.[[controlledReadableStream]]
// (or [[controlledReadableByteStream]]).
ReadableStream* unwrappedStream = unwrappedController->stream();
// Step 2: If stream.[[state]] is "closed" or stream.[[state]] is "errored",
// return false.
// or, equivalently
// Step 2: If stream.[[state]] is not "readable", return false.
// 3.9.3. Step 2:
// If ! ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)
// is false, return false.
// This turns out to be the same as 3.12.25 steps 2-3.
// 3.12.25 Step 2: If stream.[[state]] is not "readable", return false.
if (!unwrappedStream->readable()) {
return false;
}
// Step 3: If controller.[[closeRequested]] is true, return false.
// 3.12.25 Step 3: If controller.[[closeRequested]] is true, return false.
if (unwrappedController->closeRequested()) {
return false;
}
// Step 4: If controller.[[started]] is false, return false.
// Step 3 (or 4):
// If controller.[[started]] is false, return false.
if (!unwrappedController->started()) {
return false;
}
// Step 5: If ! IsReadableStreamLocked(stream) is true and
// 3.9.3.
// Step 4: If ! IsReadableStreamLocked(stream) is true and
// ! ReadableStreamGetNumReadRequests(stream) > 0, return true.
//
// 3.12.25.
// Step 5: If ! ReadableStreamHasDefaultReader(stream) is true and
// ! ReadableStreamGetNumReadRequests(stream) > 0, return true.
// Steps 5-6 of 3.12.24 are equivalent in our implementation.
// Step 6: If ! ReadableStreamHasBYOBReader(stream) is true and
// ! ReadableStreamGetNumReadIntoRequests(stream) > 0, return true.
//
// All of these amount to the same thing in this implementation:
if (unwrappedStream->locked() &&
ReadableStreamGetNumReadRequests(unwrappedStream) > 0) {
return true;
}
// Step 6: Let desiredSize be
// ReadableStreamDefaultControllerGetDesiredSize(controller).
// Step 5 (or 7):
// Let desiredSize be
// ! ReadableStreamDefaultControllerGetDesiredSize(controller).
// (ReadableByteStreamControllerGetDesiredSize in 3.12.25.)
double desiredSize =
ReadableStreamControllerGetDesiredSizeUnchecked(unwrappedController);
// Step 7: If desiredSize > 0, return true.
// Step 8: Return false.
// Steps 7-8 of 3.12.24 are equivalent in our implementation.
// Step 6 (or 8): Assert: desiredSize is not null (implicit).
// Step 7 (or 9): If desiredSize > 0, return true.
// Step 8 (or 10): Return false.
return desiredSize > 0;
}
@ -2939,13 +2951,13 @@ static MOZ_MUST_USE bool ReadableStreamDefaultControllerClose(
// Step 1: Let stream be controller.[[controlledReadableStream]].
Rooted<ReadableStream*> unwrappedStream(cx, unwrappedController->stream());
// Step 2: Assert: controller.[[closeRequested]] is false.
// Step 2: Assert:
// ! ReadableStreamDefaultControllerCanCloseOrEnqueue(controller)
// is true.
MOZ_ASSERT(!unwrappedController->closeRequested());
// Step 3: Assert: stream.[[state]] is "readable".
MOZ_ASSERT(unwrappedStream->readable());
// Step 4: Set controller.[[closeRequested]] to true.
// Step 3: Set controller.[[closeRequested]] to true.
unwrappedController->setCloseRequested();
// Step 5: If controller.[[queue]] is empty, perform
@ -3008,10 +3020,10 @@ static MOZ_MUST_USE bool ReadableStreamDefaultControllerEnqueue(
success = EnqueueValueWithSize(cx, unwrappedController, chunk, chunkSize);
}
// Step b: If result is an abrupt completion,
// and
// Step e: If enqueueResult is an abrupt completion,
if (!success) {
// Step b: If result is an abrupt completion,
// and
// Step e: If enqueueResult is an abrupt completion,
RootedValue exn(cx);
if (!cx->isExceptionPending() || !GetAndClearException(cx, &exn)) {
// Uncatchable error. Die immediately without erroring the
@ -3035,9 +3047,8 @@ static MOZ_MUST_USE bool ReadableStreamDefaultControllerEnqueue(
}
}
// Step 6: Perform
// Step 5: Perform
// ! ReadableStreamDefaultControllerCallPullIfNeeded(controller).
// Step 7: Return.
return ReadableStreamControllerCallPullIfNeeded(cx, unwrappedController);
}
@ -3054,7 +3065,8 @@ static MOZ_MUST_USE bool ReadableStreamControllerError(
MOZ_ASSERT(!cx->isExceptionPending());
AssertSameCompartment(cx, e);
// Step 1: Let stream be controller.[[controlledReadableStream]].
// Step 1: Let stream be controller.[[controlledReadableStream]]
// (or controller.[[controlledReadableByteStream]]).
Rooted<ReadableStream*> unwrappedStream(cx, unwrappedController->stream());
// Step 2: If stream.[[state]] is not "readable", return.
@ -3214,13 +3226,11 @@ static MOZ_MUST_USE bool SetUpReadableStreamDefaultController(
if (!onStartFulfilled) {
return false;
}
RootedObject onStartRejected(
cx, NewHandler(cx, ControllerStartFailedHandler, controller));
if (!onStartRejected) {
return false;
}
if (!JS::AddPromiseReactions(cx, startPromise, onStartFulfilled,
onStartRejected)) {
return false;
@ -3278,7 +3288,6 @@ SetUpReadableStreamDefaultControllerFromUnderlyingSource(
// Step 6. Perform ? SetUpReadableStreamDefaultController(stream,
// controller, startAlgorithm, pullAlgorithm, cancelAlgorithm,
// highWaterMark, sizeAlgorithm).
return SetUpReadableStreamDefaultController(
cx, stream, sourceAlgorithms, underlyingSource, pullMethod, cancelMethod,
highWaterMark, sizeAlgorithm);
@ -3420,8 +3429,8 @@ bool ReadableByteStreamController::constructor(JSContext* cx, unsigned argc,
}
/**
* Version of the ReadableByteStreamConstructor that's specialized for
* handling external, embedding-provided, underlying sources.
* Version of SetUpReadableByteStreamController that's specialized for handling
* external, embedding-provided, underlying sources.
*/
static MOZ_MUST_USE bool SetUpExternalReadableByteStreamController(
JSContext* cx, Handle<ReadableStream*> stream,
@ -3562,7 +3571,7 @@ static MOZ_MUST_USE bool ReadableByteStreamControllerHandleQueueDrain(
*/
static MOZ_MUST_USE JSObject* ReadableByteStreamControllerPullSteps(
JSContext* cx, Handle<ReadableByteStreamController*> unwrappedController) {
// Step 1: Let stream be this.[[controlledReadableStream]].
// Step 1: Let stream be this.[[controlledReadableByteStream]].
Rooted<ReadableStream*> unwrappedStream(cx, unwrappedController->stream());
// Step 2: Assert: ! ReadableStreamHasDefaultReader(stream) is true.
@ -3700,7 +3709,8 @@ static MOZ_MUST_USE JSObject* ReadableByteStreamControllerPullSteps(
// Record {[[buffer]]: buffer.[[Value]],
// [[byteOffset]]: 0,
// [[byteLength]]: autoAllocateChunkSize,
// [[bytesFilled]]: 0, [[elementSize]]: 1,
// [[bytesFilled]]: 0,
// [[elementSize]]: 1,
// [[ctor]]: %Uint8Array%,
// [[readerType]]: `"default"`}.
RootedObject pullIntoDescriptor(
@ -3720,7 +3730,7 @@ static MOZ_MUST_USE JSObject* ReadableByteStreamControllerPullSteps(
}
// Step 6: Let promise be ! ReadableStreamAddReadRequest(stream,
// forAuthorCode).
// forAuthorCode).
RootedObject promise(
cx, ReadableStreamAddReadOrReadIntoRequest(cx, unwrappedStream));
if (!promise) {
@ -3795,7 +3805,7 @@ static MOZ_MUST_USE bool ReadableByteStreamControllerClearPendingPullIntos(
*/
static MOZ_MUST_USE bool ReadableByteStreamControllerClose(
JSContext* cx, Handle<ReadableByteStreamController*> unwrappedController) {
// Step 1: Let stream be controller.[[controlledReadableStream]].
// Step 1: Let stream be controller.[[controlledReadableByteStream]].
Rooted<ReadableStream*> unwrappedStream(cx, unwrappedController->stream());
// Step 2: Assert: controller.[[closeRequested]] is false.
@ -4094,19 +4104,17 @@ inline static MOZ_MUST_USE bool DequeueValue(
// container.[[queueTotalSize]] to 0.
// (This can occur due to rounding errors.)
double totalSize = unwrappedContainer->queueTotalSize();
totalSize -= unwrappedPair->size();
if (totalSize < 0) {
totalSize = 0;
}
unwrappedContainer->setQueueTotalSize(totalSize);
// Step 7: Return pair.[[value]].
RootedValue val(cx, unwrappedPair->value());
if (!cx->compartment()->wrap(cx, &val)) {
return false;
}
// Step 7: Return pair.[[value]].
chunk.set(val);
return true;
}
@ -4165,9 +4173,6 @@ static MOZ_MUST_USE bool EnqueueValueWithSize(
/**
* Streams spec, 6.2.4. ResetQueue ( container ) nothrow
*
* Note: can operate on unwrapped container instances from another
* compartment.
*/
inline static MOZ_MUST_USE bool ResetQueue(
JSContext* cx, Handle<ReadableStreamController*> unwrappedContainer) {
@ -4263,6 +4268,7 @@ static MOZ_MUST_USE bool CreateAlgorithmFromUnderlyingMethod(
/**
* Streams spec, 6.3.2. InvokeOrNoop ( O, P, args )
* As it happens, all callers pass exactly one argument.
*/
inline static MOZ_MUST_USE bool InvokeOrNoop(JSContext* cx, HandleValue O,
HandlePropertyName P,
@ -4682,12 +4688,16 @@ JS_PUBLIC_API bool JS::ReadableStreamUpdateDataAvailableFromSource(
unwrappedController->setQueueTotalSize(availableData - bytesWritten);
} else {
// Step b: Otherwise,
// Step i: Assert: ! IsReadableStreamLocked(stream) is false.
// Step 9: Otherwise, if ! ReadableStreamHasBYOBReader(stream) is true,
// [...]
// (Omitted. BYOB readers are not implemented.)
// Step 10: Otherwise,
// Step a: Assert: ! IsReadableStreamLocked(stream) is false.
MOZ_ASSERT(!unwrappedStream->locked());
// Step ii: Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(
// controller, transferredBuffer, byteOffset, byteLength).
// Step b: Perform ! ReadableByteStreamControllerEnqueueChunkToQueue(
// controller, transferredBuffer, byteOffset, byteLength).
// (Not needed for external underlying sources.)
}
@ -4715,7 +4725,6 @@ JS_PUBLIC_API bool JS::ReadableStreamTee(JSContext* cx, HandleObject streamObj,
branch1Obj.set(branch1Stream);
branch2Obj.set(branch2Stream);
return true;
}