static JSBool chk(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JSRuntime *rt = JS_GetRuntime(cx); JSContext *acx = JS_NewContext(rt, 8192); if (!acx) { JS_ReportOutOfMemory(cx); return JS_FALSE; } // acx should not be running bool ok = !JS_IsRunning(acx); if (!ok) JS_ReportError(cx, "Assertion failed: brand new context claims to be running"); JS_DestroyContext(acx); return ok; }
static bool chk(JSContext *cx, unsigned argc, jsval *vp) { JSRuntime *rt = JS_GetRuntime(cx); JSContext *acx = JS_NewContext(rt, 8192); if (!acx) { JS_ReportOutOfMemory(cx); return false; } // acx should not be running bool ok = !JS_IsRunning(acx); if (!ok) JS_ReportError(cx, "Assertion failed: brand new context claims to be running"); JS_DestroyContext(acx); return ok; }
// Destroys JavaSctipt Engine. void pacparser_cleanup() { // Reinitliaze config variables. myip = NULL; if (cx) { JS_DestroyContext(cx); cx = NULL; } if (rt) { JS_DestroyRuntime(rt); rt = NULL; } if (!cx && !rt) JS_ShutDown(); global = NULL; if (_debug()) print_error("DEBUG: Pacparser destroyed.\n"); }
void TraceMonkeyEngine::quit() { Logging::log(Logging::DEBUG, "TraceMonkeyEngine::quit\r\n"); // Clean up our internal wrappers globalValue.reset(); /* Cleanup. */ JS_DestroyContext(context); context = NULL; JS_DestroyRuntime(runtime); runtime = NULL; // JS_ShutDown(); XXX Should be done only when NO runtimes remain, for final cleanup, as we are quitting probably }
static JSBool evalcx(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JSString *str; JSObject *sandbox; JSContext *subcx; const jschar *src; size_t srclen; JSBool ret = JS_FALSE; sandbox = NULL; if(!JS_ConvertArguments(cx, argc, argv, "S / o", &str, &sandbox)) { return JS_FALSE; } subcx = JS_NewContext(JS_GetRuntime(cx), 8L * 1024L); if(!subcx) { JS_ReportOutOfMemory(cx); return JS_FALSE; } SETUP_REQUEST(subcx); src = JS_GetStringChars(str); srclen = JS_GetStringLength(str); if(!sandbox) { sandbox = JS_NewObject(subcx, NULL, NULL, NULL); if(!sandbox || !JS_InitStandardClasses(subcx, sandbox)) { goto done; } } if(srclen == 0) { *rval = OBJECT_TO_JSVAL(sandbox); } else { JS_EvaluateUCScript(subcx, sandbox, src, srclen, NULL, 0, rval); } ret = JS_TRUE; done: FINISH_REQUEST(subcx); JS_DestroyContext(subcx); return ret; }
bool round_js_sm_engine_destroy(RoundJavaScriptEngine* engine) { if (!engine) return false; if (engine->cx) { JS_DestroyContext(engine->cx); } if (engine->rt) { JS_DestroyRuntime(engine->rt); } JS_ShutDown(); return true; }
void SG_jscontext__release(SG_context * pCtx, SG_jscontext ** ppJs) { if(ppJs==NULL || *ppJs==NULL) return; if(gpJSContextPoolGlobalState->ssjsMutable) { SG_httprequestprofiler__start(SG_HTTPREQUESTPROFILER_CATEGORY__JSREQUEST_TOGGLING); JS_EndRequest((*ppJs)->cx); JS_DestroyContext((*ppJs)->cx); SG_httprequestprofiler__stop(); if(SG_context__has_err(pCtx)) // An error was produced during GC... { SG_log__report_error__current_error(pCtx); SG_context__err_reset(pCtx); } SG_NULLFREE(pCtx, (*ppJs)); } else { SG_jscontext * pJs = *ppJs; JS_MaybeGC(pJs->cx); JS_SetContextPrivate(pJs->cx, NULL); // Clear out the old pCtx pointer. SG_httprequestprofiler__start(SG_HTTPREQUESTPROFILER_CATEGORY__JSREQUEST_TOGGLING); JS_EndRequest(pJs->cx); pJs->isInARequest = SG_FALSE; (void)JS_ClearContextThread(pJs->cx); SG_httprequestprofiler__stop(); SG_ERR_CHECK_RETURN( SG_mutex__lock(pCtx, &gpJSContextPoolGlobalState->lock) ); pJs->pNextAvailableContext = gpJSContextPoolGlobalState->pFirstAvailableContext; gpJSContextPoolGlobalState->pFirstAvailableContext = pJs; --gpJSContextPoolGlobalState->numContextsCheckedOut; SG_ERR_CHECK_RETURN( SG_mutex__unlock(pCtx, &gpJSContextPoolGlobalState->lock) ); *ppJs = NULL; } }
static void ctx_exit(struct object *obj) { if (THIS->ctx) { JS_DestroyContext(THIS->ctx); THIS->ctx = NULL; } if (THIS->output_buf) { free(THIS->output_buf); THIS->output_buf = NULL; THIS->output_buf_len = THIS->output_buf_last = 0; } if (idx_result) free_string(idx_result); if (idx_output) free_string(idx_output); }
int cScriptEngine::Exit() { if(m_cx != NULL) { JS_DestroyContext(m_cx); m_cx = NULL; } if(m_rt != NULL) { JS_Finish(m_rt); m_rt = NULL; } DELETE_A(m_script_code); return 0; }
void Engine::cleanup() { while ( !m_contexts.empty() ) { JSContext *cx = m_contexts.top(); m_contexts.pop(); JS_ClearContextThread(cx); JS_DestroyContext(cx); } if ( m_runtime!=NULL ) { JS_DestroyRuntime(m_runtime); m_runtime = NULL; } JS_ShutDown(); }
/*---------------------------------------------------------------------------*/ WebcJSBrowserContext::~WebcJSBrowserContext (void) { JSContext* acx = 0; JSContext* iterp = WEBC_NULL; #if (WEBC_DEBUG_JSCRIPT) if (mJSDebug) WEBC_DELETE(mJSDebug); #endif while ((acx = JS_ContextIterator(mRuntime, &iterp)) != WEBC_NULL) { JS_GC(acx); JS_DestroyContext(acx); iterp = WEBC_NULL; } JS_DestroyRuntime(mRuntime); JS_ShutDown(); }
jsman::~jsman() { if (JSSettings->HasBool("js_enabled")) { JSSettings->ReplaceBool("js_enabled",js_enabled); } else { JSSettings->AddBool("js_enabled",js_enabled); } if (script_head) { jsscripts_st *cur; while (script_head!=NULL) { cur=script_head->next; delete script_head; script_head=cur; } } JS_DestroyContext(cx); JS_DestroyRuntime(rt); }
/* * call-seq: * native_initialize(options={}) * * Initializes the native spidermonkey values. */ static VALUE initialize_native(VALUE self, VALUE rb_runtime, VALUE UNUSED(options)) { JohnsonContext* context; JohnsonRuntime* runtime; Data_Get_Struct(self, JohnsonContext, context); Data_Get_Struct(rb_runtime, JohnsonRuntime, runtime); if ((context->js = JS_NewContext(runtime->js, 8192L))) { // See if the runtime already has a shared global object. JSObject* global = runtime->global; // If it does, use it. If not, if (!global) // create one of our global objects. global = johnson_create_global_object(context->js); // Manually set the context's global object. JS_SetGlobalObject(context->js, global); JS_SetErrorReporter(context->js, report_js_error); JS_SetBranchCallback(context->js, branch_callback); JS_SetContextPrivate(context->js, (void *)self); JS_SetOptions(context->js, JS_GetOptions(context->js) | JSOPTION_DONT_REPORT_UNCAUGHT #ifdef JSOPTION_VAROBJFIX | JSOPTION_VAROBJFIX #endif // #ifdef JSOPTION_XML // | JSOPTION_XML // #endif ); // Success. return init_spidermonkey_extensions(context, self); } if (context->js) JS_DestroyContext(context->js); rb_raise(rb_eRuntimeError, "Failed to initialize SpiderMonkey context"); }
static void sajsj_InitLocked() { JRIEnv *env; /* if jsj has already been initialized, we don't do this * standalone jsj setup, and none of the stuff in this * file gets used */ if (!JSJ_Init(&sajsjCallbacks)) return; jsjiTask = JS_Init(8L * 1024L * 1024L); jsmon = PR_NewMonitor(); globalContext = JS_NewContext(jsjiTask, 8192); PR_ASSERT(globalContext); globalObject = NULL; JS_AddRoot(globalContext, &globalObject); globalObject = JS_NewObject(globalContext, &sajsj_global_class, NULL, NULL); if (!globalObject) { PR_ASSERT(globalObject); goto trash_cx; } if (!JS_InitStandardClasses(globalContext, globalObject)) goto trash_cx; if (!JSJ_InitContext(globalContext, globalObject)) goto trash_cx; env = JRI_GetCurrentEnv(); PR_ASSERT(env); return; trash_cx: JS_DestroyContext(globalContext); globalContext = NULL; /* FIXME error codes? */ return; }
void JSAPITest::uninit() { if (oldCompartment) { JS_LeaveCompartment(cx, oldCompartment); oldCompartment = nullptr; } if (global) { JS_LeaveCompartment(cx, nullptr); JS::RemoveObjectRoot(cx, &global); global = nullptr; } if (cx) { JS_EndRequest(cx); JS_DestroyContext(cx); cx = nullptr; } if (rt) { destroyRuntime(); rt = nullptr; } }
CJSRuntime::~CJSRuntime(void) { Cleanup(); JS_UnlockGCThing(jsContext, spellsObj); //JS_RemoveRoot(jsContext, &spellsObj); JS_UnlockGCThing(jsContext, accountsObj); //JS_RemoveRoot(jsContext, &accountsObj); JS_UnlockGCThing(jsContext, consoleObj); //JS_RemoveRoot(jsContext, &consoleObj); for (size_t i = JSP_ITEM; i < JSP_COUNT; ++i) { JS_UnlockGCThing(jsContext, protoList[i]); //JS_RemoveRoot(jsContext, &protoList[i]); } JS_UnlockGCThing(jsContext, jsGlobal); //JS_RemoveRoot(jsContext, &jsGlobal); JS_DestroyContext(jsContext); JS_DestroyRuntime(jsRuntime); }
NS_IMETHODIMP nsJSSh::Cleanup() { nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID()); if (!xpc) { NS_ERROR("failed to get xpconnect service"); return NS_ERROR_FAILURE; } { JSAutoRequest ar(mJSContext); if (mContextObj != mGlobal) JS_RemoveRoot(mJSContext, &(mContextObj)); JS_ClearScope(mJSContext, mGlobal); JS_GC(mJSContext); } JS_DestroyContext(mJSContext); return NS_OK; }
static void gjs_context_dispose(GObject *object) { GjsContext *js_context; js_context = GJS_CONTEXT(object); if (js_context->profiler) { gjs_profiler_free(js_context->profiler); js_context->profiler = NULL; } if (js_context->global != NULL) { js_context->global = NULL; } if (js_context->context != NULL) { gjs_debug(GJS_DEBUG_CONTEXT, "Destroying JS context"); if (js_context->we_own_runtime) gjs_runtime_set_default_context(js_context->runtime, NULL); JS_DestroyContext(js_context->context); js_context->context = NULL; } if (js_context->runtime != NULL) { if (js_context->we_own_runtime) { /* Cleans up data as well as destroying the runtime. Foreign * contexts aren't supported at the moment; if we supported * them, then the data simply would't get cleaned up. */ gjs_runtime_destroy(js_context->runtime); } js_context->runtime = NULL; } G_OBJECT_CLASS(gjs_context_parent_class)->dispose(object); }
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_unload(cx, jsp); } JS_RemoveRoot(cx, &showtimeobj); JS_EndRequest(cx); JS_GC(cx); JS_DestroyContext(cx); JS_DestroyRuntime(runtime); JS_ShutDown(); }
static void *thread_start(void *arg) { thread_stuff ts = (thread_stuff) arg; JSContext *cx; jsval argv[1], rval; uintN argc; cx = JS_NewContext(ts->rt, 8192); JS_SetContextPrivate(cx, ts); if(ts->arg != JSVAL_VOID) { argv[0] = ts->arg; argc = 1; } else argc = 0; ts->state = THREAD_RUN; JS_CallFunction(cx, ts->amber, ts->fun, argc, argv, &rval); ts->state = THREAD_DONE; JS_DestroyContext(cx); return NULL; }
/*---------------------------------------------------------------------------*/ void WebcJSBrowserContext::FreeContext (JSContext* cx) { if (mNumFreeContexts < WEBC_CFG_JS_CX_POOL_SIZE) { mContextPool[mNumFreeContexts++] = cx; #ifdef WEBC_JS_GARBAGE_COLLECT_INTERVAL if (!mGCCounter) { JS_GC(cx); mGCCounter = WEBC_JS_GARBAGE_COLLECT_INTERVAL; } else { mGCCounter--; } #endif // WEBC_JS_GARBAGE_COLLECT_INTERVAL JS_SetGlobalObject(cx, WEBC_NULL); } else { JS_DestroyContext(cx); } }
static void _destroyJSDContext(JSDContext* jsdc) { JSD_ASSERT_VALID_CONTEXT(jsdc); JSD_LOCK(); JS_REMOVE_LINK(&jsdc->links); JSD_UNLOCK(); jsd_DestroyObjectManager(jsdc); jsd_DestroyAtomTable(jsdc); jsdc->inited = JS_FALSE; /* * We should free jsdc here, but we let it leak in case there are any * asynchronous hooks calling into the system using it as a handle * * XXX we also leak the locks */ JS_DestroyContext(jsdc->dumbContext); jsdc->dumbContext = NULL; }
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 main(int argc, const char *argv[]) { /* Create a JS runtime. */ JSRuntime *rt = JS_NewRuntime(8L * 1024L * 1024L, JS_NO_HELPER_THREADS); if (!rt) return 1; /* Create a context. */ JSContext *cx = JS_NewContext(rt, 8192); if (!cx) return 2; JS_SetOptions(cx, JSOPTION_VAROBJFIX); JS_SetErrorReporter(cx, reportError); int status = run(cx); JS_DestroyContext(cx); JS_DestroyRuntime(rt); /* Shut down the JS engine. */ JS_ShutDown(); return status; }
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(); }
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 sm_stop(spidermonkey_vm *vm) { JS_SetContextThread(vm->context); JS_DestroyContext(vm->context); JS_DestroyRuntime(vm->runtime); driver_free(vm); }
Scope::~Scope() { if ( _context ) JS_DestroyContext( _context ); _context = NULL ; _global = NULL ; }
SkJS::~SkJS() { DisposeDisplayables(); JS_DestroyContext(fContext); JS_DestroyRuntime(fRuntime); JS_ShutDown(); }
char* launchApp(char *appName,int isMenu){ static int nruns = 0; char* tmp = NULL,*script = NULL, *addrBack = NULL; if(appName){ static JSContext *cx = NULL; static JSObject *gl = NULL; script = fileToString(LIBRARY); if(!(cx = JS_NewContext(runtime, 8192))){ fprint(stderr,"Problem creating runtime\n"); exit(EXIT_FAILURE); } JS_SetErrorReporter(cx, reportError); //if(!(gl = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL))){ static struct JSPrincipals def_principles = {0}; if(!(gl = JS_NewGlobalObject(cx, &global_class, NULL))){ fprint(stderr,"Problem creating global object\n"); exit(EXIT_FAILURE); } JSCompartment *cmp = JS_EnterCompartment(cx, gl); if (!(JS_InitStandardClasses(cx, gl))){ fprint(stderr,"Problem creating standard classes\n"); exit(EXIT_FAILURE); } if(!JS_DefineFunctions(cx, gl, jsFunctions)){ fprint(stderr,"Unable to load native functions\n"); exit(EXIT_FAILURE); } globalObject = gl; char *pathToFile = NULL; if(isMenu){ pathToFile = (char*)malloc(1+strlen(MENU_DIR)); strcpy(pathToFile,MENU_DIR); } else { pathToFile = (char*)malloc(strlen(appName) + 1 + strlen(GAMES_DIR)); strcpy(pathToFile,GAMES_DIR); strcat(pathToFile,appName); //strcat(pathToFile,"/"); } JSBool ran = JS_FALSE; jsval retVal; obj.chrootPath = pathToFile; JS_SetPrivate(cx,gl,&obj); SDL_FlushEvents(); //clear queue of events before starting a new app. if(isMenu && 0 == nruns) { //define the property first_run = true; JS_DefineProperty(cx,JS_GetGlobalObject(cx),"first_run",BOOLEAN_TO_JSVAL(JS_TRUE),NULL,NULL,0); } if(script){ loadBaseClasses(appName,pathToFile,cx); //appName is without the extension, appPath needs the directory to chroot ran = JS_EvaluateScript(cx, gl, script, strlen(script) , LIBRARY,0, &retVal); } nruns++; clearModules(cx); JS_GC(JS_GetRuntime(cx)); JS_LeaveCompartment(cx,cmp); //The user requested to quit. if(SDL_QuitRequested()){ if(script)free(script); exitProgram(cx); exit(EXIT_SUCCESS); } if(isMenu && (ran == JS_FALSE)){ if(script) free(script); exitProgram(cx); exit(EXIT_FAILURE); } if(ran != JS_FALSE){ if(JSVAL_IS_STRING(retVal)){ addrBack = JS_EncodeString(cx,JSVAL_TO_STRING(retVal)); tmp = (char*)malloc(strlen(addrBack) +1); strcpy(tmp,addrBack); JS_free(cx,addrBack); addrBack = tmp; } if(JSVAL_IS_BOOLEAN(retVal) && isMenu){ if(script) free(script); if(pathToFile) free(pathToFile); exitProgram(cx); exit(EXIT_SUCCESS); } } else { addrBack = NULL; } if(script) free(script); if(pathToFile) free(pathToFile); JS_DestroyContext(cx); return addrBack; } }