Quelle TransformStreamDefaultController.cpp
Sprache: unbekannt
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim:set ts=2 sw=2 sts=2 et cindent: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// https://streams.spec.whatwg.org/#rs-default-controller-has-backpressure // Looks like a readable stream thing but the spec explicitly says this is for // TransformStream. staticbool ReadableStreamDefaultControllerHasBackpressure(
ReadableStreamDefaultController* aController) { // Step 1: If ! ReadableStreamDefaultControllerShouldCallPull(controller) is // true, return false. // Step 2: Otherwise, return true. return !ReadableStreamDefaultControllerShouldCallPull(aController);
}
// Step 1: Let stream be controller.[[stream]].
RefPtr<TransformStream> stream = mStream;
// Step 2: Let readableController be stream.[[readable]].[[controller]].
RefPtr<ReadableStreamDefaultController> readableController =
stream->Readable()->Controller()->AsDefault();
// Step 3: If ! // ReadableStreamDefaultControllerCanCloseOrEnqueue(readableController) is // false, throw a TypeError exception. if (!ReadableStreamDefaultControllerCanCloseOrEnqueueAndThrow(
readableController, CloseOrEnqueue::Enqueue, aRv)) { return;
}
// Step 4: Let enqueueResult be // ReadableStreamDefaultControllerEnqueue(readableController, chunk).
ErrorResult rv;
ReadableStreamDefaultControllerEnqueue(aCx, readableController, aChunk, rv);
// Step 5: If enqueueResult is an abrupt completion, if (rv.MaybeSetPendingException(aCx)) {
JS::Rooted<JS::Value> error(aCx); if (!JS_GetPendingException(aCx, &error)) { // Uncatchable exception; we should mark aRv and return.
aRv.StealExceptionFromJSContext(aCx); return;
}
JS_ClearPendingException(aCx);
// Step 6: Let backpressure be ! // ReadableStreamDefaultControllerHasBackpressure(readableController). bool backpressure =
ReadableStreamDefaultControllerHasBackpressure(readableController);
// Step 7: If backpressure is not stream.[[backpressure]], if (backpressure != stream->Backpressure()) { // Step 7.1: Assert: backpressure is true.
MOZ_ASSERT(backpressure);
// Perform ! TransformStreamError(controller.[[stream]], e). // mStream is set in initialization step and only modified in cycle // collection. // TODO: Move mStream initialization to a method/constructor and make it // MOZ_KNOWN_LIVE again. (See bug 1769854)
TransformStreamError(aCx, MOZ_KnownLive(mStream), aError, aRv);
}
// Step 4: Let error be a TypeError exception indicating that the stream has // been terminated.
ErrorResult rv;
rv.ThrowTypeError("Terminating the stream");
JS::Rooted<JS::Value> error(aCx);
MOZ_ALWAYS_TRUE(ToJSValue(aCx, std::move(rv), &error));
// Step 3. Set controller.[[stream]] to stream.
aController.SetStream(aStream);
// Step 4. Set stream.[[controller]] to controller.
aStream.SetController(aController);
// Step 5. Set controller.[[transformAlgorithm]] to transformAlgorithm. // Step 6. Set controller.[[flushAlgorithm]] to flushAlgorithm.
aController.SetAlgorithms(&aTransformerAlgorithms);
}
// https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller-from-transformer void SetUpTransformStreamDefaultControllerFromTransformer(
JSContext* aCx, TransformStream& aStream,
JS::Handle<JSObject*> aTransformer, Transformer& aTransformerDict) { // Step 1. Let controller be a new TransformStreamDefaultController. auto controller =
MakeRefPtr<TransformStreamDefaultController>(aStream.GetParentObject());