static inline void build_frame(JSContext *cx, JSObject *target, unsigned argc, jsval *vp, void (*next)(view_animation *, anim_frame *, unsigned int, unsigned int)) { LOGFN("build_frame"); JSObject *thiz = JSVAL_TO_OBJECT(JS_THIS(cx, vp)); view_animation *anim = (view_animation*)JS_GetPrivate(thiz); anim_frame *frame = anim_frame_get(); // TODO: what if these defaults change? it probably won't... int32_t duration = 500; int32_t transition = 0; if (JS_ObjectIsFunction(cx, target)) { duration = 0; build_func_frame(frame, target); } else { build_style_frame(frame, target); } jsval *vals = JS_ARGV(cx, vp); if (argc > 1) { duration = JSValToInt32(cx, vals[1], duration); if (argc > 2) { transition = JSValToInt32(cx, vals[2], transition); } } next(anim, frame, duration, transition); LOGFN("end build_frame"); }
JSBool WvideoVol(JSContext *cx, uintN argc, jsval *vp){ JSObject *ob = NULL; ob = JSVAL_TO_OBJECT(JS_THIS(cx,vp)); if(ob){ video *vid = (video*)JS_GetPrivate(cx,ob); if(!vid) return JS_TRUE; if(argc = 0 || (!JSVAL_IS_DOUBLE(JS_ARGV(cx,vp)[0]) && !JSVAL_IS_INT(JS_ARGV(cx,vp)[0]))){ double vol; vol = vid->vb->getVideoVol(vid); //print("Got value %f\n",vol); JS_SET_RVAL(cx,vp,INT_TO_JSVAL((int) (vol*100))); } else { double vol; if(JSVAL_IS_DOUBLE(JS_ARGV(cx,vp)[0])) vol = JSVAL_TO_DOUBLE(JS_ARGV(cx,vp)[0])/100; else if (JSVAL_IS_INT(JS_ARGV(cx,vp)[0])) vol = ((double)JSVAL_TO_INT(JS_ARGV(cx,vp)[0]))/100; if(vol < 0) vol = 0; if(vol > 1) vol = 1; vid->vb->setVideoVol(vid,vol); JS_SET_RVAL(cx,vp,INT_TO_JSVAL((int)vol * 100)); } } return JS_TRUE; }
JSBool webRspGetImg(JSContext *cx, uintN argc, jsval *vp) { SDL_Texture *tx = NULL; JSObject * object = NULL; jsval vl; JS_GetProperty(cx,JS_GetGlobalObject(cx),"Image",&vl); object = JS_New(cx,JSVAL_TO_OBJECT(vl),0,NULL); if(object){ JSObject *ob = NULL; ob = JSVAL_TO_OBJECT(JS_THIS(cx,vp)); if(ob){ CURLMsg *msg; msg = (CURLMsg*) JS_GetPrivate(cx,ob); if(msg){ rqPrivate *rq = NULL; curl_easy_getinfo(msg->easy_handle,CURLINFO_PRIVATE,(char**)&rq); if(rq){ SDL_RWops* rwop = NULL; rwop = SDL_RWFromConstMem(rq->data,rq->size); if(rwop){ tx = IMG_LoadTexture_RW(renderer,rwop,1); //tx = IMG_LoadTextureTyped_RW(renderer,rwop,1,"JPEG"); SDL_RenderCopy(renderer,tx,NULL,NULL); if(tx){ JS_SetPrivate(cx,object,tx); imageAddProps(cx,object); print("hi\n"); JS_SET_RVAL(cx,vp,OBJECT_TO_JSVAL(object)); } } } } } } return JS_TRUE; }
JSBool WresumeVideo(JSContext *cx, uintN argc, jsval *vp) { video *vid; vid = (video*)JS_GetPrivate(cx,JSVAL_TO_OBJECT(JS_THIS(cx,vp))); if(vid){ vid->vb->resumeVideo(vid); } JS_SET_RVAL(cx,vp,JSVAL_NULL); return JS_TRUE; }
JSBool WisStoppedVideo(JSContext *cx, uintN argc, jsval *vp) { video *vid; vid = (video*)JS_GetPrivate(cx,JSVAL_TO_OBJECT(JS_THIS(cx,vp))); if(vid){ JS_SET_RVAL(cx,vp,BOOLEAN_TO_JSVAL(vid->vb->isStoppedVideo(vid))); return JS_TRUE; } JS_SET_RVAL(cx,vp,JSVAL_NULL); return JS_TRUE; }
CEXPORT JSBool def_animate_hasFrames(JSContext *cx, unsigned argc, jsval *vp) { JS_BeginRequest(cx); JSObject *thiz = JSVAL_TO_OBJECT(JS_THIS(cx, vp)); view_animation *anim = (view_animation *)JS_GetPrivate(thiz); jsval val = BOOLEAN_TO_JSVAL((bool)anim->frame_head); JS_SET_RVAL(cx, vp, val); JS_EndRequest(cx); return JS_TRUE; }
JSBool WcaptureVideo(JSContext *cx, uintN argc, jsval *vp) { video *vid = (video*)JS_GetPrivate(cx,JSVAL_TO_OBJECT(JS_THIS(cx,vp))); if(vid){ SDL_Texture *tx = vid->vb->captureFrameVideo(vid); //JS_SET_RVAL(cx,vp,); //return JS_TRUE; } JS_SET_RVAL(cx,vp,JSVAL_NULL); return JS_TRUE; }
CEXPORT JSBool def_animate_resume(JSContext *cx, unsigned argc, jsval *vp) { JS_BeginRequest(cx); JSObject *thiz = JSVAL_TO_OBJECT(JS_THIS(cx, vp)); view_animation *anim = (view_animation *)JS_GetPrivate(thiz); view_animation_resume(anim); jsval thiz_val = OBJECT_TO_JSVAL(thiz); JS_SET_RVAL(cx, vp, thiz_val); JS_EndRequest(cx); return JS_TRUE; }
static JSBool error_to_string(JSContext *context, uintN argc, jsval *vp) { jsval v_self; JSObject *self; Error *priv; jsval v_out; gchar *descr; JSBool retval; v_self = JS_THIS(context, vp); if (!JSVAL_IS_OBJECT(v_self)) { /* Lie a bit here... */ gjs_throw(context, "GLib.Error.prototype.toString() called on a non object"); return JS_FALSE; } self = JSVAL_TO_OBJECT(v_self); priv = priv_from_js(context, self); if (priv == NULL) return JS_FALSE; v_out = JSVAL_VOID; retval = JS_FALSE; /* We follow the same pattern as standard JS errors, at the expense of hiding some useful information */ if (priv->gerror == NULL) { descr = g_strdup_printf("%s.%s", g_base_info_get_namespace(priv->info), g_base_info_get_name(priv->info)); if (!gjs_string_from_utf8(context, descr, -1, &v_out)) goto out; } else { descr = g_strdup_printf("%s.%s: %s", g_base_info_get_namespace(priv->info), g_base_info_get_name(priv->info), priv->gerror->message); if (!gjs_string_from_utf8(context, descr, -1, &v_out)) goto out; } JS_SET_RVAL(context, vp, v_out); retval = JS_TRUE; out: g_free(descr); return retval; }
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; }
JSBool WdurationVideo(JSContext *cx, uintN argc, jsval *vp) { //return the length of the video in seconds, as a float. video *vid = (video*)JS_GetPrivate(cx,JSVAL_TO_OBJECT(JS_THIS(cx,vp))); double length; //if(vid->pipeline) length = vid->vb->getDurationVideo(vid); //else // length = vid->bufdur; 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 QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp) { JS::Value thisv = JS_THIS(cx, vp); if (thisv == JSVAL_NULL) return false; JSObject* obj = JSVAL_TO_OBJECT(thisv); JSClass* clasp = js::GetObjectJSClass(obj); if (!IsDOMClass(clasp) || !DOMJSClass::FromJSClass(clasp)->mDOMObjectIsISupports) { return Throw<true>(cx, NS_ERROR_FAILURE); } nsISupports* native = UnwrapDOMObject<nsISupports>(obj); if (argc < 1) { return Throw<true>(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS); } JS::Value* argv = JS_ARGV(cx, vp); if (!argv[0].isObject()) { return Throw<true>(cx, NS_ERROR_XPC_BAD_CONVERT_JS); } nsIJSIID* iid; xpc_qsSelfRef iidRef; if (NS_FAILED(xpc_qsUnwrapArg<nsIJSIID>(cx, argv[0], &iid, &iidRef.ptr, &argv[0]))) { return Throw<true>(cx, NS_ERROR_XPC_BAD_CONVERT_JS); } MOZ_ASSERT(iid); if (iid->GetID()->Equals(NS_GET_IID(nsIClassInfo))) { nsresult rv; nsCOMPtr<nsIClassInfo> ci = do_QueryInterface(native, &rv); if (NS_FAILED(rv)) { return Throw<true>(cx, rv); } return WrapObject(cx, obj, ci, &NS_GET_IID(nsIClassInfo), vp); } // Lie, otherwise we need to check classinfo or QI *vp = thisv; return true; }
CEXPORT JSBool def_animate_now(JSContext *cx, unsigned argc, jsval *vp) { JS_BeginRequest(cx); jsval *vals = JS_ARGV(cx, vp); JSObject *thiz = JSVAL_TO_OBJECT(JS_THIS(cx, vp)); if (JSVAL_IS_OBJECT(*vals)) { JSObject *target = JSVAL_TO_OBJECT(*vals); if (target) { build_frame(cx, target, argc, vp, view_animation_now); } } jsval thiz_val = OBJECT_TO_JSVAL(thiz); JS_SET_RVAL(cx, vp, thiz_val); JS_EndRequest(cx); return JS_TRUE; }
JSBool WplayVideo(JSContext *cx, uintN argc, jsval *vp) { video *vid; vid = (video*)JS_GetPrivate(cx,JSVAL_TO_OBJECT(JS_THIS(cx,vp))); int rep = 0; if(JSVAL_IS_INT(JS_ARGV(cx,vp)[0])) rep = JSVAL_TO_INT(JS_ARGV(cx,vp)[0]); if(vid){ if(vid->vb->isPlayingVideo(vid)) vid->vb->setPositionVideo(vid,0); else if(vid->vb->isPausedVideo(vid)){ vid->vb->setPositionVideo(vid,0); vid->vb->resumeVideo(vid); } else vid->vb->playVideo(vid,rep); } JS_SET_RVAL(cx,vp,JSVAL_NULL); return JS_TRUE; }
JSBool webRspData(JSContext *cx, uintN argc, jsval *vp) { JSObject *ob = NULL; ob = JSVAL_TO_OBJECT(JS_THIS(cx,vp)); if(ob){ rqPrivate *rq = NULL; CURLMsg *msg; msg = (CURLMsg*) JS_GetPrivate(cx,ob); if(msg){ curl_easy_getinfo(msg->easy_handle,CURLINFO_PRIVATE,(char**)&rq); if(rq){ JSString *string = NULL; string = JS_NewStringCopyZ(cx, rq->data); if(string) JS_SET_RVAL(cx,vp,STRING_TO_JSVAL(string)); } } } return JS_TRUE; }
static JSBool error_constructor_value_of(JSContext *context, unsigned argc, jsval *vp) { jsval v_self, v_prototype; Error *priv; jsval v_out; jsid prototype_name; v_self = JS_THIS(context, vp); if (!JSVAL_IS_OBJECT(v_self)) { /* Lie a bit here... */ gjs_throw(context, "GLib.Error.valueOf() called on a non object"); return JS_FALSE; } prototype_name = gjs_runtime_get_const_string(JS_GetRuntime(context), GJS_STRING_PROTOTYPE); if (!gjs_object_require_property(context, JSVAL_TO_OBJECT(v_self), "constructor", prototype_name, &v_prototype)) return JS_FALSE; if (!JSVAL_IS_OBJECT(v_prototype)) { gjs_throw(context, "GLib.Error.valueOf() called on something that is not" " a constructor"); return JS_FALSE; } priv = priv_from_js(context, JSVAL_TO_OBJECT(v_prototype)); if (priv == NULL) return JS_FALSE; v_out = INT_TO_JSVAL(priv->domain); JS_SET_RVAL(context, vp, v_out); return TRUE; }
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; }
static JSBool error_constructor_value_of(JSContext *context, uintN argc, jsval *vp) { jsval v_self, v_prototype; Error *priv; jsval v_out; v_self = JS_THIS(context, vp); if (!JSVAL_IS_OBJECT(v_self)) { /* Lie a bit here... */ gjs_throw(context, "GLib.Error.valueOf() called on a non object"); return JS_FALSE; } if (!gjs_object_require_property(context, JSVAL_TO_OBJECT(v_self), "constructor", "prototype", &v_prototype)) return JS_FALSE; if (!JSVAL_IS_OBJECT(v_prototype)) { gjs_throw(context, "GLib.Error.valueOf() called on something that is not" " a constructor"); return JS_FALSE; } priv = priv_from_js(context, JSVAL_TO_OBJECT(v_prototype)); if (priv == NULL) return JS_FALSE; v_out = INT_TO_JSVAL(priv->domain); JS_SET_RVAL(context, vp, v_out); return TRUE; }
static JSBool iterator_self(JSContext *cx, uintN argc, jsval *vp) { *vp = JS_THIS(cx, vp); return !JSVAL_IS_NULL(*vp); }