Skip to content

Commit

Permalink
Cleanup maybeAddGcPassForTest more
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Sep 21, 2023
1 parent 630b8aa commit 84d999d
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/workerd/io/worker-entrypoint.c++
Original file line number Diff line number Diff line change
Expand Up @@ -507,36 +507,36 @@ kj::Promise<WorkerInterface::CustomEvent::Result>
return maybeAddGcPassForTest(context, kj::mv(promise));
}

template <typename T>
kj::Promise<T> WorkerEntrypoint::maybeAddGcPassForTest(
IoContext& context, kj::Promise<T> promise) {
#ifdef KJ_DEBUG
kj::Maybe<kj::Own<const Worker>> 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 <typename T>
kj::Promise<T> addGcPassForTest(IoContext& context, kj::Promise<T> promise) {
auto worker = kj::atomicAddRef(context.getWorker());
if constexpr (kj::isSameType<T, void>()) {
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 <typename T>
kj::Promise<T> WorkerEntrypoint::maybeAddGcPassForTest(
IoContext& context, kj::Promise<T> promise) {
#ifdef KJ_DEBUG
if (isPredictableModeForTest()) {
return addGcPassForTest(context, kj::mv(promise));
}
#endif
return kj::mv(promise);
}

} // namespace workerd

0 comments on commit 84d999d

Please sign in to comment.