-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify instrumentation, store env in jsg::Lock
Rather than persisting the env in Worker::Impl, store it in jsg::Lock so that it is easier to access from places that do not have access to Worker::Impl.
- Loading branch information
Showing
13 changed files
with
115 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "modules.h" | ||
|
||
#include <workerd/jsg/setup.h> | ||
|
||
namespace workerd::api { | ||
|
||
kj::Maybe<jsg::JsObject> EnvModule::getCurrent(jsg::Lock& js) { | ||
auto& key = jsg::IsolateBase::from(js.v8Isolate).getEnvAsyncContextKey(); | ||
KJ_IF_SOME(frame, jsg::AsyncContextFrame::current(js)) { | ||
KJ_IF_SOME(value, frame.get(key)) { | ||
auto handle = value.getHandle(js); | ||
if (handle->IsObject()) { | ||
return jsg::JsObject(handle.As<v8::Object>()); | ||
} | ||
} | ||
} | ||
// If the compat flag is set to disable importable env, then this | ||
// will return nothing. | ||
if (FeatureFlags::get(js).getDisableImportableEnv()) return kj::none; | ||
|
||
// Otherwise, fallback to provide the stored environment. | ||
return js.getWorkerEnv().map([&](const jsg::Value& val) -> jsg::JsObject { | ||
auto handle = val.getHandle(js); | ||
JSG_REQUIRE(handle->IsObject(), TypeError, "Expected environment to be an object."); | ||
return jsg::JsObject(handle.As<v8::Object>()); | ||
}); | ||
} | ||
|
||
jsg::JsValue EnvModule::withEnv( | ||
jsg::Lock& js, jsg::Value newEnv, jsg::Function<jsg::JsValue()> fn) { | ||
auto& key = jsg::IsolateBase::from(js.v8Isolate).getEnvAsyncContextKey(); | ||
jsg::AsyncContextFrame::StorageScope storage(js, key, kj::mv(newEnv)); | ||
return fn(js); | ||
} | ||
|
||
} // namespace workerd::api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.