• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ JS_IdToValue函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中JS_IdToValue函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_IdToValue函数的具体用法?C++ JS_IdToValue怎么用?C++ JS_IdToValue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了JS_IdToValue函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:methril,项目名称:elinks,代码行数:30,代码来源:globhist.c


示例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;
}
开发者ID:ASpade,项目名称:cocos2d-x,代码行数:34,代码来源:jsb_pluginx_basic_conversions.cpp


示例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;
}
开发者ID:TheWindShan,项目名称:HYFish,代码行数:58,代码来源:jsb_pluginx_basic_conversions.cpp


示例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);
}
开发者ID:sjokkis,项目名称:gjs,代码行数:57,代码来源:jsapi-util.c


示例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;
}
开发者ID:bluecherrydvr,项目名称:omv,代码行数:57,代码来源:jsj_JavaClass.c


示例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;
}
开发者ID:CogDis,项目名称:craftd,代码行数:10,代码来源:Dynamic.c


示例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;
}
开发者ID:OSGeo,项目名称:zoo-project,代码行数:62,代码来源:service_internal_js.c


示例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;
}
开发者ID:Rektosauros,项目名称:0ad,代码行数:55,代码来源:ScriptInterface.cpp


示例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;
}
开发者ID:chaos-ad,项目名称:emonk,代码行数:54,代码来源:to_erl.c


示例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();
    }
开发者ID:xrogaan,项目名称:mongo,代码行数:50,代码来源:engine_spidermonkey.cpp


示例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;
}
开发者ID:TheWindShan,项目名称:HYFish,代码行数:48,代码来源:jsb_pluginx_basic_conversions.cpp


示例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;
}
开发者ID:bluecherrydvr,项目名称:omv,代码行数:48,代码来源:jsj_JavaClass.c


示例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;
    }
}
开发者ID:GNOME,项目名称:gjs,代码行数:28,代码来源:jsapi-util-string.cpp


示例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);
}
开发者ID:mattzorzin,项目名称:synchronet,代码行数:46,代码来源:js_internal.c


示例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);
}
开发者ID:kindy,项目名称:synchronet-bbs-1,代码行数:46,代码来源:js_client.c


示例16: 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
 **/
JSBool
gjs_get_string_id (JSContext       *context,
                   jsid             id,
                   char           **name_p)
{
    jsval id_val;

    if (!JS_IdToValue(context, id, &id_val))
        return JS_FALSE;

    if (JSVAL_IS_STRING(id_val)) {
        return gjs_string_to_utf8(context, id_val, name_p);
    } else {
        *name_p = NULL;
        return JS_FALSE;
    }
}
开发者ID:victoryang,项目名称:gjs,代码行数:28,代码来源:jsapi-util-string.cpp


示例17: JS_IdToValue

nsresult
leakmonJSObjectInfo::AppendProperty(jsid aID, JSContext *aCx,
                                    leakmonObjectsInReportTable &aObjectsInReport)
{
	jsval n;
	JSBool ok = JS_IdToValue(aCx, aID, &n);
	NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);

	// n should be an integer, a string, or an XML QName,
	// AttributeName, or AnyName

	// XXX This can execute JS code!  How bad is that?
	// shaver didn't seem too scared when I described it to him.
	// XXX Could I avoid JS_ValueToString and still handle XML objects
	// correctly?
	JSString *nstr = JS_ValueToString(aCx, n);
	NS_ENSURE_TRUE(nstr, NS_ERROR_OUT_OF_MEMORY);

	size_t propname_len;
	const jschar *propname = JS_GetStringCharsAndLength(aCx, nstr, &propname_len);
	NS_ENSURE_TRUE(propname, NS_ERROR_OUT_OF_MEMORY);

	// XXX JS_GetUCProperty can execute JS code!  How bad is that?
	// shaver didn't seem too scared when I described it to him.
	// Since js_GetProperty starts with a call to js_LookupProperty,
	// it's clear that JS_LookupUCProperty does less than
	// JS_GetUCProperty, so prefer Lookup over Get (although it's not
	// clear to me exactly what the differences are).
	jsval v;
	ok = JS_LookupPropertyById(aCx, JSVAL_TO_OBJECT(mJSValue), aID, &v);
	NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);

	leakmonJSObjectInfo *info;
	void *key = reinterpret_cast<void*>(JSVAL_BITS(v));
	if (!aObjectsInReport.Get(key, &info)) {
		info = new leakmonJSObjectInfo(v);
		NS_ENSURE_TRUE(info, NS_ERROR_OUT_OF_MEMORY);
		aObjectsInReport.Put(key, info);
	}

	PropertyStruct *ps = mProperties.AppendElement();
	ps->mName.Assign(reinterpret_cast<const PRUnichar*>(propname), propname_len);
	ps->mValue = info;

	return NS_OK;
}
开发者ID:dbaron,项目名称:leak-monitor,代码行数:46,代码来源:leakmonJSObjectInfo.cpp


示例18: 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,
                   GjsAutoJSChar   *name_p)
{
    JS::RootedValue id_val(context);

    if (!JS_IdToValue(context, id, &id_val))
        return false;

    if (id_val.isString()) {
        JS::RootedString str(context, id_val.toString());
        name_p->reset(JS_EncodeStringToUTF8(context, str));
        return !!*name_p;
    } else {
        return false;
    }
}
开发者ID:leigh123linux,项目名称:cjs,代码行数:29,代码来源:jsapi-util-string.cpp


示例19: add_multiopt

static void
add_multiopt(JSContext *cx, js_setting_t *jss, JSObject *optlist,
	     const char *vdef)
{
  JSIdArray *opts, *opt;
  int i;

  if((opts = JS_Enumerate(cx, optlist)) == NULL)
    return;
  
  for(i = 0; i < opts->length; i++) {
    jsval name, value;
    if(!JS_IdToValue(cx, opts->vector[i], &name) ||
       !JSVAL_IS_INT(name) ||
       !JS_GetElement(cx, optlist, JSVAL_TO_INT(name), &value) ||
       !JSVAL_IS_OBJECT(value) ||
       (opt = JS_Enumerate(cx, JSVAL_TO_OBJECT(value))) == NULL)
      continue;

    if(opt->length >= 2) {
    
      jsval id, title, def;
      
      if(JS_GetElement(cx, JSVAL_TO_OBJECT(value), 0, &id) &&
	 JS_GetElement(cx, JSVAL_TO_OBJECT(value), 1, &title)) {
	
	if(opt->length < 3 ||
	   !JS_GetElement(cx, JSVAL_TO_OBJECT(value), 2, &def))
	  def = JSVAL_FALSE;
	const char *k = JS_GetStringBytes(JS_ValueToString(cx, id));
	if(vdef)
	  def = !strcmp(k, vdef) ? JSVAL_TRUE : JSVAL_FALSE;
	
	settings_multiopt_add_opt_cstr(jss->jss_s, k,
				       JS_GetStringBytes(JS_ValueToString(cx, title)),
				       def == JSVAL_TRUE);
	
      }
    }
    JS_DestroyIdArray(cx, opt);
  }
  JS_DestroyIdArray(cx, opts);
}
开发者ID:kshostak,项目名称:showtime,代码行数:43,代码来源:js_settings.c


示例20: js_server_get

static JSBool js_server_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
	jsval idval;
	char*		ip;
    jsint       tiny;
	struct in_addr in_addr;
	js_server_props_t*	p;

	if((p=(js_server_props_t*)JS_GetPrivate(cx,obj))==NULL)
		return(JS_FALSE);

    JS_IdToValue(cx, id, &idval);
    tiny = JSVAL_TO_INT(idval);

	switch(tiny) {
		case SERVER_PROP_VER:
			if(p->version!=NULL)
				*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx,p->version));
			break;
		case SERVER_PROP_VER_DETAIL:
			if(p->version_detail!=NULL)
				*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx,p->version_detail));
			break;
		case SERVER_PROP_INTERFACE:
			if(p->interface_addr!=NULL) {
				in_addr.s_addr=*(p->interface_addr);
				in_addr.s_addr=htonl(in_addr.s_addr);
				if((ip=inet_ntoa(in_addr))!=NULL)
					*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx,ip));
			}
			break;
		case SERVER_PROP_OPTIONS:
			if(p->options!=NULL)
				*vp=UINT_TO_JSVAL(*p->options);
			break;
		case SERVER_PROP_CLIENTS:
			if(p->clients!=NULL)
				*vp=UINT_TO_JSVAL(*p->clients);
			break;
	}

	return(JS_TRUE);
}
开发者ID:kindy,项目名称:synchronet-bbs-1,代码行数:43,代码来源:js_server.c



注:本文中的JS_IdToValue函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ JS_InitStandardClasses函数代码示例发布时间:2022-05-30
下一篇:
C++ JS_GetStringLength函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap