static JSObject* Reify(JSContext* cx, JS::Compartment* origin, HandleObject iter) { // Ensure iterator gets closed. auto autoCloseIterator = mozilla::MakeScopeExit([=] { CloseIterator(iter); }); NativeIterator* ni = iter->as<PropertyIteratorObject>().getNativeIterator(); RootedObject obj(cx, ni->objectBeingIterated()); // Wrap iteratee. if (!origin->wrap(cx, &obj)) { return nullptr; } // Wrap the elements in the iterator's snapshot. size_t length = ni->numKeys(); AutoIdVector keys(cx); if (length > 0) { if (!keys.reserve(length)) { return nullptr; } RootedId id(cx); RootedValue v(cx); for (size_t i = 0; i < length; ++i) { v.setString(ni->propertiesBegin()[i]); if (!ValueToId<CanGC>(cx, v, &id)) { return nullptr; } cx->markId(id); keys.infallibleAppend(id); } } // Return iterator in current compartment. return EnumeratedIdVectorToIterator(cx, obj, keys); }
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); }
static JSObject* Reify(JSContext* cx, JSCompartment* origin, HandleObject objp) { Rooted<PropertyIteratorObject*> iterObj(cx, &objp->as<PropertyIteratorObject>()); NativeIterator* ni = iterObj->getNativeIterator(); RootedObject obj(cx, ni->obj); { AutoCloseIterator close(cx, iterObj); /* Wrap the iteratee. */ if (!origin->wrap(cx, &obj)) return nullptr; /* * 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(); AutoIdVector keys(cx); if (length > 0) { if (!keys.reserve(length)) return nullptr; RootedId id(cx); RootedValue v(cx); for (size_t i = 0; i < length; ++i) { v.setString(ni->begin()[i]); if (!ValueToId<CanGC>(cx, v, &id)) return nullptr; cx->markId(id); keys.infallibleAppend(id); } } close.clear(); CloseIterator(iterObj); obj = EnumeratedIdVectorToIterator(cx, obj, keys); } return obj; }
static bool Reify(JSContext* cx, JSCompartment* origin, MutableHandleObject objp) { Rooted<PropertyIteratorObject*> iterObj(cx, &objp->as<PropertyIteratorObject>()); NativeIterator* ni = iterObj->getNativeIterator(); AutoCloseIterator close(cx, iterObj); /* Wrap the iteratee. */ RootedObject obj(cx, 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(); AutoIdVector keys(cx); if (length > 0) { if (!keys.reserve(length)) return false; for (size_t i = 0; i < length; ++i) { RootedId id(cx); RootedValue v(cx, StringValue(ni->begin()[i])); if (!ValueToId<CanGC>(cx, v, &id)) return false; keys.infallibleAppend(id); } } close.clear(); MOZ_ALWAYS_TRUE(CloseIterator(cx, iterObj)); return EnumeratedIdVectorToIterator(cx, obj, ni->flags, keys, objp); }