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

C++ JSVAL_TO_BOOLEAN函数代码示例

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

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



在下文中一共展示了JSVAL_TO_BOOLEAN函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: js_ValueToBoolean

JSBool
js_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp)
{
    JSBool b;
    jsdouble d;

#if defined XP_PC && defined _MSC_VER && _MSC_VER <= 800
    /* MSVC1.5 coredumps */
    if (!bp)
	return JS_TRUE;
    /* This should be an if-else chain, but MSVC1.5 crashes if it is. */
#define ELSE
#else
#define ELSE else
#endif

    if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
	/* Must return early to avoid falling thru to JSVAL_IS_OBJECT case. */
	*bp = JS_FALSE;
	return JS_TRUE;
    }
    if (JSVAL_IS_OBJECT(v)) {
	if (!JSVERSION_IS_ECMA(cx->version)) {
	    if (!OBJ_DEFAULT_VALUE(cx, JSVAL_TO_OBJECT(v), JSTYPE_BOOLEAN, &v))
		return JS_FALSE;
	    if (!JSVAL_IS_BOOLEAN(v))
		v = JSVAL_TRUE;		/* non-null object is true */
	    b = JSVAL_TO_BOOLEAN(v);
	} else {
	    b = JS_TRUE;
	}
    } ELSE
    if (JSVAL_IS_STRING(v)) {
	b = JSSTRING_LENGTH(JSVAL_TO_STRING(v)) ? JS_TRUE : JS_FALSE;
    } ELSE
    if (JSVAL_IS_INT(v)) {
	b = JSVAL_TO_INT(v) ? JS_TRUE : JS_FALSE;
    } ELSE
    if (JSVAL_IS_DOUBLE(v)) {
	d = *JSVAL_TO_DOUBLE(v);
	b = (!JSDOUBLE_IS_NaN(d) && d != 0) ? JS_TRUE : JS_FALSE;
    } ELSE
#if defined XP_PC && defined _MSC_VER && _MSC_VER <= 800
    if (JSVAL_IS_BOOLEAN(v)) {
	b = JSVAL_TO_BOOLEAN(v);
    }
#else
    {
        JS_ASSERT(JSVAL_IS_BOOLEAN(v));
	b = JSVAL_TO_BOOLEAN(v);
    }
#endif

#undef ELSE
    *bp = b;
    return JS_TRUE;
}
开发者ID:DmitrySigaev,项目名称:DSMedia,代码行数:57,代码来源:jsbool.c


示例2: js_sprintf

char* DLLCALL
js_sprintf(JSContext *cx, uint argn, uintN argc, jsval *argv)
{
	char*		p;
    JSString*	str;

	if((p=js_ValueToStringBytes(cx, argv[argn++], NULL))==NULL)
		return(NULL);

	p=xp_asprintf_start(p);
    for(; argn<argc; argn++) {
		if(JSVAL_IS_DOUBLE(argv[argn]))
			p=xp_asprintf_next(p,XP_PRINTF_CONVERT|XP_PRINTF_TYPE_DOUBLE,*JSVAL_TO_DOUBLE(argv[argn]));
		else if(JSVAL_IS_INT(argv[argn]))
			p=xp_asprintf_next(p,XP_PRINTF_CONVERT|XP_PRINTF_TYPE_INT,JSVAL_TO_INT(argv[argn]));
		else if(JSVAL_IS_BOOLEAN(argv[argn]) && xp_printf_get_type(p)!=XP_PRINTF_TYPE_CHARP)
			p=xp_asprintf_next(p,XP_PRINTF_CONVERT|XP_PRINTF_TYPE_INT,JSVAL_TO_BOOLEAN(argv[argn]));
		else {
			if((str=JS_ValueToString(cx, argv[argn]))==NULL)
			    return(NULL);
			p=xp_asprintf_next(p,XP_PRINTF_CONVERT|XP_PRINTF_TYPE_CHARP,JS_GetStringBytes(str));
		}
	}

	return xp_asprintf_end(p, NULL);

}
开发者ID:ftnapps,项目名称:pkg-sbbs,代码行数:27,代码来源:js_sprintf.c


示例3: js_json_emit_jsval

static void
js_json_emit_jsval(JSContext *cx, jsval value, htsbuf_queue_t *out)
{
  char buf[100];
  if(JSVAL_IS_BOOLEAN(value)) {
    if(JSVAL_TO_BOOLEAN(value))
      htsbuf_append(out, "true", 4);
    else
      htsbuf_append(out, "false", 5);
  } else if(JSVAL_IS_INT(value)) {
    snprintf(buf, sizeof(buf), "%d", JSVAL_TO_INT(value));
    htsbuf_append(out, buf, strlen(buf));
  } else if(JSVAL_IS_DOUBLE(value)) {
    double dbl;
    if(JS_ValueToNumber(cx, value, &dbl) &&
       !my_double2str(buf, sizeof(buf), dbl))
      htsbuf_append(out, buf, strlen(buf));
    else
      htsbuf_append(out, "null", 4);
  } else if(JSVAL_IS_NULL(value)) {
    htsbuf_append(out, "null", 4);
  } else if(JSVAL_IS_STRING(value)) {
    js_json_emit_str(cx, value, out);
  } else if(JSVAL_IS_OBJECT(value)) {
    JSObject *obj = JSVAL_TO_OBJECT(value);
    JSClass *c = JS_GetClass(cx, obj);

    if(!strcmp(c->name, "XML"))   // Treat some classes special
      js_json_emit_str(cx, value, out);
    else {
      if(json_encode_from_object(cx, obj, out))
	htsbuf_append(out, "null", 4);
    }
  }
}
开发者ID:Rautz,项目名称:showtime,代码行数:35,代码来源:js_json.c


示例4: dummy_constructor

static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) {
    JS::RootedValue initializing(cx);
    bool isNewValid = true;
#if not $script_control_cpp
    JSObject* global = ScriptingCore::getInstance()->getGlobalObject();
	isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && JSVAL_TO_BOOLEAN(initializing);
#end if
	if (isNewValid)
	{
		TypeTest<T> t;
		js_type_class_t *typeClass = nullptr;
		std::string typeName = t.s_name();
		auto typeMapIter = _js_global_type_map.find(typeName);
		CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!");
		typeClass = typeMapIter->second;
		CCASSERT(typeClass, "The value is null.");

		JSObject *_tmp = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto);
	#if $script_control_cpp
		T* cobj = new T();
		js_proxy_t *pp = jsb_new_proxy(cobj, _tmp);
		JS_AddObjectRoot(cx, &pp->obj);
	#end if
		JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp));
		return true;
	}

#if not $script_control_cpp
    JS_ReportError(cx, "Don't use `new cc.XXX`, please use `cc.XXX.create` instead! ");
#end if
    return false;
}
开发者ID:289997171,项目名称:cocos2d-x,代码行数:32,代码来源:layout_head.c


示例5: js2py_with_parent

PyObject*
js2py_with_parent(Context* cx, jsval val, jsval parent)
{
    JSType vtype = JS_TypeOfValue(cx->cx, val);
    PyObject* unwrapped;

    /*
        There's not JSType for null. Or rather, its
        reported as Object which causes segfaults.
    */
    if(JSVAL_IS_NULL(val) || JSVAL_IS_VOID(val))
    {
        Py_RETURN_NONE;
    }
    else if(vtype == JSTYPE_BOOLEAN)
    {
        if(JSVAL_TO_BOOLEAN(val))
        {
            Py_RETURN_TRUE;
        }
        else
        {
            Py_RETURN_FALSE;
        }
    }
    else if(vtype == JSTYPE_STRING)
    {
        return js2py_string(cx, val);
    }
    else if(vtype == JSTYPE_NUMBER)
    {
        if(JSVAL_IS_INT(val)) return js2py_integer(cx, val);
        else return js2py_double(cx, val);
    }

    /* Now try to unwrap any incoming object in so we don't rewrap our own objects being passed around. */

    unwrapped = unwrap_pyobject(val);

    if (unwrapped != NULL)
	return unwrapped;

    if(vtype == JSTYPE_FUNCTION)
    {
        return js2py_function(cx, val, parent);
    }
    else if(vtype == JSTYPE_OBJECT)
    {
        JSObject* obj = JSVAL_TO_OBJECT(val);
        if(JS_IsArrayObject(cx->cx, obj))
        {
            return js2py_array(cx, val);
        }
        
        return js2py_object(cx, val);
    }
    
    PyErr_SetString(PyExc_RuntimeError, "Unknown JSVAL type.");
    return NULL;
}
开发者ID:smurfix,项目名称:python-spidermonkey,代码行数:60,代码来源:convert.cpp


示例6: jsdtrace_jsvaltovoid

/*
 * This function is used to convert function arguments and return value (jsval)
 * into the following based on each value's type tag:
 *
 *      jsval      returned
 *      -------------------
 *      STRING  -> char *
 *      INT     -> int
 *      DOUBLE  -> double *
 *      BOOLEAN -> int
 *      OBJECT  -> void *
 *
 * All are presented as void * for DTrace consumers to use, after shifting or
 * masking out the JavaScript type bits. This allows D scripts to use ints and
 * booleans directly and copyinstr() for string arguments, when types are known
 * beforehand.
 *
 * This is used by the function-args and function-rval probes, which also
 * provide raw (unmasked) jsvals should type info be useful from D scripts.
 */
void *
jsdtrace_jsvaltovoid(JSContext *cx, jsval argval)
{
    JSType type = TYPEOF(cx, argval);

    switch (type) {
      case JSTYPE_NULL:
      case JSTYPE_VOID:
        return JS_TYPE_STR(type);

      case JSTYPE_BOOLEAN:
        return (void *)JSVAL_TO_BOOLEAN(argval);

      case JSTYPE_STRING:
        return (void *)js_GetStringBytes(cx, JSVAL_TO_STRING(argval));

      case JSTYPE_NUMBER:
        if (JSVAL_IS_INT(argval))
            return (void *)JSVAL_TO_INT(argval);
        return JSVAL_TO_DOUBLE(argval);

      default:
        return JSVAL_TO_GCTHING(argval);
    }
    /* NOTREACHED */
}
开发者ID:edrikL,项目名称:gears,代码行数:46,代码来源:jsdtracef.c


示例7: PyUnicode_FromString

static PyObject *to_python_object(JSContext *context, jsval value) {
    if (JSVAL_IS_PRIMITIVE(value)) {
        if (JSVAL_IS_STRING(value)) {
            return PyUnicode_FromString(JS_EncodeString(context, JSVAL_TO_STRING(value)));
        } else if (JSVAL_IS_BOOLEAN(value)) {
            return PyBool_FromLong(JSVAL_TO_BOOLEAN(value));
        } else if (JSVAL_IS_INT(value)) {
            return PyLong_FromLong(JSVAL_TO_INT(value));
        } else if (JSVAL_IS_DOUBLE(value)) {
            return PyFloat_FromDouble(JSVAL_TO_DOUBLE(value));
        } else {
            Py_INCREF(Py_None);
            return Py_None;
        }
    } else {
        JSObject *obj = JSVAL_TO_OBJECT(value);
        if (JS_ObjectIsDate(context, obj)) {
            return to_python_datetime(context, obj);
        } else if (JS_IsArrayObject(context, obj)) {
            return to_python_list(context, obj);
        } else {
            return to_python_dict(context, obj);
        }
    }
}
开发者ID:jordanm,项目名称:spindly,代码行数:25,代码来源:spindly.c


示例8: __Window_echofy

void
__Window_echofy (jsval jsEcho, JSBool echoing, jsint cursor, JSBool start)
{
    if (start) {
        if (JSVAL_IS_BOOLEAN(jsEcho)) {
            if (JSVAL_TO_BOOLEAN(jsEcho)) {
                curs_set(1);
                echo();
            }
            else {
                noecho();
            }
        }
        else {
            curs_set(1);
            echo();
        }
    }
    else {
        if (echoing) {
            echo();
        }
        else {
            noecho();
        }
        curs_set(cursor);
    }
}
开发者ID:meh,项目名称:lulzjs-ncurses,代码行数:28,代码来源:Window.cpp


示例9: jsval_to_boolean_x

	/** 
	 * Converts a jsval to a C++ boolean
	 *   - throws exception if jsval is not a boolean
	 *
	 * \param 	val   Value to convert
	 * \return	C++ boolean
	 */
	static bool jsval_to_boolean_x(jsval val)
	{
		if(!JSVAL_IS_BOOLEAN(val))
			throw exception("Given jsval is not a boolean");

		return JSVAL_TO_BOOLEAN(val) != 0;
	}
开发者ID:FunkMonkey,项目名称:Bound,代码行数:14,代码来源:boolean_x.hpp


示例10: elixir_object_get_int

Eina_Bool
elixir_object_get_int(JSContext *cx, JSObject *obj, const char *name, int *value)
{
   jsval propertie;
   jsdouble localdbl;

   if (!JS_GetProperty(cx, obj, name, &propertie))
     return EINA_FALSE;

   if (JSVAL_IS_INT(propertie)
       || JSVAL_IS_STRING(propertie))
     {
        if (!JS_ValueToInt32(cx, propertie, value))
          return EINA_FALSE;
     }
   else
     if (JSVAL_IS_DOUBLE(propertie))
       {
          if (!JS_ValueToNumber(cx, propertie, &localdbl))
            return EINA_FALSE;
          *value = localdbl;
       }
     else
       if (JSVAL_IS_BOOLEAN(propertie))
         {
            *value = JSVAL_TO_BOOLEAN(propertie);
         }
       else
         return EINA_FALSE;

   return EINA_TRUE;
}
开发者ID:Limsik,项目名称:e17,代码行数:32,代码来源:elixir_object.c


示例11: js_ValueToBoolean

JSBool
js_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp)
{
    JSBool b;
    jsdouble d;

    if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v))
    {
        b = JS_FALSE;
    }
    else if (JSVAL_IS_OBJECT(v))
    {
        if (!JS_VERSION_IS_ECMA(cx))
        {
            if (!OBJ_DEFAULT_VALUE(cx, JSVAL_TO_OBJECT(v), JSTYPE_BOOLEAN, &v))
                return JS_FALSE;
            if (!JSVAL_IS_BOOLEAN(v))
                v = JSVAL_TRUE; /* non-null object is true */
            b = JSVAL_TO_BOOLEAN(v);
        }
        else
        {
            b = JS_TRUE;
        }
    }
    else if (JSVAL_IS_STRING(v))
    {
        b = JSSTRING_LENGTH(JSVAL_TO_STRING(v)) ? JS_TRUE : JS_FALSE;
    }
    else if (JSVAL_IS_INT(v))
    {
        b = JSVAL_TO_INT(v) ? JS_TRUE : JS_FALSE;
    }
    else if (JSVAL_IS_DOUBLE(v))
    {
        d = *JSVAL_TO_DOUBLE(v);
        b = (!JSDOUBLE_IS_NaN(d) && d != 0) ? JS_TRUE : JS_FALSE;
    }
    else
    {
        JS_ASSERT(JSVAL_IS_BOOLEAN(v));
        b = JSVAL_TO_BOOLEAN(v);
    }

    *bp = b;
    return JS_TRUE;
}
开发者ID:nixz,项目名称:covise,代码行数:47,代码来源:jsbool.c


示例12: Handle

 NS_IMETHOD Handle(const nsAString& aName, const JS::Value& aResult)
 {
   if (JSVAL_IS_BOOLEAN(aResult)) {
     bool isSharingEnabled = JSVAL_TO_BOOLEAN(aResult);
     SetAutoMounterSharingMode(mVolumeName, isSharingEnabled);
   }
   return NS_OK;
 }
开发者ID:Incognito,项目名称:mozilla-central,代码行数:8,代码来源:AutoMounterSetting.cpp


示例13: jsd_GetValueBoolean

JSBool
jsd_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval)
{
    jsval val = jsdval->val;
    if(!JSVAL_IS_BOOLEAN(val))
        return JS_FALSE;
    return JSVAL_TO_BOOLEAN(val);
}
开发者ID:moussa1,项目名称:mozilla-central,代码行数:8,代码来源:jsd_val.c


示例14: js_db_query

static JSBool
js_db_query(JSContext *cx, JSObject *obj, uintN argc,
            jsval *argv, jsval *rval)
{
    const char *query;
    js_db_t *jd = JS_GetPrivate(cx, obj);
    int rc;

    if(js_db_check(cx, jd))
        return JS_FALSE;

    if(!JS_ConvertArguments(cx, argc, argv, "s", &query))
        return JS_FALSE;

    if(jd->jd_stmt) {
        sqlite3_finalize(jd->jd_stmt);
        jd->jd_stmt = NULL;
    }

    rc = db_prepare(jd->jd_db, &jd->jd_stmt, query);

    if(rc != SQLITE_OK) {
        if(jd->jd_transaction && rc == SQLITE_LOCKED) {
            js_txn_deadlock(cx, jd);
            return JS_FALSE;
        }
        *rval = JSVAL_FALSE;
        return JS_TRUE;
    }

    sqlite3_stmt *stmt = jd->jd_stmt;

    for(int i = 1; i < argc; i++) {
        jsval v = argv[i];
        if(JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
            sqlite3_bind_null(stmt, i);
        } else if(JSVAL_IS_INT(v)) {
            sqlite3_bind_int(stmt, i, JSVAL_TO_INT(v));
        } else if(JSVAL_IS_BOOLEAN(v)) {
            sqlite3_bind_int(stmt, i, JSVAL_TO_BOOLEAN(v));
        } else if(JSVAL_IS_DOUBLE(v)) {
            double d;
            if(JS_ValueToNumber(cx, v, &d))
                sqlite3_bind_double(stmt, i, d);
        } else if(JSVAL_IS_STRING(v)) {
            JSString *s = JS_ValueToString(cx, v);
            sqlite3_bind_text(stmt, i, JS_GetStringBytes(s), -1, SQLITE_STATIC);
        } else {
            JS_ReportError(cx, "Unable to bind argument %d, invalid type", i);
            sqlite3_finalize(stmt);
            return JS_FALSE;
        }
    }

    *rval = JSVAL_TRUE;
    return js_stmt_step(cx, jd, rval);
}
开发者ID:Bibamaru,项目名称:showtime,代码行数:57,代码来源:js_db.c


示例15: js_weap_zoom_set_showWeapon

JSBool js_weap_zoom_set_showWeapon(JSContext *cx,JSObject *j_obj,jsval id,jsval *vp)
{
	weapon_type		*weap;
	
	weap=weapon_find_uid(js.attach.thing_uid);
	weap->zoom.show_weapon=JSVAL_TO_BOOLEAN(*vp);
	
	return(JS_TRUE);
}
开发者ID:prophile,项目名称:dim3,代码行数:9,代码来源:script_weap_zoom.c


示例16: js_obj_thrust_set_drag

JSBool js_obj_thrust_set_drag(JSContext *cx,JSObject *j_obj,jsval id,jsval *vp)
{
    obj_type		*obj;

    obj=object_find_uid(js.attach.thing_uid);
    obj->thrust.drag=JSVAL_TO_BOOLEAN(*vp);

    return(JS_TRUE);
}
开发者ID:prophile,项目名称:dim3,代码行数:9,代码来源:script_obj_object_thrust.c


示例17: assert

bool TraceMonkeyValue::getBool()
{
    assert(isValid());

    Logging::log(Logging::DEBUG, "TraceMonkeyValue::getBool: \r\n"); printJSVAL(value);

    assert(JSVAL_IS_BOOLEAN(value));
    return JSVAL_TO_BOOLEAN(value);
}
开发者ID:Amplifying,项目名称:intensityengine,代码行数:9,代码来源:script_engine_tracemonkey.cpp


示例18: ccTouchBegan

 bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) {
     CC_UNUSED_PARAM(pTouch); 
     CC_UNUSED_PARAM(pEvent); 
     jsval retval; 
     ScriptingCore::getInstance()->executeCustomTouchEvent(CCTOUCHBEGAN, 
                                                     pTouch, _mObj, retval);
     if(JSVAL_IS_BOOLEAN(retval)) {
         return JSVAL_TO_BOOLEAN(retval);
     } return false;
 };
开发者ID:nicolasgramlich,项目名称:cxx-generator,代码行数:10,代码来源:cocos2d_specifics.hpp


示例19: JSB_Facebook_getLoginStatus

JSBool JSB_Facebook_getLoginStatus(JSContext *cx, uint32_t argc, jsval *vp){
	jsval *argv = JS_ARGV(cx, vp);	
	
	int cbIndex = JSVAL_TO_INT(argv[0]);
	bool force = JSVAL_TO_BOOLEAN(argv[1]);
	
	FacebookInterface::getLoginStatus(cbIndex,force);

	return JS_TRUE;
}
开发者ID:Ratel13,项目名称:facebook-jsb-sdk-samples,代码行数:10,代码来源:js_bindings_facebook.cpp


示例20: jsval_to_boolean

SEXP
jsval_to_boolean(SEXP ptr)
{
    jsval *p = R_ExternalPtrAddr(ptr);
    if(!JSVAL_IS_BOOLEAN(*p)) {
	PROBLEM "jsval is not a boolean!"
	    ERROR;
    }
    return(ScalarLogical(JSVAL_TO_BOOLEAN(*p)));
}
开发者ID:omegahat,项目名称:SpiderMonkey,代码行数:10,代码来源:jsval.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ JSVAL_TO_STRING函数代码示例发布时间:2022-05-30
下一篇:
C++ JSVAL_IS_VOID函数代码示例发布时间: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