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