Skip to content

Commit

Permalink
Merge pull request #634 from cloudflare/jsnell/propagate-async-contex…
Browse files Browse the repository at this point in the history
…t-for-dynamic-import
  • Loading branch information
jasnell authored May 11, 2023
2 parents 3933386 + 82cc526 commit 9bd2f70
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/workerd/io/worker.c++
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <workerd/util/thread-scopes.h>
#include <workerd/api/global-scope.h>
#include <workerd/api/streams.h> // for api::StreamEncoding
#include <workerd/jsg/async-context.h>
#include <workerd/jsg/jsg.h>
#include <workerd/jsg/modules.h>
#include <workerd/jsg/util.h>
Expand Down Expand Up @@ -859,14 +860,16 @@ struct Worker::Script::Impl {
auto& worker = ioContext.getWorker();

return ioContext.awaitIo(
kj::evalLater([&worker, handler = kj::mv(handler)]() mutable {
kj::evalLater([&worker, handler = kj::mv(handler),
asyncContext = jsg::AsyncContextFrame::currentRef(js)]() mutable {
return worker.takeAsyncLockWithoutRequest(nullptr)
.then([&worker, handler = kj::mv(handler)]
.then([&worker, handler = kj::mv(handler), asyncContext = kj::mv(asyncContext)]
(Worker::AsyncLock asyncLock) mutable -> DynamicImportResult {
Worker::Lock lock(worker, asyncLock);
auto isolate = lock.getIsolate();
v8::HandleScope scope(isolate);
v8::Context::Scope contextScope(lock.getContext());
jsg::AsyncContextFrame::Scope asyncContextScope(lock, asyncContext);

auto& workerIsolate = worker.getIsolate();

Expand Down

2 comments on commit 9bd2f70

@atifnimran
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ou

@atifnimran
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U

Please # to comment.