/* -*- 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/. */
// This type is a little tricky lifetime wise: Despite the fact that we're // talking about linked list of VaueWithSize, what is actually stored in the // list are dynamically allocated ValueWithSize*. As a result, these have to be // deleted. There are two ways this lifetime is managed: // // 1. In DequeueValue we pop the first element into a UniquePtr, so that it is // correctly cleaned up at destruction time. // 2. We use an AutoCleanLinkedList which will delete elements when destroyed // or `clear`ed. using QueueWithSizes = AutoCleanLinkedList<ValueWithSize>;
// https://streams.spec.whatwg.org/#enqueue-value-with-size template <class QueueContainingClass> inlinevoid EnqueueValueWithSize(QueueContainingClass aContainer,
JS::Handle<JS::Value> aValue, double aSize,
ErrorResult& aRv) { // Step 1. Assert: container has [[queue]] and [[queueTotalSize]] internal // slots. (Implicit by template instantiation.) // Step 2. If ! IsNonNegativeNumber(size) is false, throw a RangeError // exception. if (!IsNonNegativeNumber(aSize)) {
aRv.ThrowRangeError("invalid size"); return;
}
// Step 3. If size is +∞, throw a RangeError exception. if (std::isinf(aSize)) {
aRv.ThrowRangeError("Infinite queue size"); return;
}
// Step 4. Append a new value-with-size with value value and size size to // container.[[queue]]. // (See the comment on QueueWithSizes for the lifetime reasoning around this // allocation.)
ValueWithSize* valueWithSize = new ValueWithSize(aValue, aSize);
aContainer->Queue().insertBack(valueWithSize); // Step 5. Set container.[[queueTotalSize]] to container.[[queueTotalSize]] + // size.
aContainer->SetQueueTotalSize(aContainer->QueueTotalSize() + aSize);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.