// If the thread is suspended, resume it now so that we can dispatch the cleanup tasks below.
if (m_isSuspended)
resume();
ASSERT(!m_stoppedCallback);
m_stoppedCallback = WTF::move(stoppedCallback);
// Ensure that tasks are being handled by thread event loop. If script execution weren't forbidden, a while(1) loop in JS could keep the thread alive forever.
if (globalScope()) {
if (auto* script = globalScope()->script())
script->scheduleExecutionTermination();
if (is<WorkerMainRunLoop>(m_runLoop.get())) {
auto globalScope = std::exchange(m_globalScope, nullptr);