bool MapIteratorObject::next(JSContext* cx, Handle<MapIteratorObject*> mapIterator, HandleArrayObject resultPairObj) { MOZ_ASSERT(resultPairObj->getDenseInitializedLength() == 2); ValueMap::Range* range = MapIteratorObjectRange(mapIterator); if (!range || range->empty()) { js_delete(range); mapIterator->setReservedSlot(RangeSlot, PrivateValue(nullptr)); return true; } switch (mapIterator->kind()) { case MapObject::Keys: resultPairObj->setDenseElementWithType(cx, 0, range->front().key.get()); break; case MapObject::Values: resultPairObj->setDenseElementWithType(cx, 1, range->front().value); break; case MapObject::Entries: { resultPairObj->setDenseElementWithType(cx, 0, range->front().key.get()); resultPairObj->setDenseElementWithType(cx, 1, range->front().value); break; } } range->popFront(); return false; }
bool MapIteratorObject::next(JSContext* cx, Handle<MapIteratorObject*> mapIterator, HandleArrayObject resultPairObj) { // Check invariants for inlined _GetNextMapEntryForIterator. // The array should be tenured, so that post-barrier can be done simply. MOZ_ASSERT(resultPairObj->isTenured()); // The array elements should be fixed. MOZ_ASSERT(resultPairObj->hasFixedElements()); MOZ_ASSERT(resultPairObj->getDenseInitializedLength() == 2); MOZ_ASSERT(resultPairObj->getDenseCapacity() >= 2); ValueMap::Range* range = MapIteratorObjectRange(mapIterator); if (!range || range->empty()) { js_delete(range); mapIterator->setReservedSlot(RangeSlot, PrivateValue(nullptr)); return true; } switch (mapIterator->kind()) { case MapObject::Keys: resultPairObj->setDenseElementWithType(cx, 0, range->front().key.get()); break; case MapObject::Values: resultPairObj->setDenseElementWithType(cx, 1, range->front().value); break; case MapObject::Entries: { resultPairObj->setDenseElementWithType(cx, 0, range->front().key.get()); resultPairObj->setDenseElementWithType(cx, 1, range->front().value); break; } } range->popFront(); return false; }
bool SetIteratorObject::next(Handle<SetIteratorObject*> setIterator, HandleArrayObject resultObj, JSContext* cx) { // Check invariants for inlined _GetNextSetEntryForIterator. // The array should be tenured, so that post-barrier can be done simply. MOZ_ASSERT(resultObj->isTenured()); // The array elements should be fixed. MOZ_ASSERT(resultObj->hasFixedElements()); MOZ_ASSERT(resultObj->getDenseInitializedLength() == 1); MOZ_ASSERT(resultObj->getDenseCapacity() >= 1); ValueSet::Range* range = SetIteratorObjectRange(setIterator); if (!range || range->empty()) { js_delete(range); setIterator->setReservedSlot(RangeSlot, PrivateValue(nullptr)); return true; } resultObj->setDenseElementWithType(cx, 0, range->front().get()); range->popFront(); return false; }