static bool Reify(JSContext *cx, JSCompartment *origin, Value *vp) { Rooted<PropertyIteratorObject*> iterObj(cx, &vp->toObject().asPropertyIterator()); NativeIterator *ni = iterObj->getNativeIterator(); AutoCloseIterator close(cx, iterObj); /* Wrap the iteratee. */ RootedObject obj(cx, ni->obj); if (!origin->wrap(cx, obj.address())) return false; /* * Wrap the elements in the iterator's snapshot. * N.B. the order of closing/creating iterators is important due to the * implicit cx->enumerators state. */ size_t length = ni->numKeys(); bool isKeyIter = ni->isKeyIter(); AutoIdVector keys(cx); if (length > 0) { if (!keys.reserve(length)) return false; for (size_t i = 0; i < length; ++i) { jsid id; if (!ValueToId(cx, StringValue(ni->begin()[i]), &id)) return false; keys.infallibleAppend(id); if (!origin->wrapId(cx, &keys[i])) return false; } } close.clear(); if (!CloseIterator(cx, iterObj)) return false; RootedValue value(cx, *vp); if (isKeyIter) { if (!VectorToKeyIterator(cx, obj, ni->flags, keys, &value)) return false; } else { if (!VectorToValueIterator(cx, obj, ni->flags, keys, &value)) return false; } *vp = value; return true; }
static bool Reify(JSContext *cx, JSCompartment *origin, Value *vp) { JSObject *iterObj = &vp->toObject(); NativeIterator *ni = iterObj->getNativeIterator(); /* Wrap the iteratee. */ JSObject *obj = ni->obj; if (!origin->wrap(cx, &obj)) return false; /* * Wrap the elements in the iterator's snapshot. * N.B. the order of closing/creating iterators is important due to the * implicit cx->enumerators state. */ if (ni->isKeyIter()) { size_t length = ni->numKeys(); AutoIdVector keys(cx); if (length > 0) { if (!keys.resize(length)) return false; for (size_t i = 0; i < length; ++i) { keys[i] = ni->beginKey()[i]; if (!origin->wrapId(cx, &keys[i])) return false; } } return js_CloseIterator(cx, iterObj) && VectorToKeyIterator(cx, obj, ni->flags, keys, vp); } size_t length = ni->numValues(); AutoValueVector vals(cx); if (length > 0) { if (!vals.resize(length)) return false; for (size_t i = 0; i < length; ++i) { vals[i] = ni->beginValue()[i]; if (!origin->wrap(cx, &vals[i])) return false; } } return js_CloseIterator(cx, iterObj) && VectorToValueIterator(cx, obj, ni->flags, vals, vp); }
static bool Reify(JSContext *cx, JSCompartment *origin, Value *vp) { JSObject *iterObj = &vp->toObject(); NativeIterator *ni = iterObj->getNativeIterator(); AutoCloseIterator close(cx, iterObj); /* Wrap the iteratee. */ JSObject *obj = ni->obj; if (!origin->wrap(cx, &obj)) return false; /* * Wrap the elements in the iterator's snapshot. * N.B. the order of closing/creating iterators is important due to the * implicit cx->enumerators state. */ size_t length = ni->numKeys(); bool isKeyIter = ni->isKeyIter(); AutoIdVector keys(cx); if (length > 0) { if (!keys.resize(length)) return false; for (size_t i = 0; i < length; ++i) { jsid id; if (!ValueToId(cx, StringValue(ni->begin()[i]), &id)) return false; id = js_CheckForStringIndex(id); keys[i] = id; if (!origin->wrapId(cx, &keys[i])) return false; } } close.clear(); if (!js_CloseIterator(cx, iterObj)) return false; if (isKeyIter) return VectorToKeyIterator(cx, obj, ni->flags, keys, vp); return VectorToValueIterator(cx, obj, ni->flags, keys, vp); }