本文整理汇总了C++中JS_IdToValue函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_IdToValue函数的具体用法?C++ JS_IdToValue怎么用?C++ JS_IdToValue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_IdToValue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: smjs_globhist_get_property
/* @smjs_globhist_class.getProperty */
static JSBool
smjs_globhist_get_property(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
{
JSObject *jsobj;
unsigned char *uri_string;
struct global_history_item *history_item;
jsval tmp;
if (!JS_IdToValue(ctx, id, &tmp))
goto ret_null;
uri_string = JS_EncodeString(ctx, JS_ValueToString(ctx, tmp));
if (!uri_string) goto ret_null;
history_item = get_global_history_item(uri_string);
if (!history_item) goto ret_null;
jsobj = smjs_get_globhist_item_object(history_item);
if (!jsobj) goto ret_null;
*vp = OBJECT_TO_JSVAL(jsobj);
return JS_TRUE;
ret_null:
*vp = JSVAL_NULL;
return JS_TRUE;
}
示例2: jsval_to_TProductInfo
JSBool jsval_to_TProductInfo(JSContext *cx, jsval v, TProductInfo* ret)
{
JSObject* tmp = JSVAL_TO_OBJECT(v);
if (!tmp) {
LOGD("jsval_to_TProductInfo: the jsval is not an object.");
return JS_FALSE;
}
JSObject* it = JS_NewPropertyIterator(cx, tmp);
while (true)
{
jsid idp;
jsval key;
if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key))
return JS_FALSE; // error
if (key == JSVAL_VOID)
break; // end of iteration
if (! JSVAL_IS_STRING(key))
continue; // ignore integer properties
jsval value;
JS_GetPropertyById(cx, tmp, idp, &value);
if (! JSVAL_IS_STRING(value))
continue; // ignore integer properties
JSStringWrapper strWrapper(JSVAL_TO_STRING(key), cx);
JSStringWrapper strWrapper2(JSVAL_TO_STRING(value), cx);
(*ret)[strWrapper.get()] = strWrapper2.get();
LOGD("iterate object: key = %s, value = %s", strWrapper.get().c_str(), strWrapper2.get().c_str());
}
return JS_TRUE;
}
示例3: jsval_to_FBInfo
bool jsval_to_FBInfo(JSContext *cx, jsval v, StringMap* ret)
{
JSObject* tmp = JSVAL_TO_OBJECT(v);
if (!tmp) {
LOGD("jsval_to_TProductInfo: the jsval is not an object.");
return false;
}
JSObject* it = JS_NewPropertyIterator(cx, tmp);
while (true)
{
jsid idp;
jsval key;
if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key))
return false; // error
if (key == JSVAL_VOID)
break; // end of iteration
if (! JSVAL_IS_STRING(key))
continue; // ignore integer properties
JS::RootedValue value(cx);
JS_GetPropertyById(cx, tmp, idp, &value);
// if (! JSVAL_IS_STRING(value))
// continue; // ignore integer properties
if(JSVAL_IS_STRING(value))
{
JSStringWrapper strWrapper(JSVAL_TO_STRING(key), cx);
JSStringWrapper strWrapper2(JSVAL_TO_STRING(value), cx);
ret->insert(std::map<std::string, std::string>::value_type(strWrapper.get(), strWrapper2.get()));
}
else if(JSVAL_IS_NUMBER(value))
{
double number = 0.0;
JS::ToNumber(cx, value, &number);
std::stringstream ss;
ss << number;
JSStringWrapper strWrapper(JSVAL_TO_STRING(key), cx);
//JSStringWrapper strWrapper2(JSVAL_TO_STRING(value), cx);
ret->insert(std::map<std::string, std::string>::value_type(strWrapper.get(), ss.str()));
}
else if(JSVAL_IS_BOOLEAN(value))
{
bool boolVal = JS::ToBoolean(value);
JSStringWrapper strWrapper(JSVAL_TO_STRING(key), cx);
//JSStringWrapper strWrapper2(JSVAL_TO_STRING(value), cx);
std::string boolstring = boolVal ? "true" : "false";
ret->insert(std::map<std::string, std::string>::value_type(strWrapper.get(), boolstring));
}
}
return true;
}
示例4: gjs_log_object_props
void
gjs_log_object_props(JSContext *context,
JSObject *obj,
GjsDebugTopic topic,
const char *prefix)
{
JSObject *props_iter;
jsid prop_id;
JS_BeginRequest(context);
/* We potentially create new strings, plus the property iterator,
* that could get collected as we go through this process. So
* create a local root scope.
*/
JS_EnterLocalRootScope(context);
props_iter = JS_NewPropertyIterator(context, obj);
if (props_iter == NULL) {
gjs_debug(GJS_DEBUG_ERROR,
"Failed to create property iterator for object props");
goto done;
}
prop_id = JSVAL_VOID;
if (!JS_NextProperty(context, props_iter, &prop_id))
goto done;
while (prop_id != JSVAL_VOID) {
jsval nameval;
const char *name;
jsval propval;
if (!JS_IdToValue(context, prop_id, &nameval))
goto next;
if (!gjs_get_string_id(nameval, &name))
goto next;
if (!gjs_object_get_property(context, obj, name, &propval))
goto next;
gjs_debug(topic,
"%s%s = '%s'",
prefix, name,
gjs_value_debug_string(context, propval));
next:
prop_id = JSVAL_VOID;
if (!JS_NextProperty(context, props_iter, &prop_id))
break;
}
done:
JS_LeaveLocalRootScope(context);
JS_EndRequest(context);
}
示例5: lookup_static_member_by_id
static JSBool
lookup_static_member_by_id(JSContext *cx, JNIEnv *jEnv, JSObject *obj,
JavaClassDescriptor **class_descriptorp,
jsid id, JavaMemberDescriptor **memberp)
{
jsval idval;
JavaMemberDescriptor *member_descriptor;
const char *member_name;
JavaClassDescriptor *class_descriptor;
class_descriptor = JS_GetPrivate(cx, obj);
if (!class_descriptor) {
*class_descriptorp = NULL;
*memberp = NULL;
return JS_TRUE;
}
if (class_descriptorp)
*class_descriptorp = class_descriptor;
member_descriptor = jsj_LookupJavaStaticMemberDescriptorById(cx, jEnv, class_descriptor, id);
if (!member_descriptor) {
JS_IdToValue(cx, id, &idval);
if (!JSVAL_IS_STRING(idval)) {
JS_ReportErrorNumber(cx, jsj_GetErrorMessage, NULL,
JSJMSG_BAD_JCLASS_EXPR);
return JS_FALSE;
}
member_name = JS_GetStringBytes(JSVAL_TO_STRING(idval));
/*
* See if the property looks like the explicit resolution of an
* overloaded method, e.g. "max(double,double)".
*/
member_descriptor =
jsj_ResolveExplicitMethod(cx, jEnv, class_descriptor, id, JS_TRUE);
if (member_descriptor)
goto done;
/* Why do we have to do this ? */
if (!strcmp(member_name, "prototype")) {
*memberp = NULL;
return JS_TRUE;
}
JS_ReportErrorNumber(cx, jsj_GetErrorMessage, NULL,
JSJMSG_MISSING_NAME,
class_descriptor->name, member_name);
return JS_FALSE;
}
done:
if (memberp)
*memberp = member_descriptor;
return JS_TRUE;
}
示例6: Dynamic_delete
JSBool
Dynamic_delete (JSContext* context, JSObject* owner, jsid id, jsval* value)
{
jsval name;
CDHash* self = (CDHash*) JS_GetPrivate(context, owner);
JS_IdToValue(context, id, &name);
return JS_TRUE;
}
示例7: mapFromJSObject
/**
* Convert a JavaScript Object to a map
*
* @param cx the JavaScript context
* @param t the JavaScript Object to convert
* @return a new map containing the JavaScript Object
*/
map* mapFromJSObject(JSContext *cx,jsval t){
map *res=NULL;
JSIdArray *idp=JS_Enumerate(cx,JSVAL_TO_OBJECT(t));
#ifdef JS_DEBUG
fprintf(stderr,"Properties %p\n",(void*)t);
#endif
if(idp!=NULL) {
int index;
jsdouble argNum;
#ifdef JS_DEBUG
fprintf(stderr,"Properties length : %d \n",idp->length);
#endif
for (index=0,argNum=idp->length;index<argNum;index++) {
jsval id = idp->vector[index];
jsval vp;
JS_IdToValue(cx,id,&vp);
char *tmp, *tmp1;
JSString *jsmsg,*jsmsg1;
size_t len,len1;
jsmsg = JS_ValueToString(cx,vp);
len = JS_GetStringLength(jsmsg);
jsval nvp;
tmp=JS_EncodeString(cx,jsmsg);
JS_GetProperty(cx, JSVAL_TO_OBJECT(t), tmp, &nvp);
jsmsg1 = JS_ValueToString(cx,nvp);
len1 = JS_GetStringLength(jsmsg1);
tmp1=JS_EncodeString(cx,jsmsg1);
#ifdef JS_DEBUG
fprintf(stderr,"Enumerate id : %d [ %s => %s ]\n",index,tmp,tmp1);
#endif
if(strcasecmp(tmp,"child")!=0){
if(res!=NULL){
#ifdef JS_DEBUG
fprintf(stderr,"%s - %s\n",tmp,tmp1);
#endif
addToMap(res,tmp,tmp1);
}
else{
res=createMap(tmp,tmp1);
res->next=NULL;
}
}
free(tmp);
free(tmp1);
#ifdef JS_DEBUG
dumpMap(res);
#endif
}
JS_DestroyIdArray(cx,idp);
}
#ifdef JS_DEBUG
dumpMap(res);
#endif
return res;
}
示例8: rq
bool ScriptInterface::EnumeratePropertyNamesWithPrefix(JS::HandleValue objVal, const char* prefix, std::vector<std::string>& out)
{
JSAutoRequest rq(m->m_cx);
if (!objVal.isObjectOrNull())
{
LOGERROR("EnumeratePropertyNamesWithPrefix expected object type!");
return false;
}
if(objVal.isNull())
return true; // reached the end of the prototype chain
JS::RootedObject obj(m->m_cx, &objVal.toObject());
JS::RootedObject it(m->m_cx, JS_NewPropertyIterator(m->m_cx, obj));
if (!it)
return false;
while (true)
{
JS::RootedId idp(m->m_cx);
JS::RootedValue val(m->m_cx);
if (! JS_NextProperty(m->m_cx, it, idp.address()) || ! JS_IdToValue(m->m_cx, idp, &val))
return false;
if (val.isUndefined())
break; // end of iteration
if (!val.isString())
continue; // ignore integer properties
JS::RootedString name(m->m_cx, val.toString());
size_t len = strlen(prefix)+1;
std::vector<char> buf(len);
size_t prefixLen = strlen(prefix) * sizeof(char);
JS_EncodeStringToBuffer(m->m_cx, name, &buf[0], prefixLen);
buf[len-1]= '\0';
if(0 == strcmp(&buf[0], prefix))
{
size_t len;
const jschar* chars = JS_GetStringCharsAndLength(m->m_cx, name, &len);
out.push_back(std::string(chars, chars+len));
}
}
// Recurse up the prototype chain
JS::RootedObject prototype(m->m_cx);
if (JS_GetPrototype(m->m_cx, obj, &prototype))
{
JS::RootedValue prototypeVal(m->m_cx, JS::ObjectOrNullValue(prototype));
if (! EnumeratePropertyNamesWithPrefix(prototypeVal, prefix, out))
return false;
}
return true;
}
示例9: to_erl_object
int
to_erl_object(ErlNifEnv* env, JSContext* cx, JSObject* obj, ERL_NIF_TERM* term)
{
ERL_NIF_TERM* array = NULL;
ERL_NIF_TERM list;
ERL_NIF_TERM keyterm;
ERL_NIF_TERM valterm;
JSObject* iter;
jsid idp;
jsval val;
int length;
int index;
int ret = ERROR;
iter = JS_NewPropertyIterator(cx, obj);
if(iter == NULL) goto done;
length = 0;
while(JS_NextProperty(cx, iter, &idp))
{
if(idp == JSID_VOID) break;
length += 1;
}
array = enif_alloc(length * sizeof(ERL_NIF_TERM));
if(array == NULL) goto done;
iter = JS_NewPropertyIterator(cx, obj);
if(iter == NULL) goto done;
index = 0;
while(JS_NextProperty(cx, iter, &idp))
{
if(idp == JSID_VOID)
{
list = enif_make_list_from_array(env, array, length);
*term = enif_make_tuple1(env, list);
ret = OK;
goto done;
}
if(!JS_IdToValue(cx, idp, &val)) goto done;
if(!to_erl_string(env, cx, val, &keyterm)) goto done;
if(!JS_GetPropertyById(cx, obj, idp, &val)) goto done;
if(!to_erl_intern(env, cx, val, &valterm)) goto done;
array[index] = enif_make_tuple2(env, keyterm, valterm);
index += 1;
}
done:
if(array != NULL) enif_free(array);
return ret;
}
示例10: toObject
BSONObj toObject( JSObject * o , int depth = 0) {
if ( ! o )
return BSONObj();
if ( JS_InstanceOf( _context , o , &bson_ro_class , 0 ) ) {
BSONHolder * holder = GETHOLDER( _context , o );
assert( holder );
return holder->_obj.getOwned();
}
BSONObj orig;
if ( JS_InstanceOf( _context , o , &bson_class , 0 ) ) {
BSONHolder * holder = GETHOLDER(_context,o);
assert( holder );
if ( ! holder->_modified ) {
return holder->_obj;
}
orig = holder->_obj;
}
BSONObjBuilder b;
if ( ! appendSpecialDBObject( this , b , "value" , OBJECT_TO_JSVAL( o ) , o ) ) {
if ( depth == 0 ) {
jsval theid = getProperty( o , "_id" );
if ( ! JSVAL_IS_VOID( theid ) ) {
append( b , "_id" , theid , EOO , depth + 1 );
}
}
JSIdArray * properties = JS_Enumerate( _context , o );
assert( properties );
for ( jsint i=0; i<properties->length; i++ ) {
jsid id = properties->vector[i];
jsval nameval;
assert( JS_IdToValue( _context ,id , &nameval ) );
string name = toString( nameval );
if ( depth == 0 && name == "_id" )
continue;
append( b , name , getProperty( o , name.c_str() ) , orig[name].type() , depth + 1 );
}
JS_DestroyIdArray( _context , properties );
}
return b.obj();
}
示例11: jsval_to_std_map_string_string
bool jsval_to_std_map_string_string(JSContext *cx, jsval v, std::map<std::string, std::string>* ret)
{
if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v))
{
return true;
}
JSObject* tmp = JSVAL_TO_OBJECT(v);
if (!tmp) {
CCLOG("%s", "jsval_to_ccvaluemap: the jsval is not an object.");
return false;
}
JSObject* it = JS_NewPropertyIterator(cx, tmp);
while (true)
{
jsid idp;
jsval key;
if (! JS_NextProperty(cx, it, &idp) || ! JS_IdToValue(cx, idp, &key)) {
return false; // error
}
if (key == JSVAL_VOID) {
break; // end of iteration
}
if (!JSVAL_IS_STRING(key)) {
continue; // ignore integer properties
}
JSStringWrapper keyWrapper(JSVAL_TO_STRING(key), cx);
JS::RootedValue value(cx);
JS_GetPropertyById(cx, tmp, idp, &value);
if (value.isString())
{
JSStringWrapper valueWapper(JSVAL_TO_STRING(value), cx);
ret->insert(std::make_pair(keyWrapper.get(), valueWapper.get()));
}
else
{
CCASSERT(false, "not a string");
}
}
return true;
}
示例12: JavaClass_setPropertyById
JavaClass_setPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
jclass java_class;
const char *member_name;
JavaClassDescriptor *class_descriptor;
JavaMemberDescriptor *member_descriptor;
jsval idval;
JNIEnv *jEnv;
JSJavaThreadState *jsj_env;
JSBool result;
/* printf("In JavaClass_setProperty\n"); */
/* Get the Java per-thread environment pointer for this JSContext */
jsj_env = jsj_EnterJava(cx, &jEnv);
if (!jEnv)
return JS_FALSE;
if (!lookup_static_member_by_id(cx, jEnv, obj, &class_descriptor, id, &member_descriptor)) {
jsj_ExitJava(jsj_env);
return JS_FALSE;
}
/* Check for the case where there is a method with the given name, but no field
with that name */
if (!member_descriptor->field)
goto no_such_field;
/* Silently fail if field value is final (immutable), as required by ECMA spec */
if (member_descriptor->field->modifiers & ACC_FINAL) {
jsj_ExitJava(jsj_env);
return JS_TRUE;
}
java_class = class_descriptor->java_class;
result = jsj_SetJavaFieldValue(cx, jEnv, member_descriptor->field, java_class, *vp);
jsj_ExitJava(jsj_env);
return result;
no_such_field:
JS_IdToValue(cx, id, &idval);
member_name = JS_GetStringBytes(JSVAL_TO_STRING(idval));
JS_ReportErrorNumber(cx, jsj_GetErrorMessage, NULL,
JSJMSG_MISSING_STATIC,
member_name, class_descriptor->name);
jsj_ExitJava(jsj_env);
return JS_FALSE;
}
示例13: gjs_get_string_id
/**
* gjs_get_string_id:
* @context: a #JSContext
* @id: a jsid that is an object hash key (could be an int or string)
* @name_p place to store ASCII string version of key
*
* If the id is not a string ID, return false and set *name_p to %NULL.
* Otherwise, return true and fill in *name_p with ASCII name of id.
*
* Returns: true if *name_p is non-%NULL
**/
bool
gjs_get_string_id (JSContext *context,
jsid id,
char **name_p)
{
JS::RootedValue id_val(context);
if (!JS_IdToValue(context, id, &id_val))
return false;
if (id_val.isString()) {
return gjs_string_to_utf8(context, id_val, name_p);
} else {
*name_p = NULL;
return false;
}
}
示例14: js_set
static JSBool js_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
jsval idval;
jsint tiny;
js_callback_t* cb;
if((cb=(js_callback_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
case PROP_TERMINATED:
if(cb->terminated!=NULL)
JS_ValueToBoolean(cx, *vp, (int *)cb->terminated);
break;
case PROP_AUTO_TERMINATE:
JS_ValueToBoolean(cx,*vp,&cb->auto_terminate);
break;
case PROP_COUNTER:
if(!JS_ValueToInt32(cx, *vp, (int32*)&cb->counter))
return JS_FALSE;
break;
case PROP_TIME_LIMIT:
if(!JS_ValueToInt32(cx, *vp, (int32*)&cb->limit))
return JS_FALSE;
break;
case PROP_GC_INTERVAL:
if(!JS_ValueToInt32(cx, *vp, (int32*)&cb->gc_interval))
return JS_FALSE;
break;
case PROP_YIELD_INTERVAL:
if(!JS_ValueToInt32(cx, *vp, (int32*)&cb->yield_interval))
return JS_FALSE;
break;
#ifdef jscntxt_h___
case PROP_MAXBYTES:
if(!JS_ValueToInt32(cx, *vp, (int32*)&cx->runtime->gcMaxBytes))
return JS_FALSE;
break;
#endif
}
return(JS_TRUE);
}
示例15: js_client_get
static JSBool js_client_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
jsval idval;
const char* p=NULL;
int32 val=0;
jsint tiny;
JSString* js_str;
client_t* client;
if((client=(client_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
case CLIENT_PROP_ADDR:
p=client->addr;
break;
case CLIENT_PROP_HOST:
p=client->host;
break;
case CLIENT_PROP_PORT:
val=client->port;
break;
case CLIENT_PROP_TIME:
val=(int32)client->time;
break;
case CLIENT_PROP_PROTOCOL:
p=(char*)client->protocol;
break;
case CLIENT_PROP_USER:
p=client->user;
break;
default:
return(JS_TRUE);
}
if(p!=NULL) {
if((js_str=JS_NewStringCopyZ(cx, p))==NULL)
return(JS_FALSE);
*vp = STRING_TO_JSVAL(js_str);
} else
*vp = INT_TO_JSVAL(val);
return(JS_TRUE);
}