diff --git a/src/workerd/io/worker-entrypoint.c++ b/src/workerd/io/worker-entrypoint.c++ index e06af17ad00..e0c7ded01a7 100644 --- a/src/workerd/io/worker-entrypoint.c++ +++ b/src/workerd/io/worker-entrypoint.c++ @@ -507,36 +507,36 @@ kj::Promise return maybeAddGcPassForTest(context, kj::mv(promise)); } -template -kj::Promise WorkerEntrypoint::maybeAddGcPassForTest( - IoContext& context, kj::Promise promise) { -#ifdef KJ_DEBUG - kj::Maybe> worker; - if (isPredictableModeForTest()) { - worker = kj::atomicAddRef(context.getWorker()); - } - - static auto constexpr maybeRequestGc = [](auto& worker) { - if (isPredictableModeForTest()) { - jsg::V8StackScope stackScope; - auto lock = KJ_ASSERT_NONNULL(worker)->getIsolate().getApiIsolate().lock(stackScope); - lock->requestGcForTesting(); - } - }; -#endif // KJ_DEBUG +namespace { +void requestGc(const Worker& worker) { + jsg::V8StackScope stackScope; + auto lock = worker.getIsolate().getApiIsolate().lock(stackScope); + lock->requestGcForTesting(); +} +template +kj::Promise addGcPassForTest(IoContext& context, kj::Promise promise) { + auto worker = kj::atomicAddRef(context.getWorker()); if constexpr (kj::isSameType()) { co_await promise; -#ifdef KJ_DEBUG - maybeRequestGc(worker); -#endif // KJ_DEBUG + requestGc(*worker); } else { auto ret = co_await promise; -#ifdef KJ_DEBUG - maybeRequestGc(worker); -#endif // KJ_DEBUG + requestGc(*worker); co_return kj::mv(ret); } } +} // namespace + +template +kj::Promise WorkerEntrypoint::maybeAddGcPassForTest( + IoContext& context, kj::Promise promise) { +#ifdef KJ_DEBUG + if (isPredictableModeForTest()) { + return addGcPassForTest(context, kj::mv(promise)); + } +#endif + return kj::mv(promise); +} } // namespace workerd