static JSBool js_forceUnload(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { js_plugin_unload0(cx, JS_GetPrivate(cx, obj)); *rval = JSVAL_VOID; return JS_TRUE; }
static void js_fini(void) { js_plugin_t *jsp, *n; JSContext *cx; cx = js_newctx(err_reporter); JS_BeginRequest(cx); for(jsp = LIST_FIRST(&js_plugins); jsp != NULL; jsp = n) { n = LIST_NEXT(jsp, jsp_link); js_plugin_unload0(cx, jsp); } JS_RemoveRoot(cx, &showtimeobj); JS_EndRequest(cx); JS_GC(cx); JS_DestroyContext(cx); JS_DestroyRuntime(runtime); JS_ShutDown(); }
static void js_fini(void) { js_plugin_t *jsp, *n; JSContext *cx = js_global_cx; prop_courier_destroy(js_global_pc); JS_SetContextThread(cx); JS_BeginRequest(cx); for(jsp = LIST_FIRST(&js_plugins); jsp != NULL; jsp = n) { n = LIST_NEXT(jsp, jsp_link); js_plugin_unload0(cx, jsp); } JS_RemoveRoot(cx, &showtimeobj); JS_EndRequest(cx); JS_GC(cx); JS_DestroyContext(cx); JS_DestroyRuntime(runtime); JS_ShutDown(); }
void js_plugin_unload(const char *id) { JSContext *cx; js_plugin_t *jsp; LIST_FOREACH(jsp, &js_plugins, jsp_link) if(!strcmp(jsp->jsp_id, id)) break; if(jsp == NULL) return; fa_unreference(jsp->jsp_ref); cx = js_newctx(NULL); JS_BeginRequest(cx); js_plugin_unload0(cx, jsp); JS_EndRequest(cx); JS_GC(cx); JS_DestroyContext(cx); }
int js_plugin_load(const char *id, const char *url, char *errbuf, size_t errlen) { char *sbuf; size_t size; JSContext *cx; js_plugin_t *jsp; JSObject *pobj, *gobj; JSScript *s; char path[PATH_MAX]; jsval val; fa_handle_t *ref; ref = fa_reference(url); if((sbuf = fa_load(url, &size, NULL, errbuf, errlen, NULL)) == NULL) { fa_unreference(ref); return -1; } cx = js_newctx(err_reporter); JS_BeginRequest(cx); /* Remove any plugin with same URL */ LIST_FOREACH(jsp, &js_plugins, jsp_link) if(!strcmp(jsp->jsp_id, id)) break; if(jsp != NULL) js_plugin_unload0(cx, jsp); jsp = calloc(1, sizeof(js_plugin_t)); jsp->jsp_url = strdup(url); jsp->jsp_id = strdup(id); jsp->jsp_ref = ref; LIST_INSERT_HEAD(&js_plugins, jsp, jsp_link); gobj = JS_NewObject(cx, &global_class, NULL, NULL); JS_InitStandardClasses(cx, gobj); JS_DefineProperty(cx, gobj, "showtime", OBJECT_TO_JSVAL(showtimeobj), NULL, NULL, JSPROP_READONLY | JSPROP_PERMANENT); /* Plugin object */ pobj = JS_NewObject(cx, &plugin_class, NULL, gobj); JS_AddNamedRoot(cx, &pobj, "plugin"); JS_SetPrivate(cx, pobj, jsp); JS_DefineFunctions(cx, pobj, plugin_functions); val = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, url)); JS_SetProperty(cx, pobj, "url", &val); if(!fa_parent(path, sizeof(path), url)) { val = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, path)); JS_SetProperty(cx, pobj, "path", &val); } JS_DefineProperty(cx, pobj, "URIRouting", BOOLEAN_TO_JSVAL(1), NULL, jsp_setEnableURIRoute, JSPROP_PERMANENT); jsp->jsp_enable_uri_routing = 1; JS_DefineProperty(cx, pobj, "search", BOOLEAN_TO_JSVAL(1), NULL, jsp_setEnableSearch, JSPROP_PERMANENT); jsp->jsp_enable_search = 1; jsp->jsp_protect_object = 1; s = JS_CompileScript(cx, pobj, sbuf, size, url, 1); free(sbuf); if(s != NULL) { JSObject *sobj = JS_NewScriptObject(cx, s); jsval result; JS_AddNamedRoot(cx, &sobj, "script"); JS_ExecuteScript(cx, pobj, s, &result); JS_RemoveRoot(cx, &sobj); } JS_RemoveRoot(cx, &pobj); JS_EndRequest(cx); JS_GC(cx); JS_DestroyContext(cx); return 0; }