зеркало из 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) {
|
if (!cx) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
auto destroyCx = MakeScopeExit([cx] { JS_DestroyContext(cx); });
|
||||||
|
|
||||||
UniquePtr<ShellContext> sc = MakeUnique<ShellContext>(cx);
|
UniquePtr<ShellContext> sc = MakeUnique<ShellContext>(cx);
|
||||||
if (!sc) {
|
if (!sc) {
|
||||||
return 1;
|
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_SetContextPrivate(cx, sc.get());
|
||||||
JS_SetGrayGCRootsTracer(cx, TraceGrayRoots, nullptr);
|
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.
|
// Waiting is allowed on the shell's main thread, for now.
|
||||||
JS_SetFutexCanWait(cx);
|
JS_SetFutexCanWait(cx);
|
||||||
JS::SetWarningReporter(cx, WarningReporter);
|
JS::SetWarningReporter(cx, WarningReporter);
|
||||||
|
@ -11230,6 +11242,13 @@ int main(int argc, char** argv, char** envp) {
|
||||||
|
|
||||||
js::UseInternalJobQueues(cx);
|
js::UseInternalJobQueues(cx);
|
||||||
|
|
||||||
|
auto shutdownShellThreads = MakeScopeExit([cx] {
|
||||||
|
KillWatchdog(cx);
|
||||||
|
KillWorkerThreads(cx);
|
||||||
|
DestructSharedObjectMailbox();
|
||||||
|
CancelOffThreadJobsForRuntime(cx);
|
||||||
|
});
|
||||||
|
|
||||||
if (const char* opt = op.getStringOption("nursery-strings")) {
|
if (const char* opt = op.getStringOption("nursery-strings")) {
|
||||||
if (strcmp(opt, "on") == 0) {
|
if (strcmp(opt, "on") == 0) {
|
||||||
cx->runtime()->gc.nursery().enableStrings();
|
cx->runtime()->gc.nursery().enableStrings();
|
||||||
|
@ -11275,21 +11294,5 @@ int main(int argc, char** argv, char** envp) {
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче