本文整理汇总了C++中AutoIdVector::length方法的典型用法代码示例。如果您正苦于以下问题:C++ AutoIdVector::length方法的具体用法?C++ AutoIdVector::length怎么用?C++ AutoIdVector::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoIdVector
的用法示例。
在下文中一共展示了AutoIdVector::length方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool
JSCompartment::wrap(JSContext *cx, AutoIdVector &props)
{
jsid *vector = props.begin();
int length = props.length();
for (size_t n = 0; n < size_t(length); ++n) {
if (!wrapId(cx, &vector[n]))
return false;
}
return true;
}
示例2: getOwnEnumerablePropertyKeys
bool BaseProxyHandler::getOwnEnumerablePropertyKeys(JSContext* cx,
HandleObject proxy,
AutoIdVector& props) const {
assertEnteredPolicy(cx, proxy, JSID_VOID, ENUMERATE);
MOZ_ASSERT(props.length() == 0);
if (!ownPropertyKeys(cx, proxy, props)) {
return false;
}
/* Select only the enumerable properties through in-place iteration. */
RootedId id(cx);
size_t i = 0;
for (size_t j = 0, len = props.length(); j < len; j++) {
MOZ_ASSERT(i <= j);
id = props[j];
if (JSID_IS_SYMBOL(id)) {
continue;
}
AutoWaivePolicy policy(cx, proxy, id, BaseProxyHandler::GET);
Rooted<PropertyDescriptor> desc(cx);
if (!getOwnPropertyDescriptor(cx, proxy, id, &desc)) {
return false;
}
desc.assertCompleteIfFound();
if (desc.object() && desc.enumerable()) {
props[i++].set(id);
}
}
MOZ_ASSERT(i <= props.length());
if (!props.resize(i)) {
return false;
}
return true;
}
示例3:
static bool
Filter(JSContext *cx, JSObject *wrapper, AutoIdVector &props)
{
size_t w = 0;
for (size_t n = 0; n < props.length(); ++n) {
jsid id = props[n];
Permission perm;
if (!Policy::check(cx, wrapper, id, Wrapper::GET, perm))
return false; // Error
if (perm != DenyAccess)
props[w++] = id;
}
props.resize(w);
return true;
}
示例4: id
static bool
Filter(JSContext* cx, HandleObject wrapper, AutoIdVector& props)
{
size_t w = 0;
RootedId id(cx);
for (size_t n = 0; n < props.length(); ++n) {
id = props[n];
if (Policy::check(cx, wrapper, id, Wrapper::GET) || Policy::check(cx, wrapper, id, Wrapper::SET))
props[w++].set(id);
else if (JS_IsExceptionPending(cx))
return false;
}
props.resize(w);
return true;
}
示例5: exports
bool
ModuleNamespaceObject::ProxyHandler::ownPropertyKeys(JSContext* cx, HandleObject proxy,
AutoIdVector& props) const
{
Rooted<ModuleNamespaceObject*> ns(cx, &proxy->as<ModuleNamespaceObject>());
RootedArrayObject exports(cx, &ns->exports());
uint32_t count = exports->length();
if (!props.reserve(props.length() + count))
return false;
for (uint32_t i = 0; i < count; i++) {
Value value = exports->getDenseElement(i);
props.infallibleAppend(AtomToId(&value.toString()->asAtom()));
}
return true;
}
示例6: sizeof
bool
js::VectorToIdArray(JSContext* cx, AutoIdVector& props, JSIdArray** idap)
{
JS_STATIC_ASSERT(sizeof(JSIdArray) > sizeof(jsid));
size_t len = props.length();
size_t idsz = len * sizeof(jsid);
size_t sz = (sizeof(JSIdArray) - sizeof(jsid)) + idsz;
JSIdArray* ida = reinterpret_cast<JSIdArray*>(cx->zone()->pod_malloc<uint8_t>(sz));
if (!ida)
return false;
ida->length = static_cast<int>(len);
jsid* v = props.begin();
for (int i = 0; i < ida->length; i++)
ida->vector[i].init(v[i]);
*idap = ida;
return true;
}
示例7: exports
bool
ModuleNamespaceObject::ProxyHandler::ownPropertyKeys(JSContext* cx, HandleObject proxy,
AutoIdVector& props) const
{
Rooted<ModuleNamespaceObject*> ns(cx, &proxy->as<ModuleNamespaceObject>());
RootedObject exports(cx, &ns->exports());
uint32_t count;
if (!GetLengthProperty(cx, exports, &count) || !props.reserve(props.length() + count))
return false;
Rooted<ValueVector> names(cx, ValueVector(cx));
if (!names.resize(count) || !GetElements(cx, exports, count, names.begin()))
return false;
for (uint32_t i = 0; i < count; i++)
props.infallibleAppend(AtomToId(&names[i].toString()->asAtom()));
return true;
}
示例8: begin
bool
NativeIterator::initProperties(JSContext* cx, Handle<PropertyIteratorObject*> obj,
const AutoIdVector& props)
{
// The obj parameter is just so that we can ensure that this object will get
// traced if we GC.
MOZ_ASSERT(this == obj->getNativeIterator());
size_t plength = props.length();
MOZ_ASSERT(plength == size_t(end() - begin()));
for (size_t i = 0; i < plength; i++) {
JSFlatString* str = IdToString(cx, props[i]);
if (!str)
return false;
props_array[i].init(str);
}
return true;
}
示例9: MarkAtoms
static bool MarkAtoms(JSContext* cx, const AutoIdVector& ids) {
for (size_t i = 0; i < ids.length(); i++) {
cx->markId(ids[i]);
}
return true;
}
示例10: array
// This function is shared between ownPropertyKeys, enumerate, and
// getOwnEnumerablePropertyKeys.
static bool
ArrayToIdVector(JSContext *cx, HandleObject proxy, HandleObject target, HandleValue v,
AutoIdVector &props, unsigned flags, JSAtom *trapName_)
{
MOZ_ASSERT(v.isObject());
RootedObject array(cx, &v.toObject());
RootedAtom trapName(cx, trapName_);
// steps g-h
uint32_t n;
if (!GetLengthProperty(cx, array, &n))
return false;
// steps i-k
for (uint32_t i = 0; i < n; ++i) {
// step i
RootedValue v(cx);
if (!GetElement(cx, array, array, i, &v))
return false;
// step ii
RootedId id(cx);
if (!ValueToId<CanGC>(cx, v, &id))
return false;
// step iii
for (uint32_t j = 0; j < i; ++j) {
if (props[j].get() == id) {
ReportInvalidTrapResult(cx, proxy, trapName);
return false;
}
}
// step iv
bool isFixed;
if (!HasOwnProperty(cx, target, id, &isFixed))
return false;
// step v
bool extensible;
if (!IsExtensible(cx, target, &extensible))
return false;
if (!extensible && !isFixed) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_CANT_REPORT_NEW);
return false;
}
// step vi
if (!props.append(id))
return false;
}
// step l
AutoIdVector ownProps(cx);
if (!GetPropertyKeys(cx, target, flags, &ownProps))
return false;
// step m
for (size_t i = 0; i < ownProps.length(); ++i) {
RootedId id(cx, ownProps[i]);
bool found = false;
for (size_t j = 0; j < props.length(); ++j) {
if (props[j].get() == id) {
found = true;
break;
}
}
if (found)
continue;
// step i
bool sealed;
if (!IsSealed(cx, target, id, &sealed))
return false;
if (sealed) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_CANT_SKIP_NC);
return false;
}
// step ii
bool isFixed;
if (!HasOwnProperty(cx, target, id, &isFixed))
return false;
// step iii
bool extensible;
if (!IsExtensible(cx, target, &extensible))
return false;
if (!extensible && isFixed) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_CANT_REPORT_E_AS_NE);
return false;
}
}
// step n
return true;
}