Exemple #1
0
void ScriptingCore::string_report(jsval val) {
    if (JSVAL_IS_NULL(val)) {
        LOGD("val : (JSVAL_IS_NULL(val)");
        // return 1;
    } else if ((JSVAL_IS_BOOLEAN(val)) &&
               (JS_FALSE == (JSVAL_TO_BOOLEAN(val)))) {
        LOGD("val : (return value is JS_FALSE");
        // return 1;
    } else if (JSVAL_IS_STRING(val)) {
        JSString *str = JS_ValueToString(this->getGlobalContext(), val);
        if (NULL == str) {
            LOGD("val : return string is NULL");
        } else {
			JSStringWrapper wrapper(str);
            LOGD("val : return string =\n%s\n", (char *)wrapper);
        }
    } else if (JSVAL_IS_NUMBER(val)) {
        double number;
        if (JS_FALSE ==
            JS_ValueToNumber(this->getGlobalContext(), val, &number)) {
            LOGD("val : return number could not be converted");
        } else {
            LOGD("val : return number =\n%f", number);
        }
    }
}
Exemple #2
0
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_GET_CLASS(cx, obj);

    if(!strcmp(c->name, "XML"))   // Treat some classes special
      js_json_emit_str(cx, value, out);
    else {
      if(js_json_encode_from_object(cx, obj, out))
	htsbuf_append(out, "null", 4);
    }
  }
}
Exemple #3
0
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);

}
Exemple #4
0
JSBool
js_ValueToObject(JSContext *cx, jsval v, JSObject **objp)
{
    JSObject *obj;

    if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
	obj = NULL;
    } else if (JSVAL_IS_OBJECT(v)) {
	obj = JSVAL_TO_OBJECT(v);
	if (!obj->map->clasp->convert(cx, obj, JSTYPE_OBJECT, &v))
	    return JS_FALSE;
	if (JSVAL_IS_OBJECT(v))
	    obj = JSVAL_TO_OBJECT(v);
    } else {
	if (JSVAL_IS_STRING(v)) {
	    obj = js_StringToObject(cx, JSVAL_TO_STRING(v));
	} else if (JSVAL_IS_INT(v)) {
	    obj = js_NumberToObject(cx, (jsdouble)JSVAL_TO_INT(v));
	} else if (JSVAL_IS_DOUBLE(v)) {
	    obj = js_NumberToObject(cx, *JSVAL_TO_DOUBLE(v));
	} else {
	    PR_ASSERT(JSVAL_IS_BOOLEAN(v));
	    obj = js_BooleanToObject(cx, JSVAL_TO_BOOLEAN(v));
	}
	if (!obj)
	    return JS_FALSE;
    }
    *objp = obj;
    return JS_TRUE;
}
JSBool
JSHistogram_Add(JSContext *cx, unsigned argc, jsval *vp)
{
  if (!argc) {
    JS_ReportError(cx, "Expected one argument");
    return JS_FALSE;
  }

  jsval v = JS_ARGV(cx, vp)[0];

  if (!(JSVAL_IS_NUMBER(v) || JSVAL_IS_BOOLEAN(v))) {
    JS_ReportError(cx, "Not a number");
    return JS_FALSE;
  }

  int32_t value;
  if (!JS_ValueToECMAInt32(cx, v, &value)) {
    return JS_FALSE;
  }

  if (TelemetryImpl::CanRecord()) {
    JSObject *obj = JS_THIS_OBJECT(cx, vp);
    if (!obj) {
      return JS_FALSE;
    }

    Histogram *h = static_cast<Histogram*>(JS_GetPrivate(obj));
    if (h->histogram_type() == Histogram::BOOLEAN_HISTOGRAM)
      h->Add(!!value);
    else
      h->Add(value);
  }
  return JS_TRUE;
}
Exemple #6
0
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;
}
Exemple #7
0
static JSBool SMJS_FUNCTION(upnp_service_set_action_listener)
{
	PLT_ActionDesc *action;
	PLT_ArgumentDesc *desc;
	GPAC_ActionArgListener *argl  = NULL;
	char *name;
	Bool script_callback = GF_FALSE;
	u32 i;
	SMJS_OBJ
	SMJS_ARGS
	GPAC_ServiceItem *service = (GPAC_ServiceItem *)SMJS_GET_PRIVATE(c, obj);
	if (!service || (argc<2) || !JSVAL_IS_STRING(argv[0]) || !JSVAL_IS_OBJECT(argv[1])) return JS_FALSE;

	name = SMJS_CHARS(c, argv[0]);
	if (!name) return JS_FALSE;

	action = service->m_service->FindActionDesc(name);
	SMJS_FREE(c, name);

	if (!action) return JS_FALSE;

	desc = NULL;
	if (argc==3) {
		if (JSVAL_IS_BOOLEAN(argv[2])) {
			script_callback = GF_TRUE;
		} else {
			if (!JSVAL_IS_STRING(argv[2]) ) return JS_FALSE;
			name = SMJS_CHARS(c, argv[2]);
			if (!name) return JS_FALSE;
			desc = action->GetArgumentDesc(name);
			SMJS_FREE(c, name);
			if (!desc) return JS_FALSE;
		}
	}


	/*action listener*/
	i=0;
	while ((argl = (GPAC_ActionArgListener *)gf_list_enum(service->m_ArgListeners, &i))) {
		if (argl->arg == desc) break;
		argl = NULL;
	}
	if (!argl) {
		argl = new GPAC_ActionArgListener();
		argl->arg = desc;
		gf_list_add(service->m_ArgListeners, argl);
	}
	argl->action = action;
	if (!JSVAL_IS_NULL(argl->on_event))
		gf_js_remove_root(c, &argl->on_event, GF_JSGC_VAL);
	if (JSVAL_IS_NULL(argv[1])) {
		gf_list_del_item(service->m_ArgListeners, argl);
		delete argl;
	}
	argl->on_event = argv[1];
	argl->is_script = script_callback;
	gf_js_add_root(c, &argl->on_event, GF_JSGC_VAL);
	return JS_TRUE;
}
 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;
 }
Exemple #9
0
JSBool
jsd_GetValueBoolean(JSDContext* jsdc, JSDValue* jsdval)
{
    jsval val = jsdval->val;
    if(!JSVAL_IS_BOOLEAN(val))
        return JS_FALSE;
    return JSVAL_TO_BOOLEAN(val);
}
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;
}
Exemple #11
0
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);
}
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);
}
template<> bool ScriptInterface::FromJSVal<bool>(JSContext* cx, jsval v, bool& out)
{
	JSBool ret;
	WARN_IF_NOT(JSVAL_IS_BOOLEAN(v), v);
	if (!JS_ValueToBoolean(cx, v, &ret))
		return false;
	out = (ret ? true : false);
	return true;
}
 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;
 };
Exemple #15
0
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)));
}
Exemple #16
0
loc_reload(JSContext *cx, JSObject *obj,
	   uint argc, jsval *argv, jsval *rval)
{
    if (!JS_InstanceOf(cx, obj, &lm_location_class, argv))
        return JS_FALSE;
    return url_load(cx, obj, get_url_string(cx, obj),
		    (JSVAL_IS_BOOLEAN(argv[0]) && JSVAL_TO_BOOLEAN(argv[0]))
		    ? NET_SUPER_RELOAD
		    : NET_NORMAL_RELOAD);
}
Exemple #17
0
component_mozilla_method_stub(JSContext *cx, JSObject *obj, uint argc, 
			      jsval *argv, jsval *rval)
{
    JSFunction *func;
    JSObject *func_obj;
    jsval type, native;
    uint i;
    JSCompArg *comp_argv;

    func = JS_ValueToFunction(cx, argv[-2]);
    func_obj = JS_GetFunctionObject(func);

    if (!JS_GetProperty(cx, func_obj, lm_typePrefix_str, &type) ||
	!JSVAL_IS_INT(type) ||
	!JS_GetProperty(cx, func_obj, lm_methodPrefix_str, &native) ||
	!(comp_argv = JS_malloc(cx, argc * sizeof(JSCompArg))))
	return JS_TRUE;
  
    for (i=0; i<argc; i++) {
	if (JSVAL_IS_INT(argv[i])) {
	    comp_argv[i].type = ARGTYPE_INT32;
	    comp_argv[i].value.intArg = JSVAL_TO_INT(argv[i]);
	}
	else if (JSVAL_IS_BOOLEAN(argv[i])) {
	    comp_argv[i].type = ARGTYPE_BOOL;
	    comp_argv[i].value.boolArg = JSVAL_TO_BOOLEAN(argv[i]);
	}
	else if (JSVAL_IS_STRING(argv[i])) {
	    comp_argv[i].type = ARGTYPE_STRING;
	    comp_argv[i].value.stringArg = JS_GetStringBytes(JSVAL_TO_STRING(argv[i]));
	}
	else {
	    comp_argv[i].type = ARGTYPE_NULL;
	    comp_argv[i].value.intArg = 0;
	}
    }

    switch(JSVAL_TO_INT(type)) {
    case ARGTYPE_NULL:
	ET_moz_CompMethodFunction((ETCompMethodFunc)JSVAL_TO_INT(native), argc, NULL);
	*rval = 0;
	break;
    case ARGTYPE_INT32:
	*rval = INT_TO_JSVAL((int32)ET_moz_CompMethodFunction((ETCompMethodFunc)JSVAL_TO_INT(native), argc, comp_argv));
	break;
    case ARGTYPE_BOOL:
	*rval = BOOLEAN_TO_JSVAL((JSBool)ET_moz_CompMethodFunction((ETCompMethodFunc)JSVAL_TO_INT(native), argc, comp_argv));
	break;
    case ARGTYPE_STRING:
	*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, 
		(char*)ET_moz_CompMethodFunction((ETCompMethodFunc)JSVAL_TO_INT(native), argc, comp_argv)));
	break;
    }
    return JS_TRUE;
}
/* void printArgTypes (); */
NS_IMETHODIMP
xpctestEcho::PrintArgTypes(void)
{
    GET_CALL_CONTEXT;
    if(NS_FAILED(rv) || !cc)
        return NS_ERROR_FAILURE;

    nsCOMPtr<nsISupports> callee;
    if(NS_FAILED(cc->GetCallee(getter_AddRefs(callee))) ||
       callee != static_cast<nsIEcho*>(this))
        return NS_ERROR_FAILURE;

    PRUint32 argc;
    if(NS_SUCCEEDED(cc->GetArgc(&argc)))
        printf("argc = %d  ", (int)argc);
    else
        return NS_ERROR_FAILURE;

    jsval* argv;
    if(NS_FAILED(cc->GetArgvPtr(&argv)))
        return NS_ERROR_FAILURE;

    printf("argv types = [");

    for(PRUint32 i = 0; i < argc; i++)
    {
        const char* type = "<unknown>";
        if(JSVAL_IS_OBJECT(argv[i]))
        {
            if(JSVAL_IS_NULL(argv[i]))
                type = "null";
            else
                type = "object";
        }
        else if (JSVAL_IS_BOOLEAN(argv[i]))
            type = "boolean";
        else if (JSVAL_IS_STRING(argv[i]))
            type = "string";
        else if (JSVAL_IS_DOUBLE(argv[i]))
            type = "double";
        else if (JSVAL_IS_INT(argv[i]))
            type = "int";
        else if (JSVAL_IS_VOID(argv[i]))
            type = "void";

        fputs(type, stdout);

        if(i < argc-1)
            printf(", ");
    }
    printf("]\n");
    
    return NS_OK;
}
static void _modulesInstalled(SG_context *pCtx, JSContext *cx, JSObject *glob, SG_bool *installed)
{
	jsval jv = JSVAL_VOID;

	SG_UNUSED(pCtx);

	*installed = SG_FALSE;

	if (JS_GetProperty(cx, glob, "vvModulesInstalled", &jv) && JSVAL_IS_BOOLEAN(jv))
	{
		*installed = JSVAL_TO_BOOLEAN(jv);
	}
}
bool TraceMonkeyValue::compare(ScriptValuePtr other)
{
    assert(isValid());
    assert(other->isValid());

    jsval otherValue = (dynamic_cast<TraceMonkeyValue*>(other.get()))->value;

    if (JSVAL_IS_INT(value))
        return (JSVAL_IS_INT(otherValue) && JSVAL_TO_INT(value) == JSVAL_TO_INT(otherValue));
    else if (JSVAL_IS_NULL(value))
        return (JSVAL_IS_NULL(otherValue));
    else if (JSVAL_IS_VOID(value))
        return (JSVAL_IS_VOID(otherValue));
    else if (JSVAL_IS_BOOLEAN(value))
        return (JSVAL_IS_BOOLEAN(otherValue) && JSVAL_TO_BOOLEAN(value) == JSVAL_TO_BOOLEAN(otherValue));
    else if (JSVAL_IS_DOUBLE(value))
        return (JSVAL_IS_DOUBLE(otherValue) && *(JSVAL_TO_DOUBLE(value)) == *(JSVAL_TO_DOUBLE(otherValue)));
    else if (JSVAL_IS_STRING(value))
    {
        if (!JSVAL_IS_STRING(otherValue))
            return false;
        else
            assert(0 && "TODO: compare TM strings");
    }
    else if (JSVAL_IS_OBJECT(value))
    {
        if (JSVAL_IS_NULL(otherValue)) // NULLs are objects, in TraceMonkey
            return false;
        if (!JSVAL_IS_OBJECT(otherValue))
            return false;
        else
            assert(0 && "TODO: compare TM objects");
    }
    else {
        Logging::log(Logging::INFO, "Can't compare uncertain jsvals\r\n");
    }
    assert(0);
    return false;
}
Exemple #21
0
static JSBool debug_protocol_hdlr(JSContext *cx, JSObject *obj, jsval *vp)
{
	/* Check if debugProtocol was assigned a boolean value */
	if (!JSVAL_IS_BOOLEAN(*vp))
		return JS_FALSE;

	if (JSVAL_TO_BOOLEAN(*vp) == JS_TRUE)
		config.smtp_debug = 1;
	else
		config.smtp_debug = 0;

	return JS_TRUE;
}
JSBool setSuccess(JSContext *cx, JSObject *obj, uintN argc, 
                                       jsval *argv, jsval *rval)
{// begin setSuccess
	bool Jscript_succeed = false;
	// default return value
	if(argc != 1)
		return JS_FALSE;
	if(JSVAL_IS_BOOLEAN(argv[0]) == false)
		return JS_FALSE;
	Jscript_succeed = JSVAL_TO_BOOLEAN(argv[0]);
	JS_setSuccess(Jscript_succeed);

	return JS_TRUE;
}// end setSuccess
JSBool ofxJSSoundPlayer::JSFUNC_setPaused(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
	ofxJSSoundPlayer *p = (ofxJSSoundPlayer*)JS_GetPrivate(cx, obj);
	if (argc < 1) return JS_FALSE;
	if (argc == 1) {
		/* Function: void setPaused(bool bP) */
		if (JSVAL_IS_BOOLEAN(argv[0])) {
			p->setPaused(__JSVal_TO_bool(argv[0]));
			return JS_TRUE;
		}
	}


	return JS_FALSE;
}
Exemple #24
0
INT unit_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
	CDebug cDbg("unit setProperty");

	switch(JSVAL_TO_INT(id))
	{
		case ME_CHICKENHP:
			if(JSVAL_IS_INT(*vp))
				Vars.nChickenHP		= JSVAL_TO_INT(*vp);
			break;
		case ME_CHICKENMP:
			if(JSVAL_IS_INT(*vp))
				Vars.nChickenMP		= JSVAL_TO_INT(*vp);
			break;
		case ME_QUITONHOSTILE:
			if(JSVAL_IS_BOOLEAN(*vp))
				Vars.bQuitOnHostile = JSVAL_TO_BOOLEAN(*vp);
			break;
		case OOG_QUITONERROR:
			if(JSVAL_IS_BOOLEAN(*vp))
				Vars.bQuitOnError	= JSVAL_TO_BOOLEAN(*vp);
			break;
		case OOG_MAXGAMETIME:
			if(JSVAL_IS_INT(*vp))
				Vars.dwMaxGameTime	= JSVAL_TO_INT(*vp);
			break;
		case ME_BLOCKKEYS:
			if(JSVAL_IS_BOOLEAN(*vp))
				Vars.bBlockKeys = JSVAL_TO_BOOLEAN(*vp);
			break;
		case ME_BLOCKMOUSE:
			if(JSVAL_IS_BOOLEAN(*vp))
				Vars.bBlockMouse = JSVAL_TO_BOOLEAN(*vp);
			break;
	}
	return JS_TRUE;
}
Exemple #25
0
SEXP
js_to_R(SEXP ptr)
{
    jsval *p = R_ExternalPtrAddr(ptr);
    if(JSVAL_IS_INT(*p))
	return(ScalarInteger(JSVAL_TO_INT(*p)));
    else if(JSVAL_IS_BOOLEAN(*p))
        return(ScalarLogical(JSVAL_TO_BOOLEAN(*p)));
    else if(JSVAL_IS_DOUBLE(*p))
        return(ScalarReal( * JSVAL_TO_DOUBLE(*p)));
    else  if(JSVAL_IS_STRING(*p)) {
	return(jsval_to_string(ptr));
    } else
	return(R_NilValue);
}
Exemple #26
0
JSAtom *
js_AtomizeValue(JSContext *cx, jsval value, uintN flags)
{
    if (JSVAL_IS_STRING(value))
        return js_AtomizeString(cx, JSVAL_TO_STRING(value), flags);
    if (JSVAL_IS_INT(value))
        return js_AtomizeInt(cx, JSVAL_TO_INT(value), flags);
    if (JSVAL_IS_DOUBLE(value))
        return js_AtomizeDouble(cx, *JSVAL_TO_DOUBLE(value), flags);
    if (JSVAL_IS_OBJECT(value))
        return js_AtomizeObject(cx, JSVAL_TO_OBJECT(value), flags);
    if (JSVAL_IS_BOOLEAN(value))
        return js_AtomizeBoolean(cx, JSVAL_TO_BOOLEAN(value), flags);
    return js_AtomizeHashedKey(cx, value, (JSHashNumber)value, flags);
}
bool TraceMonkeyValue::getPropertyBool(std::string propertyName)
{
    assert(isValid());

    Logging::log(Logging::DEBUG, "TraceMonkeyValue::getPropertyBool(%s): \r\n", propertyName.c_str()); printJSVAL(value);

    assert(JSVAL_IS_OBJECT(value));
    jsval ret;
    bool success =JS_GetProperty(TraceMonkeyEngine::context, JSVAL_TO_OBJECT(value), propertyName.c_str(), &ret);
    assert(success);
    assert(JSVAL_IS_BOOLEAN(ret));

    Logging::log(Logging::DEBUG, "returning: \r\n"); printJSVAL(ret);

    return JSVAL_TO_BOOLEAN(ret);
}
JSBool ADM_JSAvidemuxVideo::JSSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
        if (JSVAL_IS_INT(id)) 
        {
                ADM_JSAvidemuxVideo *priv = (ADM_JSAvidemuxVideo *) JS_GetPrivate(cx, obj);
                switch(JSVAL_TO_INT(id))
                {
                        case videoprocess_prop:
                                if(JSVAL_IS_BOOLEAN(*vp) == false)
                                        break;
                                priv->getObject()->m_bVideoProcess = JSVAL_TO_BOOLEAN(*vp);
                                UI_setVProcessToggleStatus(priv->getObject()->m_bVideoProcess);
                                break;
                }
        }
        return JS_TRUE;
}
Exemple #29
0
component_mozilla_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    char *name, *type_str, *set_str, *prop_val;
    jsval type, func;

    if (!JSVAL_IS_STRING(id))
	return JS_TRUE;

    name = JS_GetStringBytes(JSVAL_TO_STRING(id));

    type_str = JS_malloc(cx, XP_STRLEN(lm_typePrefix_str) + XP_STRLEN(name) + 1);
    set_str = JS_malloc(cx, XP_STRLEN(lm_setPrefix_str) + XP_STRLEN(name) + 1);
    if (!type_str || !set_str)
	return JS_TRUE;

    XP_STRCPY(type_str, lm_typePrefix_str);
    XP_STRCAT(type_str, name);
    XP_STRCPY(set_str, lm_setPrefix_str);
    XP_STRCAT(set_str, name);
    if (!JS_GetProperty(cx, obj, type_str, &type) ||
	!JSVAL_IS_INT(type) ||
	!JS_GetProperty(cx, obj, set_str, &func))
	return JS_TRUE;

    JS_free(cx, type_str);
    JS_free(cx, set_str);
  
    switch(JSVAL_TO_INT(type)) {
    case ARGTYPE_INT32:
	if (JSVAL_IS_INT(*vp))
	    ET_moz_CompSetterFunction((ETCompPropSetterFunc)JSVAL_TO_INT(func), name, (void*)JSVAL_TO_INT(*vp));
	break;
    case ARGTYPE_BOOL:
	if (JSVAL_IS_BOOLEAN(*vp))
	    ET_moz_CompSetterFunction((ETCompPropSetterFunc)JSVAL_TO_INT(func), name, (void*)JSVAL_TO_BOOLEAN(*vp));
	break;
    case ARGTYPE_STRING:
	if (JSVAL_IS_STRING(*vp)) {
	    prop_val = JS_GetStringBytes(JSVAL_TO_STRING(*vp));
	    ET_moz_CompSetterFunction((ETCompPropSetterFunc)JSVAL_TO_INT(func), name, (void*)prop_val);
	}
	break;
    }

    return JS_TRUE;
}
Exemple #30
0
static bool JSOBJECT_CHECK_TYPE(jsval jsObj)
{
  bool isType;

  isType = JSVAL_IS_BOOLEAN(jsObj);
  isType = JSVAL_IS_DOUBLE(jsObj);
  isType = JSVAL_IS_GCTHING(jsObj);
  isType = JSVAL_IS_INT(jsObj);
  isType = JSVAL_IS_NULL(jsObj);
  isType = JSVAL_IS_NUMBER(jsObj);
  isType = JSVAL_IS_OBJECT(jsObj);
  isType = JSVAL_IS_PRIMITIVE(jsObj);
  isType = JSVAL_IS_STRING(jsObj);
  isType = JSVAL_IS_VOID(jsObj);

  return true;
}