Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup maybeAddGcPassForTest more #1209

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
jasnell marked this conversation as resolved.
Show resolved Hide resolved
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
Loading