CEXPORT JSBool def_animate_wait(JSContext *cx, unsigned argc, jsval *vp) { JS_BeginRequest(cx); jsval *vals = JS_ARGV(cx, vp); JSObject *thiz = JSVAL_TO_OBJECT(JS_THIS(cx, vp)); view_animation *anim = (view_animation *)JS_GetPrivate(thiz); double dt; JS_ValueToNumber(cx, *vals, &dt); view_animation_wait(anim, dt); jsval thiz_val = OBJECT_TO_JSVAL(thiz); JS_SET_RVAL(cx, vp, thiz_val); JS_EndRequest(cx); return JS_TRUE; }
jsdouble js_parseFloat (JSContext* cx, jsval number) { jsval ret; jsval argv[] = {number}; JS_CallFunctionName(cx, JS_GetGlobalObject(cx), "parseFloat", 1, argv, &ret); if (strcmp(JS_GetStringBytes(JS_ValueToString(cx, ret)), "NaN") == 0) { return 0; } jsdouble nret; JS_ValueToNumber(cx, ret, &nret); return nret; }
JSBool jsval_to_long(JSContext *cx, jsval vp, long* ret) { JSBool ok = JS_TRUE; double dp; ok &= JS_ValueToNumber(cx, vp, &dp); if (!ok) { LOGD("jsval_to_long: the argument is not a number"); return JS_FALSE; } ok &= !isnan(dp); JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments"); *ret = (long)dp; return ok; }
JSBool jsval_to_uint16( JSContext *cx, jsval vp, uint16_t *outval ) { JSBool ok = JS_TRUE; double dp; ok &= JS_ValueToNumber(cx, vp, &dp); if (!ok) { LOGD("jsval_to_uint16: the argument is not a number"); return JS_FALSE; } ok &= !isnan(dp); JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments"); *outval = (uint16_t)dp; return ok; }
static void create_real_elements (JSContext *cxt, jsval val, gezira_real **elements, int *n) { int i; JSObject *array = JSVAL_TO_OBJECT (val); JS_GetArrayLength (cxt, array, (jsuint *) n); *elements = (gezira_real *) malloc (*n * sizeof (gezira_real)); //printf ("at creation, elements is %p\n", *elements); for (i = 0; i < *n; i++) { double d; jsval val; JS_GetElement (cxt, array, i, &val); JS_ValueToNumber (cxt, val, &d); (*elements)[i] = GEZIRA_REAL (d); } }
void js_prop_set_from_jsval(JSContext *cx, prop_t *p, jsval value) { JSBool b; if(JSVAL_IS_INT(value)) { prop_set_int(p, JSVAL_TO_INT(value)); } else if(JSVAL_IS_BOOLEAN(value)) { prop_set_int(p, JSVAL_TO_BOOLEAN(value)); } else if(JSVAL_IS_NULL(value) || JSVAL_IS_VOID(value)) { prop_set_void(p); } else if(JSVAL_IS_DOUBLE(value)) { double d; if(JS_ValueToNumber(cx, value, &d)) prop_set_float(p, d); } else if(JS_HasInstance(cx, RichText, value, &b) && b) { JSObject *o = JSVAL_TO_OBJECT(value); jsval v2; if(!JS_EnterLocalRootScope(cx)) return; if(!JS_GetProperty(cx, o, "text", &v2)) { JS_LeaveLocalRootScope(cx); return; } prop_set_string_ex(p, NULL, JS_GetStringBytes(JS_ValueToString(cx, v2)), PROP_STR_RICH); JS_LeaveLocalRootScope(cx); } else if(JSVAL_IS_STRING(value)) { js_prop_from_str(cx, p, value); } 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_prop_from_str(cx, p, value); else js_prop_from_object(cx, obj, p); } else { prop_set_void(p); } }
JSBool js_cocos2dx_spine_SkeletonAnimation_addAnimation(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); JSBool ok = JS_TRUE; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, JS_FALSE, "js_cocos2dx_spine_SkeletonAnimation_addAnimation : Invalid Native Object"); if (argc == 3) { int arg0; const char* arg1; JSBool arg2; ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); ok &= JS_ValueToBoolean(cx, argv[2], &arg2); JSB_PRECONDITION2(ok, cx, JS_FALSE, "js_cocos2dx_spine_SkeletonAnimation_addAnimation : Error processing arguments"); spTrackEntry* ret = cobj->addAnimation(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR spTrackEntry*; JS_SET_RVAL(cx, vp, jsret); return JS_TRUE; } if (argc == 4) { int arg0; const char* arg1; JSBool arg2; double arg3; ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0); std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); ok &= JS_ValueToBoolean(cx, argv[2], &arg2); ok &= JS_ValueToNumber(cx, argv[3], &arg3); JSB_PRECONDITION2(ok, cx, JS_FALSE, "js_cocos2dx_spine_SkeletonAnimation_addAnimation : Error processing arguments"); spTrackEntry* ret = cobj->addAnimation(arg0, arg1, arg2, arg3); jsval jsret = JSVAL_NULL; #pragma warning NO CONVERSION FROM NATIVE FOR spTrackEntry*; JS_SET_RVAL(cx, vp, jsret); return JS_TRUE; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_addAnimation : wrong number of arguments: %d, was expecting %d", argc, 3); return JS_FALSE; }
JSBool js_cocos2dx_spine_SkeletonAnimation_update(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); JSBool ok = JS_TRUE; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, JS_FALSE, "js_cocos2dx_spine_SkeletonAnimation_update : Invalid Native Object"); if (argc == 1) { double arg0; ok &= JS_ValueToNumber(cx, argv[0], &arg0); JSB_PRECONDITION2(ok, cx, JS_FALSE, "js_cocos2dx_spine_SkeletonAnimation_update : Error processing arguments"); cobj->update(arg0); JS_SET_RVAL(cx, vp, JSVAL_VOID); return JS_TRUE; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_update : wrong number of arguments: %d, was expecting %d", argc, 1); return JS_FALSE; }
static JSBool Renderer_constructor (JSContext *cxt, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { double d; gezira_renderer *renderer = (gezira_renderer *) malloc (sizeof (gezira_renderer)); JS_SetPrivate (cxt, obj, renderer); renderer->router = gezira_renderer_router; /* FIXME hackety hack hack */ JS_ValueToNumber (cxt, argv[0], &d); renderer->pixmap.pixels = *((char **) (char *) &d); renderer->pixmap.width = JSVAL_TO_INT (argv[1]); renderer->pixmap.height = JSVAL_TO_INT (argv[2]); renderer->pixmap.stride = JSVAL_TO_INT (argv[3]); renderer->pixmap.bytes_per_pixel = JSVAL_TO_INT (argv[4]); *rval = OBJECT_TO_JSVAL (obj); return JS_TRUE; }
JSBool JsPointBinding::PropertySet(JSContext *context, JSObject *obj, jsid id, JSBool strict, jsval *val) { int propId = JSID_TO_INT(id); CCPoint *pPoint = static_cast<CCPoint*> (JS_GetPrivate(context, obj)); if (!pPoint) return JS_FALSE; double data; JS_ValueToNumber(context, *val, &data); switch (propId) { case X: pPoint->x = data; break; case Y: pPoint->y = data; break; default: break; } return JS_TRUE; }
static JSBool playMusic(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *) { // sound disabled? if (!Audio::audio) return JS_TRUE; if((argc<1)||(argc>3)) EJS_THROW_ERROR(cx,obj,"Between 1 and 3 arguments required"); char* ctype; size_t len; STRING_TO_CHARVEC(argv[0],ctype,len); jsdouble volume=1; JSBool repeat=JS_FALSE; if (argc>=2) if (!JS_ValueToNumber(cx,argv[1],&volume)) return JS_FALSE; if (argc>=3) if (!JS_ValueToBoolean(cx, argv[2],&repeat)) return JS_FALSE; Audio::audio->playMusic(ctype,len,volume,repeat==JS_TRUE); return JS_TRUE; }
void JavaScriptEngine::RunScript(const char *fileName) { char * scriptStr = LoadJsFile(fileName); if (scriptStr == NULL) { return; } int lineNumber = 0; JSObject *script = JS_CompileScript(globalContext, globalObject, scriptStr, strlen(scriptStr), fileName, lineNumber); delete[] scriptStr; if (script == NULL) { return; } jsval rval; JSBool status = JS_ExecuteScript(globalContext, globalObject, script, &rval); if (status == JS_FALSE) { if (JSVAL_IS_NULL(rval)) { LogInfo(TAG, "rval : (JSVAL_IS_NULL(rval)"); } else if ((JSVAL_IS_BOOLEAN(rval)) && (JS_FALSE == (JSVAL_TO_BOOLEAN( rval)))) { LogInfo(TAG, "rval : (return value is JS_FALSE"); } else if (JSVAL_IS_STRING(rval)) { JSString *str = JS_ValueToString(globalContext, rval); if (str == NULL) { LogInfo(TAG, "rval : return string is NULL"); } else { char * content = JS_EncodeString(globalContext, str); LogInfo(TAG, "rval : return string =\n%s\n", content); JS_free(globalContext, content); } } else if (JSVAL_IS_NUMBER(rval)) { double number; if (JS_FALSE == JS_ValueToNumber(globalContext, rval, &number)) { LogInfo(TAG, "rval : return number could not be converted"); } else { LogInfo(TAG, "rval : return number =\n%f", number); } } } }
JSBool WpositionVideo(JSContext *cx, uintN argc, jsval *vp) { //return the length of the video in seconds, as a float. double length; video *vid = (video*)JS_GetPrivate(cx,JSVAL_TO_OBJECT(JS_THIS(cx,vp))); if(argc > 0){ //we are setting the playback position if(JS_ValueToNumber(cx,JS_ARGV(cx,vp)[0], &length)){ if(vid->vb->setPositionVideo(vid,length)){ JS_SET_RVAL(cx,vp,JSVAL_TRUE); return JS_TRUE; } } } else { //Merely querying it. length = vid->vb->getPositionVideo(vid); if(length != -1){ JS_SET_RVAL(cx,vp,DOUBLE_TO_JSVAL(length)); return JS_TRUE; } } JS_SET_RVAL(cx,vp,JSVAL_NULL); return JS_TRUE; }
JSBool js_cocos2dx_spine_SkeletonAnimation_setMix(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); JSBool ok = JS_TRUE; JSObject *obj = JS_THIS_OBJECT(cx, vp); js_proxy_t *proxy = jsb_get_js_proxy(obj); spine::SkeletonAnimation* cobj = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, JS_FALSE, "js_cocos2dx_spine_SkeletonAnimation_setMix : Invalid Native Object"); if (argc == 3) { const char* arg0; const char* arg1; double arg2; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); ok &= JS_ValueToNumber(cx, argv[2], &arg2); JSB_PRECONDITION2(ok, cx, JS_FALSE, "js_cocos2dx_spine_SkeletonAnimation_setMix : Error processing arguments"); cobj->setMix(arg0, arg1, arg2); JS_SET_RVAL(cx, vp, JSVAL_VOID); return JS_TRUE; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_setMix : wrong number of arguments: %d, was expecting %d", argc, 3); return JS_FALSE; }
void js_prop_set_from_jsval(JSContext *cx, prop_t *p, jsval value, int recurse) { JSBool b; if(JSVAL_IS_INT(value)) { prop_set_int(p, JSVAL_TO_INT(value)); } else if(JSVAL_IS_BOOLEAN(value)) { prop_set_int(p, JSVAL_TO_BOOLEAN(value)); } else if(JSVAL_IS_DOUBLE(value)) { double d; if(JS_ValueToNumber(cx, value, &d)) prop_set_float(p, d); } else if(JS_HasInstance(cx, RichText, value, &b) && b) { JSObject *o = JSVAL_TO_OBJECT(value); jsval v2; if(!JS_EnterLocalRootScope(cx)) return; if(!JS_GetProperty(cx, o, "text", &v2)) { JS_LeaveLocalRootScope(cx); return; } prop_set_string_ex(p, NULL, JS_GetStringBytes(JS_ValueToString(cx, v2)), PROP_STR_RICH); JS_LeaveLocalRootScope(cx); } else if(JSVAL_IS_VOID(value) || JSVAL_IS_NULL(value)) { prop_set_void(p); } else if(recurse && JSVAL_IS_OBJECT(value)) { js_prop_from_object(cx, JSVAL_TO_OBJECT(value), p, recurse); } else { prop_set_string(p, JS_GetStringBytes(JS_ValueToString(cx, value))); } }
JSBool JSSphere::Constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { DOC_BEGIN("Constructs a sphere from center/radius, center/point on surface, from another sphere or an empty one."); DOC_PARAM("a sphere", "", DOC_TYPE_SPHERE); DOC_RESET; DOC_PARAM("center", "", DOC_TYPE_POINT3F); DOC_PARAM("radius", "", DOC_TYPE_FLOAT); DOC_RESET; DOC_PARAM("center", "", DOC_TYPE_POINT3F); DOC_PARAM("point on surface", "", DOC_TYPE_POINT3F); DOC_END; IF_NOISY2(AC_TRACE << "Constructor argc =" << argc << endl); if (JSA_GetClass(cx,obj) != Class()) { JS_ReportError(cx,"Constructor for %s bad object; did you forget a 'new'?",ClassName()); return JS_FALSE; } JSSphere * myNewObject = 0; JSSphere::NativeValuePtr myNewValue = JSSphere::NativeValuePtr(new dom::SimpleValue<asl::Sphere<Number> >(0)); asl::Sphere<Number> & myNewSphere = myNewValue->openWriteableValue(); // we close it only on success, otherwise we trash it anyway if (argc == 0) { // construct empty myNewObject=new JSSphere(myNewValue); } else { if (argc == 2) { JSObject * myObject = JSVector<asl::Point3<Number> >::Construct(cx, argv[0]); if (!myObject) { JS_ReportError(cx,"JSSphere::Constructor: first argument must be a normal vector of size 3",ClassName()); return JS_FALSE; } jsdouble myNumber; if (JS_ValueToNumber(cx,argv[1],&myNumber) && !JSDOUBLE_IS_NaN(myNumber)) { // construct from center/radius myNewSphere = asl::Sphere<Number>(JSVector<asl::Point3<Number> >::getNativeRef(cx,myObject), Number(myNumber)); } else { // construct from center/point on surface JSObject * myObject2 = JSVector<asl::Point3<Number> >::Construct(cx, argv[1]); if (!myObject2) { JS_ReportError(cx,"JSSphere::Constructor: second argument must be a distance number or point on the plane of size 3",ClassName()); return JS_FALSE; } myNewSphere = asl::Sphere<Number>(JSVector<asl::Point3<Number> >::getNativeRef(cx,myObject), JSVector<asl::Point3<Number> >::getNativeRef(cx,myObject2)); } myNewObject=new JSSphere(myNewValue); } else if (argc == 1) { // construct from one Sphere if (JSVAL_IS_VOID(argv[0])) { JS_ReportError(cx,"JSSphere::Constructor: bad argument #1 (undefined)"); return JS_FALSE; } JSObject * myArgument; if (!JS_ValueToObject(cx, argv[0], &myArgument)) { JS_ReportError(cx,"JSSphere::Constructor: bad argument type, Sphere expected"); return JS_FALSE; } if (JSA_GetClass(cx,myArgument) == Class()) { myNewSphere = getJSWrapper(cx, myArgument).getNative(); myNewObject=new JSSphere(myNewValue); } } else { JS_ReportError(cx,"Constructor for %s: bad number of arguments: expected 0,1 or 2, got %d",ClassName(), argc); return JS_FALSE; } } if (myNewObject) { JS_SetPrivate(cx,obj,myNewObject); myNewValue->closeWriteableValue(); return JS_TRUE; } JS_ReportError(cx,"JSSphere::Constructor: bad parameters"); return JS_FALSE; }
static JSBool setDash_func(JSContext *context, unsigned argc, jsval *vp) { JS::CallArgs argv = JS::CallArgsFromVp (argc, vp); JSObject *obj = JSVAL_TO_OBJECT(argv.thisv()); guint i; cairo_t *cr; JSObject *dashes; double offset; JSBool retval = JS_FALSE; guint len; GArray *dashes_c = NULL; if (!gjs_parse_call_args(context, "setDash", "of", argv, "dashes", &dashes, "offset", &offset)) return JS_FALSE; JS_AddObjectRoot(context, &dashes); if (!JS_IsArrayObject(context, dashes)) { gjs_throw(context, "dashes must be an array"); goto out; } if (!JS_GetArrayLength(context, dashes, &len)) { gjs_throw(context, "Can't get length of dashes"); goto out; } dashes_c = g_array_sized_new (FALSE, FALSE, sizeof(double), len); for (i = 0; i < len; ++i) { jsval elem; double b; elem = JSVAL_VOID; if (!JS_GetElement(context, dashes, i, &elem)) { goto out; } if (JSVAL_IS_VOID(elem)) continue; if (!JS_ValueToNumber(context, elem, &b)) goto out; if (b <= 0) { gjs_throw(context, "Dash value must be positive"); goto out; } g_array_append_val(dashes_c, b); } cr = gjs_cairo_context_get_context(context, obj); cairo_set_dash(cr, (double*)dashes_c->data, dashes_c->len, offset); argv.rval().set(JSVAL_VOID); retval = JS_TRUE; out: if (dashes_c != NULL) g_array_free (dashes_c, TRUE); JS_RemoveObjectRoot(context, &dashes); return retval; }
JSBool js_to_number(JSContext *cx, jsval v, double *dp) { return JS_ValueToNumber(cx, v, dp); }
static JSBool rpmseq_setprop(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp) { void * ptr = JS_GetInstancePrivate(cx, obj, &rpmseqClass, NULL); DB_SEQUENCE * seq = ptr; jsval idval; JS_IdToValue(cx, id, &idval); jsint tiny = JSVAL_TO_INT(idval); jsdouble d = 0; int ret; /* XXX the class has ptr == NULL, instances have ptr != NULL. */ if (ptr == NULL) return JS_TRUE; switch (tiny) { case _DEBUG: if (!JS_ValueToInt32(cx, *vp, &_debug)) break; break; case _CACHESIZE: { int32_t _i = 0; if (seq->api_internal != NULL || !JS_ValueToNumber(cx, *vp, &d)) { *vp = JSVAL_FALSE; break; } _i = d; ret = seq->set_cachesize(seq, _i); *vp = (!ret ? JSVAL_TRUE : JSVAL_FALSE); } break; case _FLAGS: { uint32_t _u = 0; if (seq->api_internal != NULL || !JS_ValueToNumber(cx, *vp, &d)) { *vp = JSVAL_FALSE; break; } _u = d; ret = seq->set_flags(seq, _u); *vp = (!ret ? JSVAL_TRUE : JSVAL_FALSE); } break; case _INITVAL: { db_seq_t _ival = 0; if (seq->api_internal != NULL || !JS_ValueToNumber(cx, *vp, &d)) { *vp = JSVAL_FALSE; break; } _ival = d; ret = seq->initial_value(seq, _ival); *vp = (!ret ? JSVAL_TRUE : JSVAL_FALSE); } break; case _RANGEMIN: case _RANGEMAX: { db_seq_t _min = 0; db_seq_t _max = 0; if (seq->api_internal != NULL || !JS_ValueToNumber(cx, *vp, &d)) { *vp = JSVAL_FALSE; break; } if ((ret = seq->get_range(seq, &_min, &_max)) != 0) { *vp = JSVAL_VOID; break; } switch (tiny) { case _RANGEMIN: _min = d; break; case _RANGEMAX: _max = d; break; } ret = seq->set_range(seq, _min, _max); *vp = (!ret ? JSVAL_TRUE : JSVAL_FALSE); } break; default: break; } return JS_TRUE; }
static JSBool gjs_value_to_g_value_internal(JSContext *context, jsval value, GValue *gvalue, gboolean no_copy) { GType gtype; gtype = G_VALUE_TYPE(gvalue); if (gtype == 0) { gtype = gjs_value_guess_g_type(context, value); if (gtype == G_TYPE_INVALID) { gjs_throw(context, "Could not guess unspecified GValue type"); return JS_FALSE; } gjs_debug_marshal(GJS_DEBUG_GCLOSURE, "Guessed GValue type %s from JS Value", g_type_name(gtype)); g_value_init(gvalue, gtype); } gjs_debug_marshal(GJS_DEBUG_GCLOSURE, "Converting jsval to gtype %s", g_type_name(gtype)); if (gtype == G_TYPE_STRING) { /* Don't use ValueToString since we don't want to just toString() * everything automatically */ if (JSVAL_IS_NULL(value)) { g_value_set_string(gvalue, NULL); } else if (JSVAL_IS_STRING(value)) { gchar *utf8_string; if (!gjs_string_to_utf8(context, value, &utf8_string)) return JS_FALSE; g_value_take_string(gvalue, utf8_string); } else { gjs_throw(context, "Wrong type %s; string expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_CHAR) { gint32 i; if (JS_ValueToInt32(context, value, &i) && i >= SCHAR_MIN && i <= SCHAR_MAX) { g_value_set_schar(gvalue, (signed char)i); } else { gjs_throw(context, "Wrong type %s; char expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_UCHAR) { guint16 i; if (JS_ValueToUint16(context, value, &i) && i <= UCHAR_MAX) { g_value_set_uchar(gvalue, (unsigned char)i); } else { gjs_throw(context, "Wrong type %s; unsigned char expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_INT) { gint32 i; if (JS_ValueToInt32(context, value, &i)) { g_value_set_int(gvalue, i); } else { gjs_throw(context, "Wrong type %s; integer expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_DOUBLE) { gdouble d; if (JS_ValueToNumber(context, value, &d)) { g_value_set_double(gvalue, d); } else { gjs_throw(context, "Wrong type %s; double expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_FLOAT) { gdouble d; if (JS_ValueToNumber(context, value, &d)) { g_value_set_float(gvalue, d); } else { gjs_throw(context, "Wrong type %s; float expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_UINT) { guint32 i; if (JS_ValueToECMAUint32(context, value, &i)) { g_value_set_uint(gvalue, i); } else { gjs_throw(context, "Wrong type %s; unsigned integer expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (gtype == G_TYPE_BOOLEAN) { JSBool b; /* JS_ValueToBoolean() pretty much always succeeds, * which is maybe surprising sometimes, but could * be handy also... */ if (JS_ValueToBoolean(context, value, &b)) { g_value_set_boolean(gvalue, b); } else { gjs_throw(context, "Wrong type %s; boolean expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (g_type_is_a(gtype, G_TYPE_OBJECT) || g_type_is_a(gtype, G_TYPE_INTERFACE)) { GObject *gobj; gobj = NULL; if (JSVAL_IS_NULL(value)) { /* nothing to do */ } else if (JSVAL_IS_OBJECT(value)) { JSObject *obj; obj = JSVAL_TO_OBJECT(value); if (!gjs_typecheck_object(context, obj, gtype, JS_TRUE)) return JS_FALSE; gobj = gjs_g_object_from_object(context, obj); } else { gjs_throw(context, "Wrong type %s; object %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } g_value_set_object(gvalue, gobj); } else if (gtype == G_TYPE_STRV) { if (JSVAL_IS_NULL(value)) { /* do nothing */ } else if (gjs_object_has_property(context, JSVAL_TO_OBJECT(value), "length")) { jsval length_value; guint32 length; if (!gjs_object_require_property(context, JSVAL_TO_OBJECT(value), NULL, "length", &length_value) || !JS_ValueToECMAUint32(context, length_value, &length)) { gjs_throw(context, "Wrong type %s; strv expected", gjs_get_type_name(value)); return JS_FALSE; } else { void *result; char **strv; if (!gjs_array_to_strv (context, value, length, &result)) return JS_FALSE; /* cast to strv in a separate step to avoid type-punning */ strv = result; g_value_take_boxed (gvalue, strv); } } else { gjs_throw(context, "Wrong type %s; strv expected", gjs_get_type_name(value)); return JS_FALSE; } } else if (g_type_is_a(gtype, G_TYPE_BOXED)) { void *gboxed; gboxed = NULL; if (JSVAL_IS_NULL(value)) { /* nothing to do */ } else if (JSVAL_IS_OBJECT(value)) { JSObject *obj; obj = JSVAL_TO_OBJECT(value); if (g_type_is_a(gtype, G_TYPE_ERROR)) { /* special case GError */ if (!gjs_typecheck_gerror(context, obj, JS_TRUE)) return JS_FALSE; gboxed = gjs_gerror_from_error(context, obj); } else { /* First try a union, if that fails, assume a boxed struct. Distinguishing which one is expected would require checking the associated GIBaseInfo, which is not necessary possible, if e.g. we see the GType without loading the typelib. */ if (gjs_typecheck_union(context, obj, NULL, gtype, JS_FALSE)) { gboxed = gjs_c_union_from_union(context, obj); } else { if (!gjs_typecheck_boxed(context, obj, NULL, gtype, JS_TRUE)) return JS_FALSE; gboxed = gjs_c_struct_from_boxed(context, obj); } } } else { gjs_throw(context, "Wrong type %s; boxed type %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } if (no_copy) g_value_set_static_boxed(gvalue, gboxed); else g_value_set_boxed(gvalue, gboxed); } else if (g_type_is_a(gtype, G_TYPE_VARIANT)) { GVariant *variant = NULL; if (JSVAL_IS_NULL(value)) { /* nothing to do */ } else if (JSVAL_IS_OBJECT(value)) { JSObject *obj = JSVAL_TO_OBJECT(value); if (!gjs_typecheck_boxed(context, obj, NULL, G_TYPE_VARIANT, JS_TRUE)) return JS_FALSE; variant = gjs_c_struct_from_boxed(context, obj); } else { gjs_throw(context, "Wrong type %s; boxed type %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } g_value_set_variant (gvalue, variant); } else if (g_type_is_a(gtype, G_TYPE_ENUM)) { gint64 value_int64; if (gjs_value_to_int64 (context, value, &value_int64)) { GEnumValue *v; /* See arg.c:_gjs_enum_to_int() */ v = g_enum_get_value(G_ENUM_CLASS(g_type_class_peek(gtype)), (int)value_int64); if (v == NULL) { gjs_throw(context, "%d is not a valid value for enumeration %s", JSVAL_TO_INT(value), g_type_name(gtype)); return JS_FALSE; } g_value_set_enum(gvalue, v->value); } else { gjs_throw(context, "Wrong type %s; enum %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } } else if (g_type_is_a(gtype, G_TYPE_FLAGS)) { gint64 value_int64; if (gjs_value_to_int64 (context, value, &value_int64)) { if (!_gjs_flags_value_is_valid(context, gtype, value_int64)) return JS_FALSE; /* See arg.c:_gjs_enum_to_int() */ g_value_set_flags(gvalue, (int)value_int64); } else { gjs_throw(context, "Wrong type %s; flags %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } } else if (g_type_is_a(gtype, G_TYPE_PARAM)) { void *gparam; gparam = NULL; if (JSVAL_IS_NULL(value)) { /* nothing to do */ } else if (JSVAL_IS_OBJECT(value)) { JSObject *obj; obj = JSVAL_TO_OBJECT(value); if (!gjs_typecheck_param(context, obj, gtype, JS_TRUE)) return JS_FALSE; gparam = gjs_g_param_from_param(context, obj); } else { gjs_throw(context, "Wrong type %s; param type %s expected", gjs_get_type_name(value), g_type_name(gtype)); return JS_FALSE; } g_value_set_param(gvalue, gparam); } else if (g_type_is_a(gtype, G_TYPE_GTYPE)) { GType type; if (!JSVAL_IS_OBJECT(value)) { gjs_throw(context, "Wrong type %s; expect a GType object", gjs_get_type_name(value)); return JS_FALSE; } type = gjs_gtype_get_actual_gtype(context, JSVAL_TO_OBJECT(value)); g_value_set_gtype(gvalue, type); } else if (g_type_is_a(gtype, G_TYPE_POINTER)) { if (JSVAL_IS_NULL(value)) { /* Nothing to do */ } else { gjs_throw(context, "Cannot convert non-null JS value to G_POINTER"); return JS_FALSE; } } else if (JSVAL_IS_NUMBER(value) && g_value_type_transformable(G_TYPE_INT, gtype)) { /* Only do this crazy gvalue transform stuff after we've * exhausted everything else. Adding this for * e.g. ClutterUnit. */ gint32 i; if (JS_ValueToInt32(context, value, &i)) { GValue int_value = { 0, }; g_value_init(&int_value, G_TYPE_INT); g_value_set_int(&int_value, i); g_value_transform(&int_value, gvalue); } else { gjs_throw(context, "Wrong type %s; integer expected", gjs_get_type_name(value)); return JS_FALSE; } } else { gjs_debug(GJS_DEBUG_GCLOSURE, "jsval is number %d gtype fundamental %d transformable to int %d from int %d", JSVAL_IS_NUMBER(value), G_TYPE_IS_FUNDAMENTAL(gtype), g_value_type_transformable(gtype, G_TYPE_INT), g_value_type_transformable(G_TYPE_INT, gtype)); gjs_throw(context, "Don't know how to convert JavaScript object to GType %s", g_type_name(gtype)); return JS_FALSE; } return JS_TRUE; }
JSBool js_cocos2dx_spine_SkeletonAnimation_createWithFile(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); JSBool ok = JS_TRUE; do { if (argc == 2) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } const char* arg1; std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } spine::SkeletonAnimation* ret = spine::SkeletonAnimation::createWithFile(arg0, arg1); jsval jsret = JSVAL_NULL; do { if (ret) { js_proxy_t *proxy = js_get_or_create_proxy<spine::SkeletonAnimation>(cx, (spine::SkeletonAnimation*)ret); jsret = OBJECT_TO_JSVAL(proxy->obj); } else { jsret = JSVAL_NULL; } } while (0); JS_SET_RVAL(cx, vp, jsret); return JS_TRUE; } } while (0); do { if (argc == 3) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } const char* arg1; std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } double arg2; ok &= JS_ValueToNumber(cx, argv[2], &arg2); if (!ok) { ok = JS_TRUE; break; } spine::SkeletonAnimation* ret = spine::SkeletonAnimation::createWithFile(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; do { if (ret) { js_proxy_t *proxy = js_get_or_create_proxy<spine::SkeletonAnimation>(cx, (spine::SkeletonAnimation*)ret); jsret = OBJECT_TO_JSVAL(proxy->obj); } else { jsret = JSVAL_NULL; } } while (0); JS_SET_RVAL(cx, vp, jsret); return JS_TRUE; } } while (0); do { if (argc == 2) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas*; if (!ok) { ok = JS_TRUE; break; } spine::SkeletonAnimation* ret = spine::SkeletonAnimation::createWithFile(arg0, arg1); jsval jsret = JSVAL_NULL; do { if (ret) { js_proxy_t *proxy = js_get_or_create_proxy<spine::SkeletonAnimation>(cx, (spine::SkeletonAnimation*)ret); jsret = OBJECT_TO_JSVAL(proxy->obj); } else { jsret = JSVAL_NULL; } } while (0); JS_SET_RVAL(cx, vp, jsret); return JS_TRUE; } } while (0); do { if (argc == 3) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas*; if (!ok) { ok = JS_TRUE; break; } double arg2; ok &= JS_ValueToNumber(cx, argv[2], &arg2); if (!ok) { ok = JS_TRUE; break; } spine::SkeletonAnimation* ret = spine::SkeletonAnimation::createWithFile(arg0, arg1, arg2); jsval jsret = JSVAL_NULL; do { if (ret) { js_proxy_t *proxy = js_get_or_create_proxy<spine::SkeletonAnimation>(cx, (spine::SkeletonAnimation*)ret); jsret = OBJECT_TO_JSVAL(proxy->obj); } else { jsret = JSVAL_NULL; } } while (0); JS_SET_RVAL(cx, vp, jsret); return JS_TRUE; } } while (0); JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_createWithFile : wrong number of arguments"); return JS_FALSE; }
JSBool TCP_read (JSContext *cx, JSObject *object, uintN argc, jsval *argv, jsval *rval) { int32 size; uint16 flags = 0; jsdouble timeout = -1; JS_BeginRequest(cx); if (argc < 1) { JS_ReportError(cx, "Not enough parameters."); JS_EndRequest(cx); return JS_FALSE; } switch (argc) { case 3: JS_ValueToNumber(cx, argv[2], &timeout); case 2: JS_ValueToUint16(cx, argv[1], &flags); case 1: JS_ValueToInt32(cx, argv[0], &size); } TCPInformation* data = (TCPInformation*) JS_GetPrivate(cx, object); jsval jsConnected; JS_GetProperty(cx, object, "connected", &jsConnected); JSBool connected; JS_ValueToBoolean(cx, jsConnected, &connected); if (!connected) { JS_ReportError(cx, "The socket isn't connected."); JS_LeaveLocalRootScope(cx); JS_EndRequest(cx); return JS_FALSE; } char* string = (char*) JS_malloc(cx, size*sizeof(char)); jsrefcount req = JS_SuspendRequest(cx); int32 offset = 0; int32 received = 0; while (offset < size) { received = PR_Recv(data->socket, (string+offset), (size-offset)*sizeof(char), flags, (timeout == -1) ? PR_INTERVAL_NO_TIMEOUT : PR_MicrosecondsToInterval(timeout*1000000)); if (received == -1) { break; } offset += received; } JS_ResumeRequest(cx, req); if (received < 0) { switch (PR_GetError()) { default: JS_ReportError(cx, "Something went wrong."); break; } JS_EndRequest(cx); return JS_FALSE; } *rval = STRING_TO_JSVAL(JS_NewString(cx, string, offset)); JS_EndRequest(cx); return JS_TRUE; }
static JSBool SMJS_FUNCTION(upnp_action_send_reply) { SMJS_OBJ SMJS_ARGS GPAC_GenericDevice *device = (GPAC_GenericDevice *)SMJS_GET_PRIVATE(c, obj); if (!device) return JS_FALSE; if (argc && JSVAL_IS_OBJECT(argv[0]) ) { JSObject *list = JSVAL_TO_OBJECT(argv[0]); u32 i, count; JS_GetArrayLength(c, list, (jsuint*) &count); GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Calling response %s(", (char *) device->act_ref->GetActionDesc().GetName())); i=0; while (i+2<=count) { jsval an_arg; NPT_Result res; char *param_val, *_param_val = NULL; char szParamVal[1024]; JS_GetElement(c, list, (jsint) i, &an_arg); char *param_name = SMJS_CHARS(c, an_arg); JS_GetElement(c, list, (jsint) i+1, &an_arg); param_val = (char*)""; if (JSVAL_IS_STRING(an_arg)) { param_val = _param_val = SMJS_CHARS(c, an_arg); } else if (JSVAL_IS_BOOLEAN(an_arg)) { param_val = (char *) ((JSVAL_TO_BOOLEAN(an_arg) == JS_TRUE) ? "true" : "false"); } else if (JSVAL_IS_INT(argv[1])) { sprintf(szParamVal, "%d", JSVAL_TO_INT(an_arg)); param_val = szParamVal; } else if (JSVAL_IS_NUMBER(an_arg)) { jsdouble v; JS_ValueToNumber(c, an_arg, &v); sprintf(szParamVal, "%g", v); param_val = szParamVal; } if (!param_name || !param_val) res = NPT_FAILURE; else { GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, (" %s(%s)", param_name, param_val)); res = device->act_ref->SetArgumentValue(param_name, param_val); } SMJS_FREE(c, param_name); SMJS_FREE(c, _param_val); if (res != NPT_SUCCESS) return JS_FALSE; i+=2; } GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, (" )\n")); } //notify we are ready if (device->m_pSema) { gf_sema_notify(device->m_pSema, 1); } return JS_TRUE; }
static JSBool SMJS_FUNCTION(upnp_service_call_action) { GPAC_ActionUDTA *act_udta = NULL; char *action_name = NULL; SMJS_OBJ SMJS_ARGS GPAC_ServiceItem *service = (GPAC_ServiceItem *)SMJS_GET_PRIVATE(c, obj); if (!service || !argc || !JSVAL_IS_STRING(argv[0]) ) return JS_FALSE; action_name = SMJS_CHARS(c, argv[0]); PLT_ActionDesc* action_desc = service->m_service->FindActionDesc(action_name); SMJS_FREE(c, action_name); if (action_desc == NULL) return JS_FALSE; PLT_ActionReference action; NPT_CHECK_SEVERE( service->m_device->m_pUPnP->m_pGenericController->m_CtrlPoint->CreateAction( service->m_device->m_device, service->m_service->GetServiceType(), action_name, action) ); if ((argc>=2) && JSVAL_IS_OBJECT(argv[1])) { JSObject *list = JSVAL_TO_OBJECT(argv[1]); u32 i, count; JS_GetArrayLength(c, list, (jsuint*) &count); GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Calling %s(", action_name)); i=0; while (i+2<=count) { NPT_Result res; jsval an_arg; char *param_val, *_param_val = NULL; char szParamVal[1024]; JS_GetElement(c, list, (jsint) i, &an_arg); char *param_name = SMJS_CHARS(c, an_arg); JS_GetElement(c, list, (jsint) i+1, &an_arg); param_val = (char*)""; if (JSVAL_IS_STRING(an_arg)) { param_val = _param_val = SMJS_CHARS(c, an_arg); } else if (JSVAL_IS_BOOLEAN(an_arg)) { param_val = (char *) ((JSVAL_TO_BOOLEAN(an_arg) == JS_TRUE) ? "true" : "false"); } else if (JSVAL_IS_INT(argv[1])) { sprintf(szParamVal, "%d", JSVAL_TO_INT(an_arg)); param_val = szParamVal; } else if (JSVAL_IS_NUMBER(an_arg)) { jsdouble v; JS_ValueToNumber(c, an_arg, &v); sprintf(szParamVal, "%g", v); param_val = szParamVal; } if (!param_name || !param_val) res = NPT_FAILURE; else { GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, (" %s(%s)", param_name, param_val)); res = action->SetArgumentValue(param_name, param_val); } SMJS_FREE(c, param_name); SMJS_FREE(c, _param_val); if (res != NPT_SUCCESS) return JS_FALSE; i+=2; } GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, (" )\n")); } if ((argc==3) && JSVAL_IS_OBJECT(argv[2])) { act_udta = new GPAC_ActionUDTA(); act_udta->udta = argv[2]; gf_js_add_root(c, &act_udta->udta, GF_JSGC_VAL); } service->m_device->m_pUPnP->m_pGenericController->m_CtrlPoint->InvokeAction(action, act_udta); return JS_TRUE; }
/** * gjs_parse_args: * @context: * @function_name: The name of the function being called * @format: Printf-like format specifier containing the expected arguments * @argc: Number of JavaScript arguments * @argv: JavaScript argument array * @Varargs: for each character in @format, a pair of a char * which is the name * of the argument, and a pointer to a location to store the value. The type of * value stored depends on the format character, as described below. * * This function is inspired by Python's PyArg_ParseTuple for those * familiar with it. It takes a format specifier which gives the * types of the expected arguments, and a list of argument names and * value location pairs. The currently accepted format specifiers are: * * s: A string, converted into UTF-8 * z: Like 's', but may be null in JavaScript (which appears as NULL in C) * F: A string, converted into "filename encoding" (i.e. active locale) * i: A number, will be converted to a C "gint32" * u: A number, converted into a C "guint32" * o: A JavaScript object, as a "JSObject *" * * The '|' character introduces optional arguments. All format specifiers * after a '|' when not specified, do not cause any changes in the C * value location. */ JSBool gjs_parse_args (JSContext *context, const char *function_name, const char *format, uintN argc, jsval *argv, ...) { guint i; const char *fmt_iter; va_list args; GError *arg_error = NULL; guint n_unwind = 0; #define MAX_UNWIND_STRINGS 16 gpointer unwind_strings[MAX_UNWIND_STRINGS]; guint n_required; guint n_total; guint consumed_args; JS_BeginRequest(context); va_start (args, argv); /* Check for optional argument specifier */ fmt_iter = strchr (format, '|'); if (fmt_iter) { /* Be sure there's not another '|' */ g_return_val_if_fail (strchr (fmt_iter + 1, '|') == NULL, JS_FALSE); n_required = fmt_iter - format; n_total = n_required + strlen (fmt_iter + 1); } else { n_required = n_total = strlen (format); } if (argc < n_required || argc > n_total) { if (n_required == n_total) { gjs_throw(context, "Error invoking %s: Expected %d arguments, got %d", function_name, n_required, argc); } else { gjs_throw(context, "Error invoking %s: Expected minimum %d arguments (and %d optional), got %d", function_name, n_required, n_total - n_required, argc); } goto error_unwind; } /* We have 3 iteration variables here. * @i: The current integer position in fmt_args * @fmt_iter: A pointer to the character in fmt_args * @consumed_args: How many arguments we've taken from argv * * consumed_args can currently be different from 'i' because of the '|' character. */ for (i = 0, consumed_args = 0, fmt_iter = format; *fmt_iter; fmt_iter++, i++) { const char *argname; gpointer arg_location; jsval js_value; const char *arg_error_message = NULL; if (*fmt_iter == '|') continue; if (consumed_args == argc) { break; } argname = va_arg (args, char *); arg_location = va_arg (args, gpointer); g_return_val_if_fail (argname != NULL, JS_FALSE); g_return_val_if_fail (arg_location != NULL, JS_FALSE); js_value = argv[consumed_args]; switch (*fmt_iter) { case 'o': { if (!JSVAL_IS_OBJECT(js_value)) { arg_error_message = "Not an object"; } else { JSObject **arg = arg_location; *arg = JSVAL_TO_OBJECT(js_value); } } break; case 's': case 'z': { char **arg = arg_location; if (*fmt_iter == 'z' && JSVAL_IS_NULL(js_value)) { *arg = NULL; } else { if (gjs_try_string_to_utf8 (context, js_value, arg, &arg_error)) { unwind_strings[n_unwind++] = *arg; g_assert(n_unwind < MAX_UNWIND_STRINGS); } } } break; case 'F': { char **arg = arg_location; if (gjs_try_string_to_filename (context, js_value, arg, &arg_error)) { unwind_strings[n_unwind++] = *arg; g_assert(n_unwind < MAX_UNWIND_STRINGS); } } break; case 'i': { if (!JS_ValueToInt32(context, js_value, (gint32*) arg_location)) { /* Our error message is going to be more useful */ JS_ClearPendingException(context); arg_error_message = "Couldn't convert to integer"; } } break; case 'u': { gdouble num; if (!JS_ValueToNumber(context, js_value, &num)) { /* Our error message is going to be more useful */ JS_ClearPendingException(context); arg_error_message = "Couldn't convert to unsigned integer"; } else if (num > G_MAXUINT32 || num < 0) { arg_error_message = "Value is out of range"; } else { *((guint32*) arg_location) = num; } } break; case 'f': { double num; if (!JS_ValueToNumber(context, js_value, &num)) { /* Our error message is going to be more useful */ JS_ClearPendingException(context); arg_error_message = "Couldn't convert to double"; } else { *((double*) arg_location) = num; } } break; default: g_assert_not_reached (); } if (arg_error != NULL) arg_error_message = arg_error->message; if (arg_error_message != NULL) { gjs_throw(context, "Error invoking %s, at argument %d (%s): %s", function_name, consumed_args+1, argname, arg_error_message); g_clear_error (&arg_error); goto error_unwind; } consumed_args++; } va_end (args); JS_EndRequest(context); return JS_TRUE; error_unwind: va_end (args); /* We still own the strings in the error case, free any we converted */ for (i = 0; i < n_unwind; i++) { g_free (unwind_strings[i]); } JS_EndRequest(context); return JS_FALSE; }
JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsid id, JSBool UNUSED(strict), jsval* vp) { IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, obj, &JSI_IGUIObject::JSI_class, NULL); if (!e) return JS_FALSE; jsval idval; if (!JS_IdToValue(cx, id, &idval)) return JS_FALSE; std::string propName; if (!ScriptInterface::FromJSVal(cx, idval, propName)) return JS_FALSE; if (propName == "name") { std::string value; if (!ScriptInterface::FromJSVal(cx, *vp, value)) return JS_FALSE; e->SetName(value); return JS_TRUE; } // Use onWhatever to set event handlers if (propName.substr(0, 2) == "on") { if (!JSVAL_IS_OBJECT(*vp) || !JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(*vp))) { JS_ReportError(cx, "on- event-handlers must be functions"); return JS_FALSE; } CStr eventName (CStr(propName.substr(2)).LowerCase()); e->SetScriptHandler(eventName, JSVAL_TO_OBJECT(*vp)); return JS_TRUE; } // Retrieve the setting's type (and make sure it actually exists) EGUISettingType Type; if (e->GetSettingType(propName, Type) != PSRETURN_OK) { JS_ReportError(cx, "Invalid setting '%s'", propName.c_str()); return JS_TRUE; } switch (Type) { case GUIST_CStr: { std::string value; if (!ScriptInterface::FromJSVal(cx, *vp, value)) return JS_FALSE; GUI<CStr>::SetSetting(e, propName, value); break; } case GUIST_CStrW: { std::wstring value; if (!ScriptInterface::FromJSVal(cx, *vp, value)) return JS_FALSE; GUI<CStrW>::SetSetting(e, propName, value); break; } case GUIST_CGUISpriteInstance: { std::string value; if (!ScriptInterface::FromJSVal(cx, *vp, value)) return JS_FALSE; GUI<CGUISpriteInstance>::SetSetting(e, propName, CGUISpriteInstance(value)); break; } case GUIST_CGUIString: { std::wstring value; if (!ScriptInterface::FromJSVal(cx, *vp, value)) return JS_FALSE; CGUIString str; str.SetValue(value); GUI<CGUIString>::SetSetting(e, propName, str); break; } case GUIST_EAlign: { std::string value; if (!ScriptInterface::FromJSVal(cx, *vp, value)) return JS_FALSE; EAlign a; if (value == "left") a = EAlign_Left; else if (value == "right") a = EAlign_Right; else if (value == "center" || value == "centre") a = EAlign_Center; else { JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')"); return JS_FALSE; } GUI<EAlign>::SetSetting(e, propName, a); break; } case GUIST_EVAlign: { std::string value; if (!ScriptInterface::FromJSVal(cx, *vp, value)) return JS_FALSE; EVAlign a; if (value == "top") a = EVAlign_Top; else if (value == "bottom") a = EVAlign_Bottom; else if (value == "center" || value == "centre") a = EVAlign_Center; else { JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')"); return JS_FALSE; } GUI<EVAlign>::SetSetting(e, propName, a); break; } case GUIST_int: { int32 value; if (JS_ValueToInt32(cx, *vp, &value) == JS_TRUE) GUI<int>::SetSetting(e, propName, value); else { JS_ReportError(cx, "Cannot convert value to int"); return JS_FALSE; } break; } case GUIST_float: { jsdouble value; if (JS_ValueToNumber(cx, *vp, &value) == JS_TRUE) GUI<float>::SetSetting(e, propName, (float)value); else { JS_ReportError(cx, "Cannot convert value to float"); return JS_FALSE; } break; } case GUIST_bool: { JSBool value; if (JS_ValueToBoolean(cx, *vp, &value) == JS_TRUE) GUI<bool>::SetSetting(e, propName, value||0); // ||0 to avoid int-to-bool compiler warnings else { JS_ReportError(cx, "Cannot convert value to bool"); return JS_FALSE; } break; } case GUIST_CClientArea: { if (JSVAL_IS_STRING(*vp)) { std::wstring value; if (!ScriptInterface::FromJSVal(cx, *vp, value)) return JS_FALSE; if (e->SetSetting(propName, value) != PSRETURN_OK) { JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); return JS_FALSE; } } else if (JSVAL_IS_OBJECT(*vp) && JS_InstanceOf(cx, JSVAL_TO_OBJECT(*vp), &JSI_GUISize::JSI_class, NULL)) { CClientArea area; GUI<CClientArea>::GetSetting(e, propName, area); JSObject* obj = JSVAL_TO_OBJECT(*vp); #define P(x, y, z) area.x.y = (float)g_ScriptingHost.GetObjectProperty_Double(obj, #z) P(pixel, left, left); P(pixel, top, top); P(pixel, right, right); P(pixel, bottom, bottom); P(percent, left, rleft); P(percent, top, rtop); P(percent, right, rright); P(percent, bottom, rbottom); #undef P GUI<CClientArea>::SetSetting(e, propName, area); } else { JS_ReportError(cx, "Size only accepts strings or GUISize objects"); return JS_FALSE; } break; } case GUIST_CColor: { if (JSVAL_IS_STRING(*vp)) { std::wstring value; if (!ScriptInterface::FromJSVal(cx, *vp, value)) return JS_FALSE; if (e->SetSetting(propName, value) != PSRETURN_OK) { JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); return JS_FALSE; } } else if (JSVAL_IS_OBJECT(*vp) && JS_InstanceOf(cx, JSVAL_TO_OBJECT(*vp), &JSI_GUIColor::JSI_class, NULL)) { CColor colour; JSObject* obj = JSVAL_TO_OBJECT(*vp); jsval t; double s; #define PROP(x) JS_GetProperty(cx, obj, #x, &t); \ JS_ValueToNumber(cx, t, &s); \ colour.x = (float)s PROP(r); PROP(g); PROP(b); PROP(a); #undef PROP GUI<CColor>::SetSetting(e, propName, colour); } else { JS_ReportError(cx, "Color only accepts strings or GUIColor objects"); return JS_FALSE; } break; } case GUIST_CGUIList: { JSObject* obj = JSVAL_TO_OBJECT(*vp); jsuint length; if (JSVAL_IS_OBJECT(*vp) && JS_GetArrayLength(cx, obj, &length) == JS_TRUE) { CGUIList list; for (int i=0; i<(int)length; ++i) { jsval element; if (! JS_GetElement(cx, obj, i, &element)) { JS_ReportError(cx, "Failed to get list element"); return JS_FALSE; } std::wstring value; if (!ScriptInterface::FromJSVal(cx, element, value)) return JS_FALSE; CGUIString str; str.SetValue(value); list.m_Items.push_back(str); } GUI<CGUIList>::SetSetting(e, propName, list); } else { JS_ReportError(cx, "List only accepts a GUIList object"); return JS_FALSE; } break; } // TODO Gee: (2004-09-01) EAlign and EVAlign too. default: JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str()); break; } return !JS_IsExceptionPending(cx); }
/* * Convert a JS value to an instance of java.lang.Object or one of its subclasses, * performing any necessary type coercion. If non-trivial coercion is required, * the cost value is incremented. If the java_value pass-by-reference argument * is non-NULL, the resulting Java value is stored there. * * Returns JS_TRUE if the conversion is possible, JS_FALSE otherwise */ JSBool jsj_ConvertJSValueToJavaObject(JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignature *signature, int *cost, jobject *java_value, JSBool *is_local_refp) { JSString *jsstr; jclass target_java_class; JS_ASSERT(IS_REFERENCE_TYPE(signature->type)); /* Initialize to default case, in which no new Java object is synthesized to perform the conversion and, therefore, no JNI local references are being held. */ *is_local_refp = JS_FALSE; /* Get the Java type of the target value */ target_java_class = signature->java_class; if (JSVAL_IS_OBJECT(v)) { JSObject *js_obj = JSVAL_TO_OBJECT(v); /* JS null is always assignable to a Java object */ if (!js_obj) { if (java_value) *java_value = NULL; return JS_TRUE; } if (JS_InstanceOf(cx, js_obj, &JavaObject_class, 0) || JS_InstanceOf(cx, js_obj, &JavaArray_class, 0)) { /* The source value is a Java object wrapped inside a JavaScript object. Unwrap the JS object and return the original Java object if it's class makes it assignment-compatible with the target class using Java's assignability rules. */ JavaObjectWrapper *java_wrapper = JS_GetPrivate(cx, js_obj); jobject java_obj = java_wrapper->java_obj; if ((*jEnv)->IsInstanceOf(jEnv, java_obj, target_java_class)) { if (java_value) *java_value = java_obj; return JS_TRUE; } /* Fall through, to attempt conversion to a Java string */ } else if (JS_InstanceOf(cx, js_obj, &JavaClass_class, 0)) { /* We're dealing with the reflection of a Java class */ JavaClassDescriptor *java_class_descriptor = JS_GetPrivate(cx, js_obj); /* Check if target type is java.lang.Class class */ if ((*jEnv)->IsAssignableFrom(jEnv, jlClass, target_java_class)) { if (java_value) *java_value = java_class_descriptor->java_class; return JS_TRUE; } /* Check if target type is netscape.javascript.JSObject wrapper class */ if (convert_js_obj_to_JSObject_wrapper(cx, jEnv, js_obj, signature, cost, java_value)) { if (java_value && *java_value) *is_local_refp = JS_TRUE; return JS_TRUE; } /* Fall through, to attempt conversion to a Java string */ } else if (JS_InstanceOf(cx, js_obj, &JavaMember_class, 0)) { if (!JS_ConvertValue(cx, v, JSTYPE_OBJECT, &v)) return JS_FALSE; return jsj_ConvertJSValueToJavaObject(cx, jEnv, v, signature, cost, java_value, is_local_refp); /* JS Arrays are converted, element by element, to Java arrays */ } else if (JS_IsArrayObject(cx, js_obj) && (signature->type == JAVA_SIGNATURE_ARRAY)) { if (convert_js_array_to_java_array(cx, jEnv, js_obj, signature, java_value)) { if (java_value && *java_value) *is_local_refp = JS_TRUE; return JS_TRUE; } return JS_FALSE; } else { /* Otherwise, see if the target type is the netscape.javascript.JSObject wrapper class or one of its subclasses, in which case a reference is passed to the original JS object by wrapping it inside an instance of netscape.javascript.JSObject */ if (convert_js_obj_to_JSObject_wrapper(cx, jEnv, js_obj, signature, cost, java_value)) { if (java_value && *java_value) *is_local_refp = JS_TRUE; return JS_TRUE; } /* Fall through, to attempt conversion to a Java string */ } } else if (JSVAL_IS_NUMBER(v)) { /* JS numbers, integral or not, can be converted to instances of java.lang.Double */ if ((*jEnv)->IsAssignableFrom(jEnv, jlDouble, target_java_class)) { if (java_value) { jsdouble d; if (!JS_ValueToNumber(cx, v, &d)) goto conversion_error; *java_value = (*jEnv)->NewObject(jEnv, jlDouble, jlDouble_Double, d); if (*java_value) { *is_local_refp = JS_TRUE; } else { jsj_UnexpectedJavaError(cx, jEnv, "Couldn't construct instance of java.lang.Double"); return JS_FALSE; } } return JS_TRUE; } /* Fall through, to attempt conversion to a java.lang.String ... */ } else if (JSVAL_IS_BOOLEAN(v)) { /* JS boolean values can be converted to instances of java.lang.Boolean */ if ((*jEnv)->IsAssignableFrom(jEnv, jlBoolean, target_java_class)) { if (java_value) { JSBool b; if (!JS_ValueToBoolean(cx, v, &b)) goto conversion_error; *java_value = (*jEnv)->NewObject(jEnv, jlBoolean, jlBoolean_Boolean, b); if (*java_value) { *is_local_refp = JS_TRUE; } else { jsj_UnexpectedJavaError(cx, jEnv, "Couldn't construct instance " "of java.lang.Boolean"); return JS_FALSE; } } return JS_TRUE; } /* Fall through, to attempt conversion to a java.lang.String ... */ } /* If the source JS type is either a string or undefined, or if no conversion is possible from a number, boolean or JS object, see if the target type is java.lang.String */ if ((*jEnv)->IsAssignableFrom(jEnv, jlString, target_java_class)) { /* Convert to JS string, if necessary, and then to a Java Unicode string */ jsstr = JS_ValueToString(cx, v); if (jsstr) { if (java_value) { *java_value = jsj_ConvertJSStringToJavaString(cx, jEnv, jsstr); if (*java_value) { *is_local_refp = JS_TRUE; } else { return JS_FALSE; } } return JS_TRUE; } } conversion_error: return JS_FALSE; }
JSBool js_cocos2dx_spine_SkeletonAnimation_constructor(JSContext *cx, uint32_t argc, jsval *vp) { jsval *argv = JS_ARGV(cx, vp); JSBool ok = JS_TRUE; JSObject *obj = NULL; spine::SkeletonAnimation* cobj = NULL; do { if (argc == 2) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas*; if (!ok) { ok = JS_TRUE; break; } cobj = new spine::SkeletonAnimation(arg0, arg1); cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* proxy = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &proxy->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 3) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } spAtlas* arg1; #pragma warning NO CONVERSION TO NATIVE FOR spAtlas*; if (!ok) { ok = JS_TRUE; break; } double arg2; ok &= JS_ValueToNumber(cx, argv[2], &arg2); if (!ok) { ok = JS_TRUE; break; } cobj = new spine::SkeletonAnimation(arg0, arg1, arg2); cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* proxy = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &proxy->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 1) { spSkeletonData* arg0; #pragma warning NO CONVERSION TO NATIVE FOR spSkeletonData*; if (!ok) { ok = JS_TRUE; break; } cobj = new spine::SkeletonAnimation(arg0); cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* proxy = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &proxy->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 2) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } const char* arg1; std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } cobj = new spine::SkeletonAnimation(arg0, arg1); cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* proxy = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &proxy->obj, "spine::SkeletonAnimation"); } } while(0); do { if (argc == 3) { const char* arg0; std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } const char* arg1; std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str(); if (!ok) { ok = JS_TRUE; break; } double arg2; ok &= JS_ValueToNumber(cx, argv[2], &arg2); if (!ok) { ok = JS_TRUE; break; } cobj = new spine::SkeletonAnimation(arg0, arg1, arg2); cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<spine::SkeletonAnimation> 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."); obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); js_proxy_t* proxy = jsb_new_proxy(cobj, obj); JS_AddNamedObjectRoot(cx, &proxy->obj, "spine::SkeletonAnimation"); } } while(0); if (cobj) { JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); return JS_TRUE; } JS_ReportError(cx, "js_cocos2dx_spine_SkeletonAnimation_constructor : wrong number of arguments"); return JS_FALSE; }
int runJS(char* script) { LOGD("runJS"); // LOGD("script :\n%s", script); /* Create a JS runtime. */ JSRuntime *rt = JS_NewRuntime(8L * 1024L * 1024L); if (rt == NULL) { LOGD("(rt == NULL)"); return 1; } /* Create a context. */ JSContext *cx = JS_NewContext(rt, 8192); if (cx == NULL) { LOGD("(cx == NULL)"); return 1; } JS_SetOptions(cx, JSOPTION_VAROBJFIX); JS_SetVersion(cx, JSVERSION_LATEST); JS_SetErrorReporter(cx, jsbindings::reportError); /* Create the global object in a new compartment. */ JSObject *global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL); if (global == NULL) { LOGD("(global == NULL)"); return 1; } // Populate the global object with the standard globals, // like Object and Array. if (!JS_InitStandardClasses(cx, global)) { LOGD("(!JS_InitStandardClasses(cx, global))"); return 1; } const char *filename = NULL; int lineno = 0; jsval rval; JSBool evaluatedOK = JS_EvaluateScript(cx, global, script, strlen(script), filename, lineno, &rval); if (JS_FALSE == evaluatedOK) { LOGD("evaluatedOK == JS_FALSE)"); // return 1; } else { if (JSVAL_IS_NULL(rval)) { LOGD("rval : (JSVAL_IS_NULL(rval)"); // return 1; } else if ((JSVAL_IS_BOOLEAN(rval)) && (JS_FALSE == (JSVAL_TO_BOOLEAN(rval)))) { LOGD("rval : (return value is JS_FALSE"); // return 1; } else if (JSVAL_IS_STRING(rval)) { JSString *str = JS_ValueToString(cx, rval); if (NULL == str) { LOGD("rval : return string is NULL"); } else { LOGD("rval : return string =\n%s\n", JS_EncodeString(cx, str)); } } else if (JSVAL_IS_NUMBER(rval)) { double number; if (JS_FALSE == JS_ValueToNumber(cx, rval, &number)) { LOGD("rval : return number could not be converted"); } else { LOGD("rval : return number =\n%f", number); } } } // Cleanup JS_DestroyContext(cx); JS_DestroyRuntime(rt); JS_ShutDown(); LOGD("runJS done."); return 0; }
/* void takePicture (in nsICameraTakePictureCallback onSuccess, [optional] in nsICameraErrorCallback onError); */ NS_IMETHODIMP nsCameraControl::TakePicture(nsICameraPictureOptions *aOptions, nsICameraTakePictureCallback *onSuccess, nsICameraErrorCallback *onError, JSContext* cx) { PRUint32 width = 0; PRUint32 height = 0; PRInt32 rotation = 0; double latitude = 0; double longitude = 0; double altitude = 0; double timestamp = 0; bool latitudeSet = false; bool longitudeSet = false; bool altitudeSet = false; bool timestampSet = false; NS_ENSURE_TRUE(onSuccess, NS_ERROR_INVALID_ARG); NS_ENSURE_TRUE(aOptions, NS_ERROR_INVALID_ARG); jsval pictureSize; nsresult rv = aOptions->GetPictureSize(&pictureSize); NS_ENSURE_SUCCESS(rv, rv); if (pictureSize.isObject()) { JSObject* options = JSVAL_TO_OBJECT(pictureSize); jsval v; if (JS_GetProperty(cx, options, "width", &v)) { if (JSVAL_IS_INT(v)) { width = JSVAL_TO_INT(v); } } if (JS_GetProperty(cx, options, "height", &v)) { if (JSVAL_IS_INT(v)) { height = JSVAL_TO_INT(v); } } } nsString fileFormat; rv = aOptions->GetFileFormat(fileFormat); NS_ENSURE_SUCCESS(rv, rv); rv = aOptions->GetRotation(&rotation); NS_ENSURE_SUCCESS(rv, rv); jsval position; rv = aOptions->GetPosition(&position); NS_ENSURE_SUCCESS(rv, rv); if (position.isObject()) { JSObject* options = JSVAL_TO_OBJECT(position); jsval v; if (JS_GetProperty(cx, options, "latitude", &v)) { if (JSVAL_IS_NUMBER(v)) { if (JS_ValueToNumber(cx, v, &latitude)) { latitudeSet = true; } } } if (JS_GetProperty(cx, options, "longitude", &v)) { if (JSVAL_IS_NUMBER(v)) { if (JS_ValueToNumber(cx, v, &longitude)) { longitudeSet = true; } } } if (JS_GetProperty(cx, options, "altitude", &v)) { if (JSVAL_IS_NUMBER(v)) { if (JS_ValueToNumber(cx, v, &altitude)) { altitudeSet = true; } } } if (JS_GetProperty(cx, options, "timestamp", &v)) { if (JSVAL_IS_NUMBER(v)) { if (JS_ValueToNumber(cx, v, ×tamp)) { timestampSet = true; } } } } nsCOMPtr<nsIRunnable> takePictureTask = new TakePictureTask(this, width, height, rotation, fileFormat, latitude, latitudeSet, longitude, longitudeSet, altitude, altitudeSet, timestamp, timestampSet, onSuccess, onError); mCameraThread->Dispatch(takePictureTask, NS_DISPATCH_NORMAL); return NS_OK; }