コード例 #1
0
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;
}
コード例 #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
void ScriptingHost::FinalShutdown()
{
	// This should only be called once per process, just to clean up before
	// we report memory leaks. (Otherwise, if it's called while there are
	// other contexts active in other threads, things will break.)
	JS_ShutDown();
}
コード例 #5
0
void
JetpackChild::CleanUp()
{
  ClearReceivers();
  JS_DestroyContext(mCx);
  JS_DestroyRuntime(mRuntime);
  JS_ShutDown();
}
コード例 #6
0
ファイル: js.cpp プロジェクト: badcell/kopete-lwqq
void qq_js_close(qq_js_t* js)
{
    JS_DestroyContext(js->context);
    JS_DestroyRuntime(js->runtime);
    JS_ShutDown();
    /*something wrong here*/
    //s_free(js);
}
コード例 #7
0
void TearDownScripting(){
    JS_DestroyContext(cx);
    JS_DestroyRuntime(rt);

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

}
コード例 #8
0
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;
}
コード例 #9
0
ファイル: smash.cpp プロジェクト: hypersoft/smash
void TerminateSpiderMonkey(JSContext * context) {

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

}
コード例 #10
0
ファイル: jsEngine.cpp プロジェクト: joejoyce/jsEngine
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;
}
コード例 #11
0
ファイル: tests.cpp プロジェクト: ashishrana7/firefox
int main(int argc, char *argv[])
{
    int total = 0;
    int failures = 0;
    const char *filter = (argc == 2) ? argv[1] : nullptr;

    if (!JS_Init()) {
        printf("TEST-UNEXPECTED-FAIL | jsapi-tests | JS_Init() failed.\n");
        return 1;
    }

    for (JSAPITest *test = JSAPITest::list; test; test = test->next) {
        const char *name = test->name();
        if (filter && strstr(name, filter) == nullptr)
            continue;

        total += 1;

        printf("%s\n", name);
        if (!test->init()) {
            printf("TEST-UNEXPECTED-FAIL | %s | Failed to initialize.\n", name);
            failures++;
            test->uninit();
            continue;
        }

        JS::HandleObject global = JS::HandleObject::fromMarkedLocation(test->global.unsafeGet());
        if (test->run(global)) {
            printf("TEST-PASS | %s | ok\n", name);
        } else {
            JSAPITestString messages = test->messages();
            printf("%s | %s | %.*s\n",
                   (test->knownFail ? "TEST-KNOWN-FAIL" : "TEST-UNEXPECTED-FAIL"),
                   name, (int) messages.length(), messages.begin());
            if (!test->knownFail)
                failures++;
        }
        test->uninit();
    }

    JS_ShutDown();

    if (failures) {
        printf("\n%d unexpected failure%s.\n", failures, (failures == 1 ? "" : "s"));
        return 1;
    }
    printf("\nPassed: ran %d tests.\n", total);
    return 0;
}
コード例 #12
0
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);
	}
}
コード例 #13
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);
	}
}
コード例 #14
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");
}
コード例 #15
0
ファイル: js_sm_engine.c プロジェクト: cybergarage/round
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;
}
コード例 #16
0
ファイル: Engine.cpp プロジェクト: CIHANGIRCAN/vibestreamer
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();
}
コード例 #17
0
/*---------------------------------------------------------------------------*/
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();
}
コード例 #18
0
ファイル: SBjsi.cpp プロジェクト: chemeris/sipxecs
/**
 * Global platform shutdown of Jsi
 *
 * @param log    VXI Logging interface used for error/diagnostic logging,
 *               only used for the duration of this function call
 *
 * @result VXIjsiResult 0 on success
 */
SBJSI_API VXIjsiResult SBjsiShutDown (VXIlogInterface  *log)
{
  static const wchar_t func[] = L"SBjsiShutDown";
  if ( log )
    log->Diagnostic (log, gblDiagTagBase + SBJSI_LOG_API, func,
		     L"entering: 0x%p", log);

  // Make sure we've been created successfully
  VXIjsiResult rc = VXIjsi_RESULT_SUCCESS;
  if ( gblInitialized == false ) {
    SBinetLogger::Error (log, MODULE_SBJSI, JSI_ERROR_NOT_INITIALIZED, NULL);
    rc = VXIjsi_RESULT_FATAL_ERROR;
    if ( log )
      log->Diagnostic (log, gblDiagTagBase + SBJSI_LOG_API, func,
		       L"exiting: returned %d", rc);
    return rc;
  }

  if ( ! log )
    return VXIjsi_RESULT_INVALID_ARGUMENT;

  // Destroy the runtime environment
  if ( gblJsiRuntime )
    delete gblJsiRuntime;
  gblJsiRuntime = NULL;
  
  // Shut down SpiderMonkey 
  JS_ShutDown( );
  
  // Finish shutdown
  gblRuntimeSize = 0;
  gblContextSize = 0;
  gblMaxBranches = 0;
  gblInitialized = false;

  log->Diagnostic (log, gblDiagTagBase + SBJSI_LOG_API, func,
		   L"exiting: returned %d", rc);
  return rc;
}
コード例 #19
0
ファイル: js.c プロジェクト: stallman/showtime
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();
}
コード例 #20
0
ファイル: js.c プロジェクト: Daisho/showtime
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();
}
コード例 #21
0
ファイル: engine.cpp プロジェクト: alabid/mongo
MozJSScriptEngine::~MozJSScriptEngine() {
    JS_ShutDown();
}
コード例 #22
0
ファイル: engine.cpp プロジェクト: Andrew8305/SequoiaDB
 ScriptEngine::~ScriptEngine()
 {
    if ( _runtime ) JS_DestroyRuntime( _runtime );
    JS_ShutDown();
 }
コード例 #23
0
ファイル: SkJS.cpp プロジェクト: FunkyVerb/devtools-window
SkJS::~SkJS() {
    DisposeDisplayables();
    JS_DestroyContext(fContext);
    JS_DestroyRuntime(fRuntime);
    JS_ShutDown();
}
コード例 #24
0
ファイル: main.cpp プロジェクト: 6520874/pipiGame
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;
    }
    
    if (!JS_Init())
        return false;
    
    std::cout << "Input file: " << inputFilePath << std::endl;
    JSRuntime * runtime = JS_NewRuntime(10 * 1024 * 1024, JS_NO_HELPER_THREADS);

    JSContext *cx = JS_NewContext(runtime, 10240);
    JS_SetOptions(cx, JSOPTION_TYPE_INFERENCE);
    
    JS::CompartmentOptions options;
    options.setVersion(JSVERSION_LATEST);
    
    JS::RootedObject global(cx, JS_NewGlobalObject(cx, &GlobalClass, NULL, JS::DontFireOnNewGlobalHook, options));
    
    JS_SetErrorReporter(cx, &ReportError);
    
    {
        JSAutoCompartment ac(cx, global);
    
        if (JS_InitStandardClasses(cx, global)) {
            
            JS_InitReflect(cx, global);
            
            JS_FireOnNewGlobalObject(cx, global);
            
            JS::CompileOptions options(cx);
            options.setUTF8(true);
            options.setSourcePolicy(JS::CompileOptions::NO_SOURCE);
            std::cout << "Compiling ..." << std::endl;
            
            JS::RootedScript script(cx, JS::Compile(cx, global, options, inputFilePath.c_str()));
            
            if (script) {
                void *data = NULL;
                uint32_t length = 0;
                std::cout << "Encoding ..." << std::endl;
                data = JS_EncodeScript(cx, script, &length);
                
                if (data) {
                    if (WriteFile(ofp, data, length)) {
                        std::cout << "Done! " << "Output file: " << ofp << std::endl;
                        result = true;
                    }
                }
            }
            else
            {
                std::cout << "Compiled " << inputFilePath << " fails!" << std::endl;
            }
        }
        else
        {
            std::cout << "JS_InitStandardClasses failed! " << std::endl;
        }
    }
    if (cx) {
        JS_DestroyContext(cx);
        cx = NULL;
    }
    if (runtime) {
        JS_DestroyRuntime(runtime);
        runtime = NULL;
    }
    
    JS_ShutDown();
    
    return result;
}
コード例 #25
0
ファイル: ScriptInterface.cpp プロジェクト: Rektosauros/0ad
void ScriptInterface::ShutDown()
{
	JS_ShutDown();
}
コード例 #26
0
ファイル: sm180.c プロジェクト: draco2003/bigcouch
int
main(int argc, const char* argv[])
{
    JSRuntime* rt = NULL;
    JSContext* cx = NULL;
    JSObject* global = NULL;
    JSObject* klass = NULL;
    JSScript* script;
    JSString* scriptsrc;
    jschar* schars;
    size_t slen;
    jsval sroot;
    jsval result;

    couch_args* args = couch_parse_args(argc, argv);

    rt = JS_NewRuntime(64L * 1024L * 1024L);
    if(rt == NULL)
        return 1;

    cx = JS_NewContext(rt, args->stack_size);
    if(cx == NULL)
        return 1;

    JS_SetErrorReporter(cx, couch_error);
    JS_ToggleOptions(cx, JSOPTION_XML);

    SETUP_REQUEST(cx);

    global = JS_NewObject(cx, &global_class, NULL, NULL);
    if(global == NULL)
        return 1;

    JS_SetGlobalObject(cx, global);

    if(!JS_InitStandardClasses(cx, global))
        return 1;

    if(couch_load_funcs(cx, global, global_functions) != JS_TRUE)
        return 1;

    if(args->use_http) {
        http_check_enabled();

        klass = JS_InitClass(
            cx, global,
            NULL,
            &CouchHTTPClass, req_ctor,
            0,
            CouchHTTPProperties, CouchHTTPFunctions,
            NULL, NULL
        );

        if(!klass)
        {
            fprintf(stderr, "Failed to initialize CouchHTTP class.\n");
            exit(2);
        }
    }

    // Convert script source to jschars.
    scriptsrc = dec_string(cx, args->script, strlen(args->script));
    if(!scriptsrc)
        return 1;

    schars = JS_GetStringChars(scriptsrc);
    slen = JS_GetStringLength(scriptsrc);

    // Root it so GC doesn't collect it.
    sroot = STRING_TO_JSVAL(scriptsrc);
    if(JS_AddRoot(cx, &sroot) != JS_TRUE) {
        fprintf(stderr, "Internal root error.\n");
        return 1;
    }

    // Compile and run
    script = JS_CompileUCScript(cx, global, schars, slen, args->script_name, 1);
    if(!script) {
        fprintf(stderr, "Failed to compile script.\n");
        return 1;
    }

    JS_ExecuteScript(cx, global, script, &result);

    // Warning message if we don't remove it.
    JS_RemoveRoot(cx, &sroot);

    FINISH_REQUEST(cx);
    JS_DestroyContext(cx);
    JS_DestroyRuntime(rt);
    JS_ShutDown();

    return 0;
}
コード例 #27
0
ファイル: XPCOMInit.cpp プロジェクト: Nazi-Nigger/gecko-dev
nsresult
ShutdownXPCOM(nsIServiceManager* aServMgr)
{
  // Make sure the hang monitor is enabled for shutdown.
  HangMonitor::NotifyActivity();

  if (!NS_IsMainThread()) {
    NS_RUNTIMEABORT("Shutdown on wrong thread");
  }

  nsresult rv;
  nsCOMPtr<nsISimpleEnumerator> moduleLoaders;

  // Notify observers of xpcom shutting down
  {
    // Block it so that the COMPtr will get deleted before we hit
    // servicemanager shutdown

    nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
    if (NS_WARN_IF(!thread)) {
      return NS_ERROR_UNEXPECTED;
    }

    RefPtr<nsObserverService> observerService;
    CallGetService("@mozilla.org/observer-service;1",
                   (nsObserverService**)getter_AddRefs(observerService));

    if (observerService) {
      observerService->NotifyObservers(nullptr,
                                       NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID,
                                       nullptr);

      nsCOMPtr<nsIServiceManager> mgr;
      rv = NS_GetServiceManager(getter_AddRefs(mgr));
      if (NS_SUCCEEDED(rv)) {
        observerService->NotifyObservers(mgr, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
                                         nullptr);
      }
    }

    // This must happen after the shutdown of media and widgets, which
    // are triggered by the NS_XPCOM_SHUTDOWN_OBSERVER_ID notification.
    NS_ProcessPendingEvents(thread);
    gfxPlatform::ShutdownLayersIPC();

    mozilla::scache::StartupCache::DeleteSingleton();
    if (observerService)
      observerService->NotifyObservers(nullptr,
                                       NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID,
                                       nullptr);

    gXPCOMThreadsShutDown = true;
    NS_ProcessPendingEvents(thread);

    // Shutdown the timer thread and all timers that might still be alive before
    // shutting down the component manager
    nsTimerImpl::Shutdown();

    NS_ProcessPendingEvents(thread);

    // Shutdown all remaining threads.  This method does not return until
    // all threads created using the thread manager (with the exception of
    // the main thread) have exited.
    nsThreadManager::get()->Shutdown();

    NS_ProcessPendingEvents(thread);

    HangMonitor::NotifyActivity();

    // Late-write checks needs to find the profile directory, so it has to
    // be initialized before mozilla::services::Shutdown or (because of
    // xpcshell tests replacing the service) modules being unloaded.
    mozilla::InitLateWriteChecks();

    // We save the "xpcom-shutdown-loaders" observers to notify after
    // the observerservice is gone.
    if (observerService) {
      observerService->EnumerateObservers(NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
                                          getter_AddRefs(moduleLoaders));

      observerService->Shutdown();
    }
  }

  // Free ClearOnShutdown()'ed smart pointers.  This needs to happen *after*
  // we've finished notifying observers of XPCOM shutdown, because shutdown
  // observers themselves might call ClearOnShutdown().
  mozilla::KillClearOnShutdown();

  // XPCOM is officially in shutdown mode NOW
  // Set this only after the observers have been notified as this
  // will cause servicemanager to become inaccessible.
  mozilla::services::Shutdown();

#ifdef DEBUG_dougt
  fprintf(stderr, "* * * * XPCOM shutdown. Access will be denied * * * * \n");
#endif
  // We may have AddRef'd for the caller of NS_InitXPCOM, so release it
  // here again:
  NS_IF_RELEASE(aServMgr);

  // Shutdown global servicemanager
  if (nsComponentManagerImpl::gComponentManager) {
    nsComponentManagerImpl::gComponentManager->FreeServices();
  }

  // Release the directory service
  NS_IF_RELEASE(nsDirectoryService::gService);

  free(gGREBinPath);
  gGREBinPath = nullptr;

  if (moduleLoaders) {
    bool more;
    nsCOMPtr<nsISupports> el;
    while (NS_SUCCEEDED(moduleLoaders->HasMoreElements(&more)) && more) {
      moduleLoaders->GetNext(getter_AddRefs(el));

      // Don't worry about weak-reference observers here: there is
      // no reason for weak-ref observers to register for
      // xpcom-shutdown-loaders

      // FIXME: This can cause harmless writes from sqlite committing
      // log files. We have to ignore them before we can move
      // the mozilla::PoisonWrite call before this point. See bug
      // 834945 for the details.
      nsCOMPtr<nsIObserver> obs(do_QueryInterface(el));
      if (obs) {
        obs->Observe(nullptr, NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID, nullptr);
      }
    }

    moduleLoaders = nullptr;
  }

  nsCycleCollector_shutdown();

  layers::AsyncTransactionTrackersHolder::Finalize();

  PROFILER_MARKER("Shutdown xpcom");
  // If we are doing any shutdown checks, poison writes.
  if (gShutdownChecks != SCM_NOTHING) {
#ifdef XP_MACOSX
    mozilla::OnlyReportDirtyWrites();
#endif /* XP_MACOSX */
    mozilla::BeginLateWriteChecks();
  }

  // Shutdown nsLocalFile string conversion
  NS_ShutdownLocalFile();
#ifdef XP_UNIX
  NS_ShutdownNativeCharsetUtils();
#endif

#if defined(XP_WIN)
  // This exit(0) call is intended to be temporary, to get shutdown leak
  // checking working on Linux.
  // On Windows XP debug, there are intermittent failures in
  // dom/media/tests/mochitest/test_peerConnection_basicH264Video.html
  // if we don't exit early in a child process. See bug 1073310.
  if (XRE_IsContentProcess() && !IsVistaOrLater()) {
      NS_WARNING("Exiting child process early!");
      exit(0);
  }
#endif

  // Shutdown xpcom. This will release all loaders and cause others holding
  // a refcount to the component manager to release it.
  if (nsComponentManagerImpl::gComponentManager) {
    rv = (nsComponentManagerImpl::gComponentManager)->Shutdown();
    NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
  } else {
    NS_WARNING("Component Manager was never created ...");
  }

#ifdef MOZ_ENABLE_PROFILER_SPS
  // In optimized builds we don't do shutdown collections by default, so
  // uncollected (garbage) objects may keep the nsXPConnect singleton alive,
  // and its XPCJSRuntime along with it. However, we still destroy various
  // bits of state in JS_ShutDown(), so we need to make sure the profiler
  // can't access them when it shuts down. This call nulls out the
  // JS pseudo-stack's internal reference to the main thread JSRuntime,
  // duplicating the call in XPCJSRuntime::~XPCJSRuntime() in case that
  // never fired.
  if (PseudoStack* stack = mozilla_get_pseudo_stack()) {
    stack->sampleRuntime(nullptr);
  }
#endif

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

  // Release our own singletons
  // Do this _after_ shutting down the component manager, because the
  // JS component loader will use XPConnect to call nsIModule::canUnload,
  // and that will spin up the InterfaceInfoManager again -- bad mojo
  XPTInterfaceInfoManager::FreeInterfaceInfoManager();

  // Finally, release the component manager last because it unloads the
  // libraries:
  if (nsComponentManagerImpl::gComponentManager) {
    nsrefcnt cnt;
    NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
    NS_ASSERTION(cnt == 0, "Component Manager being held past XPCOM shutdown.");
  }
  nsComponentManagerImpl::gComponentManager = nullptr;
  nsCategoryManager::Destroy();

  NS_PurgeAtomTable();

  NS_IF_RELEASE(gDebug);

  delete sIOThread;
  sIOThread = nullptr;

  delete sMessageLoop;
  sMessageLoop = nullptr;

  if (sCommandLineWasInitialized) {
    CommandLine::Terminate();
    sCommandLineWasInitialized = false;
  }

  delete sExitManager;
  sExitManager = nullptr;

  Omnijar::CleanUp();

  HangMonitor::Shutdown();

  delete sMainHangMonitor;
  sMainHangMonitor = nullptr;

  BackgroundHangMonitor::Shutdown();

  profiler_shutdown();

  NS_LogTerm();

#if defined(MOZ_WIDGET_GONK)
  // This exit(0) call is intended to be temporary, to get shutdown leak
  // checking working on Linux.
  // On debug B2G, the child process crashes very late.  Instead, just
  // give up so at least we exit cleanly. See bug 1071866.
  if (XRE_IsContentProcess()) {
      NS_WARNING("Exiting child process early!");
      exit(0);
  }
#endif

  return NS_OK;
}
コード例 #28
0
void sm_shutdown() {
  JS_ShutDown();
}
コード例 #29
0
    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;
    }
コード例 #30
0
ファイル: jsrunner.c プロジェクト: mikemb/Thwonk
/*
 * Purpose: Carry out rule running in this spun off thread
 *
 * Entry:
 * 	1st - Queue entry
 *
 * Exit:
 *	SUCCESS = ERR_NONE
 * 	FAILURE = ERR_* (type of error)
*/
ERRTYPE spawnRuleRunner(Queue_Entry *qentry) {
	JSObject *script = NULL;
	JSRuntime *rt = NULL;
	JSContext *cx = NULL;
	JSBool ret;
	JSObject *global;
	jsval rval;
	Logic_Entry *lentry;

	if((lentry = getLogicEntryForVoid(qentry->voidId)) == NULL) {
		printf("logic 2\r\n");
		return ERR_NONE;
	}

	rt = JS_NewRuntime(SPIDERMONKEY_ALLOC_RAM);

	if(rt == NULL) {
		return ERR_UNKNOWN;
	}

	/*
	 * 8192 = size of each stack chunk (not stack size)
	 *
	 * Apparently this is an internal variable in spidermonkey
	 * that shouldn't be tweaked without knowing a lot about
	 * spidermonkey's garbage collection.
	*/
	cx = JS_NewContext(rt, 8192);

	if(cx == NULL) {
		JS_DestroyRuntime(rt);
		return ERR_UNKNOWN;
	}

	JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_COMPILE_N_GO); // JSOPTION_METHODJIT
	JS_SetVersion(cx, JSVERSION_LATEST);

	JS_SetErrorReporter(cx, jsErrorHandler);

	// Create the global object in a new compartment. See http://developer.mozilla.org/En/SpiderMonkey/JSAPI_User_Guide#Native_functions
	global = JS_NewCompartmentAndGlobalObject(cx, &js_global_object_class, NULL);

    	if (global == NULL) {
		JS_DestroyContext(cx);
		JS_DestroyRuntime(rt);
		return ERR_UNKNOWN;
	}

	if(JS_InitStandardClasses(cx, global) == false) {
		JS_DestroyContext(cx);
		JS_DestroyRuntime(rt);
		return ERR_UNKNOWN;
	}

	createJSObjectThwonk(cx, global, qentry);

	script = JS_CompileScript(cx, global, lentry->logic, strlen(lentry->logic), "<inline>", 0);

	if(script == NULL) {
		// TODO: Log error to database for script writer to see
		printf("Couldn't compiled the script\n");
		JS_DestroyContext(cx);
		JS_DestroyRuntime(rt);
		return ERR_UNKNOWN;
	}

	ret = JS_ExecuteScript(cx, global, script, &rval);
 
	if(ret == JS_FALSE) {
		// TODO: Log error to database for script writer to see
		printf("Failed to run compiled script.\n");
		JS_DestroyContext(cx);
		JS_DestroyRuntime(rt);
		return ERR_UNKNOWN;
	}

//	str = JS_ValueToString(cx, rval);

//	printf("script result: %s\n", JS_GetStringBytes(str));

	JS_DestroyContext(cx);
	JS_DestroyRuntime(rt);
	JS_ShutDown();		// Is this needed since thread is ending on return from this function?

	return ERR_NONE;
}