Пример #1
0
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;
}
Пример #2
0
void
MapObject::mark(JSTracer* trc, JSObject* obj)
{
    if (ValueMap* map = obj->as<MapObject>().getData()) {
        for (ValueMap::Range r = map->all(); !r.empty(); r.popFront()) {
            MarkKey(r, r.front().key, trc);
            TraceEdge(trc, &r.front().value, "value");
        }
    }
}
Пример #3
0
bool
MapObject::getKeysAndValuesInterleaved(JSContext* cx, HandleObject obj,
                                       JS::MutableHandle<GCVector<JS::Value>> entries)
{
    ValueMap* map = obj->as<MapObject>().getData();
    if (!map)
        return false;

    for (ValueMap::Range r = map->all(); !r.empty(); r.popFront()) {
        if (!entries.append(r.front().key.get()) ||
            !entries.append(r.front().value))
        {
            return false;
        }
    }

    return true;
}
Пример #4
0
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;
}