本文整理汇总了C++中JSVAL_TO_BOOLEAN函数的典型用法代码示例。如果您正苦于以下问题:C++ JSVAL_TO_BOOLEAN函数的具体用法?C++ JSVAL_TO_BOOLEAN怎么用?C++ JSVAL_TO_BOOLEAN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSVAL_TO_BOOLEAN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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 */
}
示例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);
}
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}