Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit c16d618

Browse files
committed
Bug 1517896 - Fix shell context shutdown ordering, r=jonco
--HG-- extra : rebase_source : 530a05250ed4b02206b62d4499fda8cdb5c5462e extra : amend_source : 7f28a75c5d1abea4bc1076c92fa48fae964ae054
1 parent 4896602 commit c16d618

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

js/src/shell/js.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3978,8 +3978,9 @@ static void WorkerMain(WorkerInput* input) {
39783978
auto guard = mozilla::MakeScopeExit([&] {
39793979
CancelOffThreadJobsForContext(cx);
39803980
sc->markObservers.reset();
3981-
JS_DestroyContext(cx);
3981+
JS_SetContextPrivate(cx, nullptr);
39823982
js_delete(sc);
3983+
JS_DestroyContext(cx);
39833984
js_delete(input);
39843985
});
39853986

@@ -10986,6 +10987,8 @@ int main(int argc, char** argv, char** envp) {
1098610987

1098710988
CancelOffThreadJobsForRuntime(cx);
1098810989

10990+
JS_SetContextPrivate(cx, nullptr);
10991+
sc.reset();
1098910992
JS_DestroyContext(cx);
1099010993
return result;
1099110994
}

js/src/vm/JSContext.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,19 @@ void js::DestroyContext(JSContext* cx) {
184184

185185
cx->jobQueue = nullptr;
186186
cx->internalJobQueue = nullptr;
187+
SetContextProfilingStack(cx, nullptr);
188+
189+
JSRuntime* rt = cx->runtime();
187190

188191
// Flush promise tasks executing in helper threads early, before any parts
189192
// of the JSRuntime that might be visible to helper threads are torn down.
190-
cx->runtime()->offThreadPromiseState.ref().shutdown(cx);
193+
rt->offThreadPromiseState.ref().shutdown(cx);
191194

192195
// Destroy the runtime along with its last context.
193-
cx->runtime()->destroyRuntime();
194-
js_delete(cx->runtime());
196+
js::AutoNoteSingleThreadedRegion nochecks;
197+
rt->destroyRuntime();
195198
js_delete_poison(cx);
199+
js_delete_poison(rt);
196200
}
197201

198202
void JS::RootingContext::checkNoGCRooters() {

0 commit comments

Comments
 (0)