示例#1
0
void sm_stop(spidermonkey_vm *vm) {
  begin_request(vm);
  spidermonkey_state *state = (spidermonkey_state *) JS_GetContextPrivate(vm->context);
  state->terminate = 1;
  JS_SetContextPrivate(vm->context, state);

  //Wait for any executing function to stop
  //before beginning to free up any memory.
  while (JS_IsRunning(vm->context))  {
      sleep(1);
  }

  end_request(vm);

  //Now we should be free to proceed with
  //freeing up memory without worrying about
  //crashing the VM.
  if (state != NULL) {
    if (state->error != NULL) {
      free_error(state);
    }
    driver_free(state);
  }
  JS_SetContextPrivate(vm->context, NULL);
  JS_DestroyContext(vm->context);
  JS_DestroyRuntime(vm->runtime);
  driver_free(vm);
}
示例#2
0
文件: jsparser.cpp 项目: dyne/FreeJ
JsParser::~JsParser() {
  /** The world is over */
  //  JS_DestroyContext(js_context);
  JS_DestroyRuntime(js_runtime);
  JS_ShutDown();
  func("JsParser::close()");
}
示例#3
0
文件: lwjs.c 项目: fsky/webqq
void lwqq_js_close(lwqq_js_t* js)
{
    JS_DestroyContext(js->context);
    JS_DestroyRuntime(js->runtime);
    JS_ShutDown();
    s_free(js);
}
示例#4
0
/**
 * gjs_runtime_destroy:
 * @runtime: a #JSRuntime
 *
 * Calls JS_DestroyRuntime() on runtime and frees data allocated by
 * gjs_runtime_init(); these are unified into a single call because we
 * need to order things so that the allocated data is cleaned up
 * after JS_DestroyRuntime(). We might have finalizers run by
 * JS_DestroyRuntime() that rely on the information stored in the data,
 * such as the dynamic class structs.
 *
 * This should only be called by GJS, not by applications.
 */
void
gjs_runtime_destroy(JSRuntime *runtime)
{
    RuntimeData *rd;
    void *key;
    void *value;

    rd = JS_GetRuntimePrivate(runtime);
    if (rd->context_stack != NULL || rd->current_frame.depth != 0)
        gjs_fatal("gjs_runtime_destroy() called during gjs_push_context()");

    gjs_debug(GJS_DEBUG_CONTEXT,
              "Destroying JS runtime");

    JS_DestroyRuntime(runtime);

    gjs_debug(GJS_DEBUG_CONTEXT,
              "Destroying any remaining dataset items on runtime");

    while (gjs_g_hash_table_remove_one(rd->dynamic_classes, &key, &value)) {
        JSClass *clasp = value;

        gjs_debug(GJS_DEBUG_GREPO,
                  "Finalizing dynamic class '%s'",
                  clasp->name);

        g_free( (char*) clasp->name); /* we know we malloc'd the char* even though it's const */
        g_slice_free(DynamicJSClass, (DynamicJSClass*) clasp);
    }

    g_hash_table_destroy(rd->dynamic_classes);
    g_slice_free(RuntimeData, rd);
}
int main(int argc, const char *argv[]) {
    /* Initialize the JS engine -- new/required as of SpiderMonkey 31. */
    /*if (!JS_Init())
       return 1;*/

    /* 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 1;
    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;
}
示例#6
0
static void _egueb_script_js_sm_scripter_free(void *prv)
{
	Egueb_Script_Js_Sm_Scripter *thiz = prv;

	JS_DestroyContext(thiz->cx);
	JS_DestroyRuntime(thiz->rt);
	free(thiz);
}
示例#7
0
void TearDownScripting(){
    JS_DestroyContext(cx);
    JS_DestroyRuntime(rt);

    /* Shut down the JS engine. */
    JS_ShutDown();

}
示例#8
0
void
JetpackChild::CleanUp()
{
  ClearReceivers();
  JS_DestroyContext(mCx);
  JS_DestroyRuntime(mRuntime);
  JS_ShutDown();
}
示例#9
0
void qq_js_close(qq_js_t* js)
{
    JS_DestroyContext(js->context);
    JS_DestroyRuntime(js->runtime);
    JS_ShutDown();
    /*something wrong here*/
    //s_free(js);
}
示例#10
0
void
Runtime_dealloc(Runtime* self)
{
    if(self->rt != NULL)
    {
        JS_DestroyRuntime(self->rt);
    }
}
示例#11
0
文件: core.c 项目: ohmori7/kcn-tools
void
cleanup_smjs(struct module *module)
{
	if (!smjs_ctx) return;

	JS_DestroyContext(smjs_ctx);
	JS_DestroyRuntime(smjs_rt);
}
void SpidermonkeyDestroy()
{// begin SpidermonkeyDestroy
#ifdef ADM_JS_THREADSAFE
	JS_SetContextThread(g_pCx);	
#endif
	JS_DestroyContext(g_pCx);
	JS_DestroyRuntime(g_pRt);
}// end SpidermonkeyDestroy
示例#13
0
文件: smash.cpp 项目: hypersoft/smash
void TerminateSpiderMonkey(JSContext * context) {

	if (terminated) return;
	JS_DestroyContext(context);
	JS_DestroyRuntime(runtime);
	JS_ShutDown();
	terminated = true;

}
int main(int argc, const char *argv[]) {
    /* JS variables. */
    JSRuntime *rt;
    JSContext *cx;
    JSObject *global;

    /* Create a JS runtime. */
    rt = JS_NewRuntime(8L * 1024L * 1024L,JS_NO_HELPER_THREADS);
    if (rt == NULL)
       return 1;

    /* Create a context. */
    cx = JS_NewContext(rt, 8192);
    if (cx == NULL)
       return 1;
    JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_METHODJIT);
    JS_SetVersion(cx, JSVERSION_LATEST);
    JS_SetErrorReporter(cx, reportError);

    /* Create the global object in a new compartment. */
    global = JS_NewGlobalObject(cx, &global_class, NULL);
    if (global == NULL)
       return 1;

    /* Populate the global object with the standard globals, like Object and Array. */
    if (!JS_InitStandardClasses(cx, global))
       return 1;

 
    /* Your application code here. This may include JSAPI calls
     * to create your own custom JavaScript objects and to run scripts.
     *
     * The following example code creates a literal JavaScript script,
     * evaluates it, and prints the result to stdout.
     *
     * Errors are conventionally saved in a JSBool variable named ok.
     */
	
	JS_DefineFunction(cx,global,"print",&js_print,0,0);
	
	// execJsFile(cx,"t.js");
	
	// testObj(cx);
	
	beforeTest(cx);
	execJsFile(cx,"t4.js");
	test(cx);
    
 
    /* End of your application code */
 
    /* Clean things up and shut down SpiderMonkey. */
    JS_DestroyContext(cx);
    JS_DestroyRuntime(rt);
    JS_ShutDown();
    return 0;
}
示例#15
0
static void ctxs_free(ctxStore *self)
{
	if (!self) return;
	if (self->ctx) JS_DestroyContext(self->ctx);
	if (self->run) JS_DestroyRuntime(self->run);
	if (self->cls) px_free(self->cls);
	px_free(self->pac);
	px_free(self);
}
示例#16
0
short exitProgram(JSContext *cx){ //To be called at the very end - Shutdown the whole application
	if(cx)
		JS_DestroyContext(cx);
	JS_DestroyRuntime(runtime);
	TTF_Quit();
	SDL_DestroyRenderer(renderer);
	SDL_Quit();
	JS_ShutDown();
	return 0;
}
示例#17
0
MozJSImplScope::MozRuntime::~MozRuntime() {
    JS_DestroyContext(_context);
    JS_DestroyRuntime(_runtime);

    if (_thread) {
        invariant(PR_GetCurrentThread() == _thread);
        PR_DestroyFakeThread(_thread);
        PR_BindThread(nullptr);
    }
}
示例#18
0
void DLLCALL jsrt_Release(JSRuntime *rt)
{
	list_node_t	*node;

	pthread_mutex_lock(&jsrt_mutex);
	node = listFindNode(&rt_list, rt, 0);
	if(node)
		listRemoveNode(&rt_list, node, FALSE);
	JS_DestroyRuntime(rt);
	pthread_mutex_unlock(&jsrt_mutex);
}
示例#19
0
MonkeyEngine::~MonkeyEngine()
{
	if (cx != NULL) {
		JS_DestroyContext(cx);

	}

	if (rt != NULL) {
		JS_DestroyRuntime(rt);
	}
}
示例#20
0
文件: jsparser.cpp 项目: dyne/FreeJ
JsExecutionContext::~JsExecutionContext()
{
  JS_SetContextThread(cx);
  JS_GC(cx);
  JS_BeginRequest(cx);
  JS_ClearScope(cx, obj);
  JS_EndRequest(cx);
  JS_ClearContextThread(cx);
  JS_DestroyContext(cx);
  JS_DestroyRuntime(rt);
}
示例#21
0
  ~JSRuntimeWrapper()
  {
    MOZ_COUNT_DTOR(JSRuntimeWrapper);
    if (mContext) {
      JS_DestroyContext(mContext);
    }

    if (mRuntime) {
      JS_DestroyRuntime(mRuntime);
    }
  }
示例#22
0
文件: runtime.c 项目: ripta/johnson
static void deallocate(JohnsonRuntime* runtime)
{
  JS_RemoveRoot(johnson_get_current_context(runtime), &(runtime->global));
  
  JSContext *context;
  JSContext *iterator = NULL;

  while ((context = JS_ContextIterator(runtime->js, &iterator)) != NULL)
    JS_DestroyContext(context);
  
  JS_DestroyRuntime(runtime->js);
  free(runtime);
}
示例#23
0
bool CompileFile(const std::string &inputFilePath, const std::string &outputFilePath) {
    bool result = false;
    std::string ofp;
    if (!outputFilePath.empty()) {
        ofp = outputFilePath;
    }
    else {
        ofp = RemoveFileExt(inputFilePath) + BYTE_CODE_FILE_EXT;
    }
    std::cout << "Input file: " << inputFilePath << std::endl;
    JSRuntime * runtime = JS_NewRuntime(10 * 1024 * 1024, JS_NO_HELPER_THREADS);
    JSContext *context = JS_NewContext(runtime, 10240);
    JS_SetOptions(context, JSOPTION_TYPE_INFERENCE);
    JS_SetVersion(context, JSVERSION_LATEST);
    JS_SetOptions(context, JS_GetOptions(context) & ~JSOPTION_METHODJIT);
    JS_SetOptions(context, JS_GetOptions(context) & ~JSOPTION_METHODJIT_ALWAYS);
	JSObject* global = JS_NewGlobalObject(context, &GlobalClass, NULL);
    JS_SetErrorReporter(context, &ReportError);
	if (JS_InitStandardClasses(context, global)) {

        JS::CompileOptions options(context);
        options.setUTF8(true);
        options.setSourcePolicy(JS::CompileOptions::NO_SOURCE);
        js::RootedObject rootedObject(context, global);
        std::cout << "Compiling ..." << std::endl;
        JSScript *script = JS::Compile(context, rootedObject, options, inputFilePath.c_str());
        if (script) {
            void *data = NULL;
            uint32_t length = 0;
            std::cout << "Encoding ..." << std::endl;
            data = JS_EncodeScript(context, script, &length);
            if (data) {
                if (WriteFile(ofp, data, length)) {
                    std::cout << "Done! " << "Output file: " << ofp << std::endl;
                    result = true;
                }
            }
        }
        
    }
    if (context) {
        JS_DestroyContext(context);
        context = NULL;
    }
    if (runtime) {
        JS_DestroyRuntime(runtime);
        runtime = NULL;
    }
    return result;
}
示例#24
0
/* XXX FIXME: Iargv/Ienviron are now associated with running. */
rpmjs rpmjsNew(char ** av, uint32_t flags)
{
    rpmjs js =
#ifdef	NOTYET
	(flags & 0x80000000) ? rpmjsI() :
#endif
	rpmjsGetPool(_rpmjsPool);
    JSI_t I = NULL;

#if defined(WITH_GPSEE)

#if defined(XXX_GPSEE_DEBUGGER)	/* XXX js->jsdc? */
    JSDContext *jsdc;
#endif

    if (flags == 0)
	flags = _rpmjs_options;

    if (F_ISSET(flags, NOUTF8) || getenv("GPSEE_NO_UTF8_C_STRINGS")) {
	JS_DestroyRuntime(JS_NewRuntime(1024));
	putenv((char *) "GPSEE_NO_UTF8_C_STRINGS=1");
    }

    /* XXX FIXME: js->Iargv/js->Ienviron for use by rpmjsRunFile() */
    I = gpsee_createInterpreter();
#if defined(XXX_GPSEE_DEBUGGER)
    js->jsdc = gpsee_initDebugger(I->cx, I->realm, DEBUGGER_JS);
#endif

#ifdef	NOTYET	/* FIXME: dig out where NOCACHE has moved. */
    if (F_ISSET(flags, NOCACHE))
	I->useCompilerCache = 0;
#endif
    if (F_ISSET(flags, NOWARN)) {
	gpsee_runtime_t * grt = JS_GetRuntimePrivate(JS_GetRuntime(I->cx));
	grt->errorReport |= er_noWarnings;
    }

    JS_SetOptions(I->cx, (flags & 0xffff));
#if defined(JS_GC_ZEAL)
    JS_SetGCZeal(I->cx, _rpmjs_zeal);
#endif
#endif	/* WITH_GPSEE */

    js->flags = flags;
    js->I = I;

    return rpmjsLink(js);
}
void SG_jscore__shutdown(SG_context * pCtx)
{
	if(gpJSCoreGlobalState!=NULL)
	{
		if (gpJSCoreGlobalState->rt)
			JS_DestroyRuntime(gpJSCoreGlobalState->rt);
		JS_ShutDown();

		SG_PATHNAME_NULLFREE(pCtx, gpJSCoreGlobalState->pPathToDispatchDotJS);
		SG_PATHNAME_NULLFREE(pCtx, gpJSCoreGlobalState->pPathToCore);
		SG_PATHNAME_NULLFREE(pCtx, gpJSCoreGlobalState->pPathToModules);
		SG_RBTREE_NULLFREE_WITH_ASSOC(pCtx, gpJSCoreGlobalState->prbJSMutexes, _free_js_mutex_cb);
		SG_NULLFREE(pCtx, gpJSCoreGlobalState);
	}
}
示例#26
0
文件: nsjs.c 项目: scottg/aolserver
static void
JsCleanup(void *arg) 
{
	jsEnv *jsEnvPtr = arg;
	
	if (jsEnvPtr != NULL) {
		JS_DestroyContext(jsEnvPtr->context); 
		JS_DestroyRuntime(jsEnvPtr->runtime);
		JS_ShutDown();

		Ns_Log(Debug, "JsCleanup: %p", jsEnvPtr);

		ns_free(jsEnvPtr);
	}
}
示例#27
0
文件: pacparser.c 项目: betaY/crawler
// 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
}
示例#29
0
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;
}
示例#30
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();
}