本文整理汇总了C++中js::MutableHandleValue::isUndefined方法的典型用法代码示例。如果您正苦于以下问题:C++ MutableHandleValue::isUndefined方法的具体用法?C++ MutableHandleValue::isUndefined怎么用?C++ MutableHandleValue::isUndefined使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::MutableHandleValue
的用法示例。
在下文中一共展示了MutableHandleValue::isUndefined方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ToString
std::string ScriptInterface::ToString(JS::MutableHandleValue obj, bool pretty)
{
JSAutoRequest rq(m->m_cx);
if (obj.isUndefined())
return "(void 0)";
// Try to stringify as JSON if possible
// (TODO: this is maybe a bad idea since it'll drop 'undefined' values silently)
if (pretty)
{
Stringifier str;
JS::RootedValue indentVal(m->m_cx, JS::Int32Value(2));
// Temporary disable the error reporter, so we don't print complaints about cyclic values
JSErrorReporter er = JS_SetErrorReporter(m->m_cx, NULL);
bool ok = JS_Stringify(m->m_cx, obj, JS::NullPtr(), indentVal, &Stringifier::callback, &str);
// Restore error reporter
JS_SetErrorReporter(m->m_cx, er);
if (ok)
return str.stream.str();
// Clear the exception set when Stringify failed
JS_ClearPendingException(m->m_cx);
}
// Caller didn't want pretty output, or JSON conversion failed (e.g. due to cycles),
// so fall back to obj.toSource()
std::wstring source = L"(error)";
CallFunction(obj, "toSource", source);
return utf8_from_wstring(source);
}
示例2: getProperty
void DBInfo::getProperty(JSContext* cx,
JS::HandleObject obj,
JS::HandleId id,
JS::MutableHandleValue vp) {
// 2nd look into real values, may be cached collection object
if (!vp.isUndefined()) {
auto scope = getScope(cx);
auto opContext = scope->getOpContext();
if (opContext && vp.isObject()) {
ObjectWrapper o(cx, vp);
if (o.hasOwnField(InternedString::_fullName)) {
// need to check every time that the collection did not get sharded
if (haveLocalShardingInfo(opContext, o.getString(InternedString::_fullName)))
uasserted(ErrorCodes::BadValue, "can't use sharded collection from db.eval");
}
}
return;
}
JS::RootedObject parent(cx);
if (!JS_GetPrototype(cx, obj, &parent))
uasserted(ErrorCodes::JSInterpreterFailure, "Couldn't get prototype");
ObjectWrapper parentWrapper(cx, parent);
if (parentWrapper.hasOwnField(id)) {
parentWrapper.getValue(id, vp);
return;
}
IdWrapper idw(cx, id);
// if starts with '_' we dont return collection, one must use getCollection()
if (idw.isString()) {
JSStringWrapper jsstr;
auto sname = idw.toStringData(&jsstr);
if (sname.size() == 0 || sname[0] == '_') {
return;
}
}
// no hit, create new collection
JS::RootedValue getCollection(cx);
parentWrapper.getValue(InternedString::getCollection, &getCollection);
if (!(getCollection.isObject() && JS_ObjectIsFunction(cx, getCollection.toObjectOrNull()))) {
uasserted(ErrorCodes::BadValue, "getCollection is not a function");
}
JS::AutoValueArray<1> args(cx);
idw.toValue(args[0]);
JS::RootedValue coll(cx);
ObjectWrapper(cx, obj).callMethod(getCollection, args, &coll);
uassert(16861,
"getCollection returned something other than a collection",
getScope(cx)->getProto<DBCollectionInfo>().instanceOf(coll));
// cache collection for reuse, don't enumerate
ObjectWrapper(cx, obj).defineProperty(id, coll, 0);
vp.set(coll);
}