本文整理汇总了C++中ObjectWrapper函数的典型用法代码示例。如果您正苦于以下问题:C++ ObjectWrapper函数的具体用法?C++ ObjectWrapper怎么用?C++ ObjectWrapper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectWrapper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: obj
std::string ValueWriter::typeAsString() {
if (_value.isNull())
return "null";
if (_value.isUndefined())
return "undefined";
if (_value.isString())
return "string";
if (JS_IsArrayObject(_context, _value))
return "array";
if (_value.isBoolean())
return "boolean";
if (_value.isNumber())
return "number";
if (_value.isObject()) {
JS::RootedObject obj(_context, _value.toObjectOrNull());
if (JS_IsArrayObject(_context, obj))
return "array";
if (JS_ObjectIsDate(_context, obj))
return "date";
if (JS_ObjectIsFunction(_context, obj))
return "function";
return ObjectWrapper(_context, _value).getClassName();
}
uasserted(ErrorCodes::BadValue, "unable to get type");
}
示例2: getScope
void MozJSImplScope::_reportError(JSContext* cx, const char* message, JSErrorReport* report) {
auto scope = getScope(cx);
if (!JSREPORT_IS_WARNING(report->flags)) {
str::stream ss;
ss << message;
// TODO: something far more elaborate that mimics the stack printing from v8
JS::RootedValue excn(cx);
if (JS_GetPendingException(cx, &excn) && excn.isObject()) {
JS::RootedValue stack(cx);
ObjectWrapper(cx, excn).getValue("stack", &stack);
auto str = ValueWriter(cx, stack).toString();
if (str.empty()) {
ss << " @" << report->filename << ":" << report->lineno << ":" << report->column
<< "\n";
} else {
ss << " :\n" << str;
}
}
scope->_status = Status(
JSErrorReportToStatus(cx, report, ErrorCodes::JSInterpreterFailure, message).code(),
ss);
}
}
示例3: print2
void
SuifPrinterModule::print(ostream& output, const Address what,
const MetaClass* type, int _indent )
{
print2(output, ObjectWrapper(what, type), emptyLString, _indent, 0);
output <<endl;
}
示例4: BSONObj
BSONObj ValueWriter::toBSON() {
if (!_value.isObject())
return BSONObj();
JS::RootedObject obj(_context, _value.toObjectOrNull());
return ObjectWrapper(_context, obj).toBSON();
}
示例5: protoWrapper
void MaxKeyInfo::postInstall(JSContext* cx, JS::HandleObject global, JS::HandleObject proto) {
ObjectWrapper protoWrapper(cx, proto);
JS::RootedValue value(cx);
getScope(cx)->getProto<MaxKeyInfo>().newObject(&value);
ObjectWrapper(cx, global).setValue(InternedString::MaxKey, value);
protoWrapper.setValue(InternedString::singleton, value);
}
示例6: entry
void MozJSImplScope::setFunction(const char* field, const char* code) {
MozJSEntry entry(this);
JS::RootedValue fun(_context);
_MozJSCreateFunction(code, getFunctionCache().size() + 1, &fun);
ObjectWrapper(_context, _global).setValue(field, fun);
}
示例7: suif_assert
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void SuifPrinterModule::print(ostream& output, const SuifObject*rootNode)
{
suif_assert(rootNode != NULL);
//const MetaClass *type = rootNode->get_meta_class();
int _indent = 2;
print2(output, ObjectWrapper(rootNode), emptyLString, _indent);
output <<endl;
}
示例8: JS_GetClass
std::string ObjectWrapper::getClassName() {
auto jsclass = JS_GetClass(_object);
if (jsclass)
return jsclass->name;
JS::RootedValue ctor(_context);
getValue(InternedString::constructor, &ctor);
return ObjectWrapper(_context, ctor).getString(InternedString::name);
}
示例9: getScope
void JSThreadInfo::Functions::init::call(JSContext* cx, JS::CallArgs args) {
auto scope = getScope(cx);
JS::RootedObject obj(cx);
scope->getProto<JSThreadInfo>().newObject(&obj);
JSThreadConfig* config = new JSThreadConfig(cx, args);
JS_SetPrivate(obj, config);
ObjectWrapper(cx, args.thisv()).setObject("_JSThreadConfig", obj);
args.rval().setUndefined();
}
示例10: getHolder
void NativeFunctionInfo::call(JSContext* cx, JS::CallArgs args) {
auto holder = getHolder(args);
if (!holder) {
// Calling the prototype
args.rval().setUndefined();
return;
}
JS::RootedObject robj(cx, JS_NewArrayObject(cx, args));
if (!robj) {
uasserted(ErrorCodes::JSInterpreterFailure, "Failed to JS_NewArrayObject");
}
BSONObj out = holder->_func(ObjectWrapper(cx, robj).toBSON(), holder->_ctx);
ValueReader(cx, args.rval()).fromBSONElement(out.firstElement(), out, false);
}
示例11: ObjectWrapper
void MozJSImplScope::installBSONTypes() {
_binDataProto.install(_global);
_bsonProto.install(_global);
_dbPointerProto.install(_global);
_dbRefProto.install(_global);
_maxKeyProto.install(_global);
_minKeyProto.install(_global);
_nativeFunctionProto.install(_global);
_numberIntProto.install(_global);
_numberLongProto.install(_global);
_objectProto.install(_global);
_oidProto.install(_global);
_regExpProto.install(_global);
_timestampProto.install(_global);
// This builtin map is a javascript 6 thing. We want our version. so
// take theirs out
ObjectWrapper(_context, _global).deleteProperty("Map");
}
示例12: getHolder
void BSONInfo::setProperty(
JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool strict, JS::MutableHandleValue vp) {
auto holder = getHolder(obj);
if (holder) {
if (holder->_readOnly) {
uasserted(ErrorCodes::BadValue, "Read only object");
}
auto iter = holder->_removed.find(IdWrapper(cx, id).toString());
if (iter != holder->_removed.end()) {
holder->_removed.erase(iter);
}
holder->_altered = true;
}
ObjectWrapper(cx, obj).defineProperty(id, vp, JSPROP_ENUMERATE);
}
示例13: wid
void DBQueryInfo::resolve(JSContext* cx, JS::HandleObject obj, JS::HandleId id, bool* resolvedp) {
*resolvedp = false;
IdWrapper wid(cx, id);
// We only use this for index access
if (!wid.isInt()) {
return;
}
JS::RootedObject parent(cx);
if (!JS_GetPrototype(cx, obj, &parent))
uasserted(ErrorCodes::InternalError, "Couldn't get prototype");
ObjectWrapper parentWrapper(cx, parent);
JS::RootedValue arrayAccess(cx);
parentWrapper.getValue(InternedString::arrayAccess, &arrayAccess);
if (arrayAccess.isObject() && JS_ObjectIsFunction(cx, arrayAccess.toObjectOrNull())) {
JS::AutoValueArray<1> args(cx);
args[0].setInt32(wid.toInt32());
JS::RootedValue vp(cx);
ObjectWrapper(cx, obj).callMethod(arrayAccess, args, &vp);
if (!vp.isNullOrUndefined()) {
ObjectWrapper o(cx, obj);
// Assumes the user won't modify the contents of what DBQuery::arrayAccess returns
// otherwise we need to install a getter.
o.defineProperty(id, vp, 0);
}
*resolvedp = true;
}
}
示例14: excn
bool MozJSImplScope::_checkErrorState(bool success, bool reportError, bool assertOnError) {
if (success)
return false;
if (_quickExit)
return false;
if (_status.isOK()) {
JS::RootedValue excn(_context);
if (JS_GetPendingException(_context, &excn) && excn.isObject()) {
str::stream ss;
JS::RootedValue stack(_context);
ObjectWrapper(_context, excn).getValue("stack", &stack);
ss << ValueWriter(_context, excn).toString() << " :\n"
<< ValueWriter(_context, stack).toString();
_status = Status(ErrorCodes::JSInterpreterFailure, ss);
} else {
_status = Status(ErrorCodes::UnknownError, "Unknown Failure from JSInterpreter");
}
}
_error = _status.reason();
if (reportError)
error() << _error << std::endl;
// Clear the status state
auto status = std::move(_status);
if (assertOnError) {
// Throw if necessary
uassertStatusOK(status);
}
return true;
}
示例15: getScope
void MozJSImplScope::_reportError(JSContext* cx, const char* message, JSErrorReport* report) {
auto scope = getScope(cx);
if (!JSREPORT_IS_WARNING(report->flags)) {
str::stream ss;
ss << message;
// TODO: something far more elaborate that mimics the stack printing from v8
JS::RootedValue excn(cx);
if (JS_GetPendingException(cx, &excn) && excn.isObject()) {
JS::RootedValue stack(cx);
ObjectWrapper(cx, excn).getValue("stack", &stack);
ss << " :\n" << ValueWriter(cx, stack).toString();
}
scope->_status =
Status(report->errorNumber ? static_cast<ErrorCodes::Error>(report->errorNumber)
: ErrorCodes::JSInterpreterFailure,
ss);
}
}