本文整理汇总了C++中js::HandleValue::toObjectOrNull方法的典型用法代码示例。如果您正苦于以下问题:C++ HandleValue::toObjectOrNull方法的具体用法?C++ HandleValue::toObjectOrNull怎么用?C++ HandleValue::toObjectOrNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js::HandleValue
的用法示例。
在下文中一共展示了HandleValue::toObjectOrNull方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setJSDelegate
void JSListenerBase::setJSDelegate(JSContext *cx, JS::HandleValue func) {
if (nullptr != proFunc) {
delete proFunc;
proFunc = nullptr;
}
proFunc = new JS::PersistentRootedObject(cx, func.toObjectOrNull());
}
示例2: jsval_to_physics3DRigidBodyDes
bool jsval_to_physics3DRigidBodyDes(JSContext* cx, JS::HandleValue v, Physics3DRigidBodyDes* des)
{
JS::RootedObject jsobj(cx, v.toObjectOrNull());
JS::RootedValue tmp(cx);
if(JS_GetProperty(cx, jsobj, "mass", &tmp))
{
des->mass = tmp.toNumber();
}
if(JS_GetProperty(cx, jsobj, "shape", &tmp))
{
JS::RootedObject tmpObj(cx, tmp.toObjectOrNull());
js_proxy_t* proxy = jsb_get_js_proxy(tmpObj);
des->shape = proxy ? (cocos2d::Physics3DShape*)proxy->ptr : nullptr;
}
if(JS_GetProperty(cx, jsobj, "localInertia", &tmp))
{
Vec3 v3;
jsval_to_vector3(cx, tmp, &v3);
des->localInertia = v3;
}
if(JS_GetProperty(cx, jsobj, "originalTransform", &tmp))
{
Mat4 m4;
jsval_to_matrix(cx, tmp, &m4);
des->originalTransform = m4;
}
if(JS_GetProperty(cx, jsobj, "disableSleep", &tmp))
{
des->disableSleep = tmp.toBoolean();
}
return true;
}
示例3: obj
bool
JavaScriptShared::toVariant(JSContext *cx, JS::HandleValue from, JSVariant *to)
{
switch (JS_TypeOfValue(cx, from)) {
case JSTYPE_VOID:
*to = UndefinedVariant();
return true;
case JSTYPE_OBJECT:
case JSTYPE_FUNCTION:
{
RootedObject obj(cx, from.toObjectOrNull());
if (!obj) {
MOZ_ASSERT(from == JSVAL_NULL);
*to = NullVariant();
return true;
}
if (xpc_JSObjectIsID(cx, obj)) {
JSIID iid;
const nsID *id = xpc_JSObjectToID(cx, obj);
ConvertID(*id, &iid);
*to = iid;
return true;
}
ObjectVariant objVar;
if (!toObjectVariant(cx, obj, &objVar))
return false;
*to = objVar;
return true;
}
case JSTYPE_STRING:
{
nsAutoJSString autoStr;
if (!autoStr.init(cx, from))
return false;
*to = autoStr;
return true;
}
case JSTYPE_NUMBER:
if (from.isInt32())
*to = double(from.toInt32());
else
*to = from.toDouble();
return true;
case JSTYPE_BOOLEAN:
*to = from.toBoolean();
return true;
default:
MOZ_ASSERT(false);
return false;
}
}
示例4: setJSCallback
void setJSCallback(JS::HandleValue jsFunc, JS::HandleObject jsTarget)
{
if (_callback != nullptr)
{
CC_SAFE_DELETE(_callback);
}
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
_callback = new (std::nothrow) JSFunctionWrapper(cx, jsTarget, jsFunc);
_jsFunc = jsFunc.toObjectOrNull();
}
示例5: jsval_to_TerrainData
bool jsval_to_TerrainData(JSContext* cx, JS::HandleValue v, Terrain::TerrainData* ret)
{
JS::RootedObject jsobj(cx, v.toObjectOrNull());
JS::RootedValue js_heightMap(cx);
JS::RootedValue js_alphaMap(cx);
JS::RootedValue js_chunkSize(cx);
JS::RootedValue js_mapHeight(cx);
JS::RootedValue js_mapScale(cx);
JS::RootedValue js_detailMap(cx);
std::string heightMap, alphaMap;
Size chunkSize;
double mapScale, mapHeight;
bool ok = true;
ok &= JS_GetProperty(cx, jsobj, "heightMap", &js_heightMap) &&
JS_GetProperty(cx, jsobj, "alphaMap", &js_alphaMap) &&
JS_GetProperty(cx, jsobj, "chunkSize", &js_chunkSize) &&
JS_GetProperty(cx, jsobj, "mapHeight", &js_mapHeight) &&
JS_GetProperty(cx, jsobj, "mapScale", &js_mapScale) &&
JS_GetProperty(cx, jsobj, "detailMap", &js_detailMap) &&
jsval_to_std_string(cx, js_heightMap, &heightMap) &&
jsval_to_std_string(cx, js_alphaMap, &alphaMap) &&
jsval_to_ccsize(cx, js_chunkSize, &chunkSize) &&
JS::ToNumber(cx, js_mapScale, &mapScale) &&
JS::ToNumber(cx, js_mapHeight, &mapHeight);
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
ret->_heightMapSrc = heightMap.c_str();
char* tmp = (char*)malloc(sizeof(char) * (alphaMap.size() + 1));
strcpy(tmp, alphaMap.c_str());
tmp[alphaMap.size()] = '\0';
ret->_alphaMapSrc = tmp;
ret->_chunkSize = chunkSize;
ret->_mapHeight = mapHeight;
ret->_mapScale = mapScale;
ret->_skirtHeightRatio = 1;
JS::RootedObject jsobj_detailMap(cx, js_detailMap.toObjectOrNull());
uint32_t length = 0;
JS_GetArrayLength(cx, jsobj_detailMap, &length);
for(uint32_t i = 0; i < length; ++i)
{
JS::RootedValue element(cx);
JS_GetElement(cx, jsobj_detailMap, i, &element);
Terrain::DetailMap dm;
jsval_to_DetailMap(cx, element, &dm);
ret->_detailMaps[i] = dm;
}
ret->_detailMapAmount = length;
return true;
}
示例6: jsobj
std::vector<Vec3> jsval_to_std_vector_vec3(JSContext* cx, JS::HandleValue v)
{
std::vector<Vec3> ret;
JS::RootedObject jsobj(cx, v.toObjectOrNull());
uint32_t length;
JS_GetArrayLength(cx, jsobj, &length);
ret.reserve(length);
for(size_t i = 0; i < length; ++i)
{
JS::RootedValue element(cx);
JS_GetElement(cx, jsobj, (uint32_t)i, &element);
Vec3 v3;
jsval_to_vector3(cx, element, &v3);
ret.push_back(v3);
}
return ret;
}
示例7: set
void JSAudioNodeThreaded::set(JS::HandleValue val)
{
if (!val.isObject()) return;
JS::RootedObject global(m_Cx, JSAudioContext::GetContext()->m_JsGlobalObj);
JS::RootedObject thisObj(m_Cx, this->getJSObject());
JS::RootedObject props(m_Cx, val.toObjectOrNull());
JS::Rooted<JS::IdVector> ida(m_Cx, JS::IdVector(m_Cx));
JS_Enumerate(m_Cx, props, &ida);
for (size_t i = 0; i < ida.length(); i++) {
// Retrieve the current key & value
JS::RootedId id(m_Cx, ida[i]);
JSAutoByteString key(m_Cx, JSID_TO_STRING(id));
JS::RootedValue val(m_Cx);
if (!JS_GetPropertyById(m_Cx, props, id, &val)) {
break;
}
// Set the property
JS::RootedObject hashObj(m_Cx, m_HashObj);
JS_SetProperty(m_Cx, hashObj, key.ptr(), val);
// Call the setter callback
JSTransferableFunction *fun
= m_Node->getFunction(JSAudioNodeCustomBase::SETTER_FN);
if (fun->isSet()) {
JS::RootedValue rval(m_Cx);
JS::RootedString jskey(m_Cx, JS_NewStringCopyZ(m_Cx, key.ptr()));
JS::AutoValueArray<3> params(m_Cx);
params[0].setString(jskey);
params[1].set(val);
params[2].setObjectOrNull(global);
fun->call(thisObj, params, &rval);
}
}
}
示例8: jsval_to_DetailMap
bool jsval_to_DetailMap(JSContext* cx, JS::HandleValue v, Terrain::DetailMap* ret)
{
JS::RootedObject jsobj(cx, v.toObjectOrNull());
JS::RootedValue js_file(cx);
JS::RootedValue js_size(cx);
std::string file;
double size;
bool ok = JS_GetProperty(cx, jsobj, "file", &js_file) &&
JS_GetProperty(cx, jsobj, "size", &js_size) &&
jsval_to_std_string(cx, js_file, &file) &&
JS::ToNumber(cx, js_size, &size);
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
ret->_detailMapSrc = file;
ret->_detailMapSize = size;
return true;
}
示例9: getOID
OID OIDInfo::getOID(JSContext* cx, JS::HandleValue value) {
JS::RootedObject obj(cx, value.toObjectOrNull());
return getOID(cx, obj);
}
示例10: obj
bool
JavaScriptShared::toVariant(JSContext *cx, JS::HandleValue from, JSVariant *to)
{
switch (JS_TypeOfValue(cx, from)) {
case JSTYPE_VOID:
*to = void_t();
return true;
case JSTYPE_NULL:
{
*to = uint64_t(0);
return true;
}
case JSTYPE_OBJECT:
case JSTYPE_FUNCTION:
{
RootedObject obj(cx, from.toObjectOrNull());
if (!obj) {
MOZ_ASSERT(from == JSVAL_NULL);
*to = uint64_t(0);
return true;
}
if (xpc_JSObjectIsID(cx, obj)) {
JSIID iid;
const nsID *id = xpc_JSObjectToID(cx, obj);
ConvertID(*id, &iid);
*to = iid;
return true;
}
ObjectId id;
if (!makeId(cx, obj, &id))
return false;
*to = uint64_t(id);
return true;
}
case JSTYPE_STRING:
{
nsDependentJSString dep;
if (!dep.init(cx, from))
return false;
*to = dep;
return true;
}
case JSTYPE_NUMBER:
if (JSVAL_IS_INT(from))
*to = double(from.toInt32());
else
*to = from.toDouble();
return true;
case JSTYPE_BOOLEAN:
*to = from.toBoolean();
return true;
default:
MOZ_ASSERT(false);
return false;
}
}
示例11: toStatus
Status MongoStatusInfo::toStatus(JSContext* cx, JS::HandleValue value) {
return *static_cast<Status*>(JS_GetPrivate(value.toObjectOrNull()));
}
示例12: ToNumberDecimal
Decimal128 NumberDecimalInfo::ToNumberDecimal(JSContext* cx, JS::HandleValue thisv) {
auto x = static_cast<Decimal128*>(JS_GetPrivate(thisv.toObjectOrNull()));
return x ? *x : Decimal128(0);
}
示例13: ToNumberInt
int NumberIntInfo::ToNumberInt(JSContext* cx, JS::HandleValue thisv) {
auto x = static_cast<int*>(JS_GetPrivate(thisv.toObjectOrNull()));
return x ? *x : 0;
}
示例14:
ObjectWrapper::ObjectWrapper(JSContext* cx, JS::HandleValue value)
: _context(cx), _object(cx, value.toObjectOrNull()) {}