本文整理汇总了C++中JSVAL_IS_NUMBER函数的典型用法代码示例。如果您正苦于以下问题:C++ JSVAL_IS_NUMBER函数的具体用法?C++ JSVAL_IS_NUMBER怎么用?C++ JSVAL_IS_NUMBER使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSVAL_IS_NUMBER函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: __JSVal_TO_string
JSBool ofxJSTrueTypeFont::JSFUNC_loadFont(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
ofxJSTrueTypeFont *p = (ofxJSTrueTypeFont*)JS_GetPrivate(cx, obj);
if (argc < 2) return JS_FALSE;
if (argc == 2) {
/* Function: void loadFont (string filename, int fontsize) */
if (JSVAL_IS_STRING(argv[0]) && JSVAL_IS_NUMBER(argv[1])) {
p->loadFont(
__JSVal_TO_string(argv[0]),
__JSVal_TO_int(argv[1])
);
return JS_TRUE;
}
}
if (argc == 5) {
/* Function: void loadFont (string filename, int fontsize, bool _bAntiAliased, bool _bFullCharacterSet, bool makeContours) */
if (JSVAL_IS_STRING(argv[0]) && JSVAL_IS_NUMBER(argv[1]) && JSVAL_IS_BOOLEAN(argv[2]) && JSVAL_IS_BOOLEAN(argv[3]) && JSVAL_IS_BOOLEAN(argv[4])) {
p->loadFont(
__JSVal_TO_string(argv[0]),
__JSVal_TO_int(argv[1]),
__JSVal_TO_bool(argv[2]),
__JSVal_TO_bool(argv[3]),
__JSVal_TO_bool(argv[4])
);
return JS_TRUE;
}
}
return JS_FALSE;
}
示例2: js_conio_window
static JSBool
js_conio_window(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
int32 left=1;
int32 top=1;
int32 right=cio_textinfo.screenwidth;
int32 bottom=cio_textinfo.screenheight;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if(argc > 4)
return(JS_FALSE);
if(argc > 0) {
if(!JSVAL_IS_NUMBER(argv[0]))
return(JS_FALSE);
if(!JS_ValueToInt32(cx, argv[0], &left))
return(JS_FALSE);
}
if(argc > 1) {
if(!JSVAL_IS_NUMBER(argv[1]))
return(JS_FALSE);
if(!JS_ValueToInt32(cx, argv[1], &top))
return(JS_FALSE);
}
if(argc > 2) {
if(!JSVAL_IS_NUMBER(argv[2]))
return(JS_FALSE);
if(!JS_ValueToInt32(cx, argv[2], &right))
return(JS_FALSE);
}
if(argc > 3) {
if(!JSVAL_IS_NUMBER(argv[3]))
return(JS_FALSE);
if(!JS_ValueToInt32(cx, argv[3], &bottom))
return(JS_FALSE);
}
rc=JS_SUSPENDREQUEST(cx);
window(left, top, right, bottom);
JS_RESUMEREQUEST(cx, rc);
if(cio_textinfo.winleft == left
&& cio_textinfo.winright==right
&& cio_textinfo.wintop==top
&& cio_textinfo.winbottom==bottom) {
JS_SET_RVAL(cx, arglist,JSVAL_TRUE);
}
else {
JS_SET_RVAL(cx, arglist,JSVAL_FALSE);
}
return(JS_TRUE);
}
示例3: JSHistogram_Add
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;
}
示例4: js_conio_gettext
static JSBool
js_conio_gettext(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
int32 args[4];
unsigned char *result;
int i;
int size;
JSObject *array;
jsval val;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
/* default values: */
args[0]=1;
args[1]=1;
args[2]=cio_textinfo.screenwidth;
args[3]=cio_textinfo.screenheight;
if(argc > 4)
return(JS_FALSE);
for(i=0; i<(int)argc; i++) {
if(!JSVAL_IS_NUMBER(argv[i]))
return(JS_FALSE);
if(!JS_ValueToInt32(cx, argv[i], &args[i]))
return(JS_FALSE);
}
if(args[0] < 1 || args[1] < 1 || args[2] < 1 || args[3] < 1
|| args[0] > args[2] || args[1] > args[3]
|| args[2] > cio_textinfo.screenwidth || args[3] > cio_textinfo.screenheight) {
JS_SET_RVAL(cx, arglist,JSVAL_FALSE);
return(JS_TRUE);
}
size=(args[2]-args[0]+1)*(args[3]-args[1]+1)*2;
result=(unsigned char *)malloc(size);
if(result==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
if(gettext(args[0], args[1], args[2], args[3], result)) {
JS_RESUMEREQUEST(cx, rc);
array=JS_NewArrayObject(cx, 0, NULL);
for(i=0; i<size; i++) {
val=UINT_TO_JSVAL(result[i]);
if(!JS_SetElement(cx, array, i, &val)) {
free(result);
return(JS_FALSE);
}
}
JS_SET_RVAL(cx, arglist,OBJECT_TO_JSVAL(array));
}
else {
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist,JSVAL_NULL);
}
free(result);
return(JS_TRUE);
}
示例5: Array
static JSBool
Array(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsuint length;
jsval *vector;
/* If called without new, replace obj with a new Array object. */
if (!(cx->fp->flags & JSFRAME_CONSTRUCTING)) {
obj = js_NewObject(cx, &js_ArrayClass, NULL, NULL);
if (!obj)
return JS_FALSE;
*rval = OBJECT_TO_JSVAL(obj);
}
if (argc == 0) {
length = 0;
vector = NULL;
} else if (cx->version == JSVERSION_1_2) {
length = (jsuint) argc;
vector = argv;
} else if (argc > 1) {
length = (jsuint) argc;
vector = argv;
} else if (!JSVAL_IS_NUMBER(argv[0])) {
length = 1;
vector = argv;
} else {
if (!ValueIsLength(cx, argv[0], &length))
return JS_FALSE;
vector = NULL;
}
return InitArrayObject(cx, obj, length, vector);
}
示例6: JSVAL_TO_INT
int32_t Context::FromJSArg<int32_t>(const JS::Value &val) const
{
if(!JSVAL_IS_NUMBER(val)) {
return 0;
}
return JSVAL_TO_INT(val);
}
示例7: byte_array_set_prop
/* a hook on setting a property; set value_p to override property value to
* be set. Return value is JS_FALSE on OOM/exception.
*/
static JSBool
byte_array_set_prop(JSContext *context,
JS::HandleObject obj,
JS::HandleId id,
JSBool strict,
JS::MutableHandleValue value_p)
{
ByteArrayInstance *priv;
jsval id_value;
priv = priv_from_js(context, obj);
if (priv == NULL)
return JS_TRUE; /* prototype, not an instance. */
if (!JS_IdToValue(context, id, &id_value))
return JS_FALSE;
/* First handle array indexing */
if (JSVAL_IS_NUMBER(id_value)) {
gsize idx;
if (!gjs_value_to_gsize(context, id_value, &idx))
return JS_FALSE;
return byte_array_set_index(context, obj, priv, idx, value_p);
}
/* We don't special-case anything else for now */
return JS_TRUE;
}
示例8: js_printtail
static JSBool
js_printtail(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
int lines=0;
long mode=0;
uintN i;
sbbs_t* sbbs;
JSString* js_str=NULL;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
for(i=0;i<argc;i++) {
if(JSVAL_IS_NUMBER(argv[i])) {
if(!lines)
JS_ValueToInt32(cx,argv[i],(int32*)&lines);
else
JS_ValueToInt32(cx,argv[i],(int32*)&mode);
} else if(JSVAL_IS_STRING(argv[i]))
js_str = JS_ValueToString(cx, argv[i]);
}
if(js_str==NULL)
return(JS_FALSE);
if(!lines)
lines=5;
sbbs->printtail(JS_GetStringBytes(js_str),lines,mode);
return(JS_TRUE);
}
示例9: js_conio_cgets
static JSBool
js_conio_cgets(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
char buf[258];
int32 maxlen=255;
char *ret;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if(argc > 1)
return(JS_FALSE);
if(argc > 0) {
if(!JSVAL_IS_NUMBER(argv[0]))
return(JS_FALSE);
if(!JS_ValueToInt32(cx, argv[0], &maxlen))
return(JS_FALSE);
if(maxlen > 255)
return(JS_FALSE);
}
buf[0]=(char)maxlen;
rc=JS_SUSPENDREQUEST(cx);
ret=cgets(buf);
JS_RESUMEREQUEST(cx, rc);
if(ret==NULL)
JS_SET_RVAL(cx, arglist,JSVAL_NULL);
else {
buf[257]=0;
JS_SET_RVAL(cx, arglist,STRING_TO_JSVAL(JS_NewStringCopyZ(cx,ret)));
}
return(JS_TRUE);
}
示例10: JSVAL_TO_DOUBLE
double Context::FromJSArg<double>(const JS::Value &val) const
{
if(!JSVAL_IS_NUMBER(val)) {
return 0.0f;
}
return JSVAL_TO_DOUBLE(val);
}
示例11: 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;
}
示例12: WARN_IF_NOT
template<> bool ScriptInterface::FromJSVal<u8>(JSContext* cx, jsval v, u8& out)
{
uint16 ret;
WARN_IF_NOT(JSVAL_IS_NUMBER(v), v);
if (!JS_ValueToUint16(cx, v, &ret))
return false;
out = (u8)ret;
return true;
}
示例13: JSFUNC_drawStringAsShapes
JSBool ofxJSTrueTypeFont::JSFUNC_drawStringAsShapes(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
ofxJSTrueTypeFont *p = (ofxJSTrueTypeFont*)JS_GetPrivate(cx, obj);
if (argc < 3) return JS_FALSE;
if (argc == 3) {
/* Function: void drawStringAsShapes (string s, float x, float y) */
if (JSVAL_IS_STRING(argv[0]) && JSVAL_IS_NUMBER(argv[1]) && JSVAL_IS_NUMBER(argv[2])) {
p->drawStringAsShapes(
__JSVal_TO_string(argv[0]),
__JSVal_TO_float(argv[1]),
__JSVal_TO_float(argv[2])
);
return JS_TRUE;
}
}
return JS_FALSE;
}
示例14: js_conio_gotoxy
static JSBool
js_conio_gotoxy(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
int32 x,y;
jsrefcount rc;
if(argc >= 2 && JSVAL_IS_NUMBER(argv[0]) && JS_ValueToInt32(cx,argv[0],&x)
&& JSVAL_IS_NUMBER(argv[1]) && JS_ValueToInt32(cx,argv[1],&y)) {
rc=JS_SUSPENDREQUEST(cx);
gotoxy(x,y);
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
JS_ReportError(cx, "Insufficient Arguments");
return(JS_FALSE);
}
示例15: Core_print
JSBool
Core_print (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JS_BeginRequest(cx);
JS_EnterLocalRootScope(cx);
char* separator = " ";
char* end = "\n";
int fd = fileno(stdout);
FILE* fp = NULL;
jsval property;
JSObject* options;
if (argc > 1 && JS_TypeOfValue(cx, argv[argc-1]) == JSTYPE_OBJECT) {
JS_ValueToObject(cx, argv[argc-1], &options);
argc--;
JS_GetProperty(cx, options, "separator", &property);
if (JSVAL_IS_VOID(property) || JSVAL_IS_NULL(property)) {
JS_GetProperty(cx, options, "sep", &property);
}
if (JSVAL_IS_STRING(property)) {
separator = JS_GetStringBytes(JS_ValueToString(cx, property));
}
JS_GetProperty(cx, options, "end", &property);
if (JSVAL_IS_STRING(property)) {
end = JS_GetStringBytes(JS_ValueToString(cx, property));
}
JS_GetProperty(cx, options, "file", &property);
if (JSVAL_IS_NUMBER(property)) {
fd = JSVAL_TO_INT(property);
}
}
fp = fdopen(fd, "a+");
uintN i;
for (i = 0; i < argc; i++) {
fprintf(fp, "%s", JS_GetStringBytes(JS_ValueToString(cx, argv[i])));
if (i != argc-1) {
fprintf(fp, "%s", separator);
}
}
fprintf(fp, "%s", end);
JS_LeaveLocalRootScope(cx);
JS_EndRequest(cx);
return JS_TRUE;
}