本文整理汇总了C++中NativeIterator::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ NativeIterator::begin方法的具体用法?C++ NativeIterator::begin怎么用?C++ NativeIterator::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NativeIterator
的用法示例。
在下文中一共展示了NativeIterator::begin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: close
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;
}
示例2: close
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);
}
示例3: obj
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;
}
示例4: close
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);
}