зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1534776 - Don't leak the world if the shell's main() exits early. r=jwalden
This changes the order of some cleanup operations, harmlessly, to make initialization and teardown more FIFO. Differential Revision: https://phabricator.services.mozilla.com/D23222 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
b143cd0aa1
Коммит
c7cc4c6c91
|
@ -11181,14 +11181,26 @@ int main(int argc, char** argv, char** envp) {
|
|||
if (!cx) {
|
||||
return 1;
|
||||
}
|
||||
auto destroyCx = MakeScopeExit([cx] { JS_DestroyContext(cx); });
|
||||
|
||||
UniquePtr<ShellContext> sc = MakeUnique<ShellContext>(cx);
|
||||
if (!sc) {
|
||||
return 1;
|
||||
}
|
||||
auto destroyShellContext = MakeScopeExit([cx, &sc] {
|
||||
// Must clear out some of sc's pointer containers before JS_DestroyContext.
|
||||
sc->markObservers.reset();
|
||||
|
||||
JS_SetContextPrivate(cx, nullptr);
|
||||
sc.reset();
|
||||
});
|
||||
|
||||
JS_SetContextPrivate(cx, sc.get());
|
||||
JS_SetGrayGCRootsTracer(cx, TraceGrayRoots, nullptr);
|
||||
auto resetGrayGCRootsTracer = MakeScopeExit([cx] {
|
||||
JS_SetGrayGCRootsTracer(cx, nullptr, nullptr);
|
||||
});
|
||||
|
||||
// Waiting is allowed on the shell's main thread, for now.
|
||||
JS_SetFutexCanWait(cx);
|
||||
JS::SetWarningReporter(cx, WarningReporter);
|
||||
|
@ -11230,6 +11242,13 @@ int main(int argc, char** argv, char** envp) {
|
|||
|
||||
js::UseInternalJobQueues(cx);
|
||||
|
||||
auto shutdownShellThreads = MakeScopeExit([cx] {
|
||||
KillWatchdog(cx);
|
||||
KillWorkerThreads(cx);
|
||||
DestructSharedObjectMailbox();
|
||||
CancelOffThreadJobsForRuntime(cx);
|
||||
});
|
||||
|
||||
if (const char* opt = op.getStringOption("nursery-strings")) {
|
||||
if (strcmp(opt, "on") == 0) {
|
||||
cx->runtime()->gc.nursery().enableStrings();
|
||||
|
@ -11275,21 +11294,5 @@ int main(int argc, char** argv, char** envp) {
|
|||
}
|
||||
#endif
|
||||
|
||||
JS_SetGrayGCRootsTracer(cx, nullptr, nullptr);
|
||||
|
||||
// Must clear out some of sc's pointer containers before JS_DestroyContext.
|
||||
sc->markObservers.reset();
|
||||
|
||||
KillWatchdog(cx);
|
||||
|
||||
KillWorkerThreads(cx);
|
||||
|
||||
DestructSharedObjectMailbox();
|
||||
|
||||
CancelOffThreadJobsForRuntime(cx);
|
||||
|
||||
JS_SetContextPrivate(cx, nullptr);
|
||||
sc.reset();
|
||||
JS_DestroyContext(cx);
|
||||
return result;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче