| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9a4d21d commit 5250947
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ | |||
| 11 | 11 | #include "node_internals.h" | |
| 12 | 12 | #include "node_options-inl.h" | |
| 13 | 13 | #include "node_process-inl.h" | |
| 14 | + #include "node_shadow_realm.h" | ||
| 14 | 15 | #include "node_v8_platform-inl.h" | |
| 15 | 16 | #include "node_worker.h" | |
| 16 | 17 | #include "req_wrap-inl.h" | |
@@ -226,6 +227,14 @@ void Environment::UntrackContext(Local<Context> context) { | |||
| 226 | 227 | } | |
| 227 | 228 | } | |
| 228 | 229 | ||
| 230 | + void Environment::TrackShadowRealm(shadow_realm::ShadowRealm* realm) { | ||
| 231 | + shadow_realms_.insert(realm); | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + void Environment::UntrackShadowRealm(shadow_realm::ShadowRealm* realm) { | ||
| 235 | + shadow_realms_.erase(realm); | ||
| 236 | + } | ||
| 237 | + | ||
| 229 | 238 | AsyncHooks::DefaultTriggerAsyncIdScope::DefaultTriggerAsyncIdScope( | |
| 230 | 239 | Environment* env, double default_trigger_async_id) | |
| 231 | 240 | : async_hooks_(env->async_hooks()) { | |
@@ -901,6 +910,10 @@ Environment::~Environment() { | |||
| 901 | 910 | addon.Close(); | |
| 902 | 911 | } | |
| 903 | 912 | } | |
| 913 | + | ||
| 914 | + for (auto realm : shadow_realms_) { | ||
| 915 | + realm->OnEnvironmentDestruct(); | ||
| 916 | + } | ||
| 904 | 917 | } | |
| 905 | 918 | ||
| 906 | 919 | void Environment::InitializeLibuv() { | |
@@ -1896,6 +1909,7 @@ void Environment::MemoryInfo(MemoryTracker* tracker) const { | |||
| 1896 | 1909 | tracker->TrackField("timeout_info", timeout_info_); | |
| 1897 | 1910 | tracker->TrackField("tick_info", tick_info_); | |
| 1898 | 1911 | tracker->TrackField("principal_realm", principal_realm_); | |
| 1912 | + tracker->TrackField("shadow_realms", shadow_realms_); | ||
| 1899 | 1913 | ||
| 1900 | 1914 | // FIXME(joyeecheung): track other fields in Environment. | |
| 1901 | 1915 | // Currently MemoryTracker is unable to track these | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,6 +64,9 @@ | |||
| 64 | 64 | ||
| 65 | 65 | namespace node { | |
| 66 | 66 | ||
| 67 | + namespace shadow_realm { | ||
| 68 | + class ShadowRealm; | ||
| 69 | + } | ||
| 67 | 70 | namespace contextify { | |
| 68 | 71 | class ContextifyScript; | |
| 69 | 72 | class CompiledFnEntry; | |
@@ -643,6 +646,8 @@ class Environment : public MemoryRetainer { | |||
| 643 | 646 | const ContextInfo& info); | |
| 644 | 647 | void TrackContext(v8::Local<v8::Context> context); | |
| 645 | 648 | void UntrackContext(v8::Local<v8::Context> context); | |
| 649 | + void TrackShadowRealm(shadow_realm::ShadowRealm* realm); | ||
| 650 | + void UntrackShadowRealm(shadow_realm::ShadowRealm* realm); | ||
| 646 | 651 | ||
| 647 | 652 | void StartProfilerIdleNotifier(); | |
| 648 | 653 | ||
@@ -1020,6 +1025,7 @@ class Environment : public MemoryRetainer { | |||
| 1020 | 1025 | ||
| 1021 | 1026 | size_t async_callback_scope_depth_ = 0; | |
| 1022 | 1027 | std::vector<double> destroy_async_id_list_; | |
| 1028 | + std::unordered_set<shadow_realm::ShadowRealm*> shadow_realms_; | ||
| 1023 | 1029 | ||
| 1024 | 1030 | #if HAVE_INSPECTOR | |
| 1025 | 1031 | std::unique_ptr<profiler::V8CoverageConnection> coverage_connection_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,7 +33,6 @@ void Realm::MemoryInfo(MemoryTracker* tracker) const { | |||
| 33 | 33 | PER_REALM_STRONG_PERSISTENT_VALUES(V) | |
| 34 | 34 | #undef V | |
| 35 | 35 | ||
| 36 | - tracker->TrackField("env", env_); | ||
| 37 | 36 | tracker->TrackField("cleanup_queue", cleanup_queue_); | |
| 38 | 37 | tracker->TrackField("builtins_with_cache", builtins_with_cache); | |
| 39 | 38 | tracker->TrackField("builtins_without_cache", builtins_without_cache); | |
@@ -301,10 +300,6 @@ PrincipalRealm::PrincipalRealm(Environment* env, | |||
| 301 | 300 | } | |
| 302 | 301 | } | |
| 303 | 302 | ||
| 304 | - void PrincipalRealm::MemoryInfo(MemoryTracker* tracker) const { | ||
| 305 | - Realm::MemoryInfo(tracker); | ||
| 306 | - } | ||
| 307 | - | ||
| 308 | 303 | MaybeLocal<Value> PrincipalRealm::BootstrapRealm() { | |
| 309 | 304 | HandleScope scope(isolate_); | |
| 310 | 305 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -165,7 +165,6 @@ class PrincipalRealm : public Realm { | |||
| 165 | 165 | ||
| 166 | 166 | SET_MEMORY_INFO_NAME(PrincipalRealm) | |
| 167 | 167 | SET_SELF_SIZE(PrincipalRealm) | |
| 168 | - void MemoryInfo(MemoryTracker* tracker) const override; | ||
| 169 | 168 | ||
| 170 | 169 | #define V(PropertyName, TypeName) \ | |
| 171 | 170 | v8::Local<TypeName> PropertyName() const override; \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,7 @@ void ShadowRealm::WeakCallback(const v8::WeakCallbackInfo<ShadowRealm>& data) { | |||
| 46 | 46 | ||
| 47 | 47 | ShadowRealm::ShadowRealm(Environment* env) | |
| 48 | 48 | : Realm(env, NewContext(env->isolate()), kShadowRealm) { | |
| 49 | + env->TrackShadowRealm(this); | ||
| 49 | 50 | context_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter); | |
| 50 | 51 | CreateProperties(); | |
| 51 | 52 | } | |
@@ -54,10 +55,15 @@ ShadowRealm::~ShadowRealm() { | |||
| 54 | 55 | while (HasCleanupHooks()) { | |
| 55 | 56 | RunCleanup(); | |
| 56 | 57 | } | |
| 58 | + if (env_ != nullptr) { | ||
| 59 | + env_->UntrackShadowRealm(this); | ||
| 60 | + } | ||
| 57 | 61 | } | |
| 58 | 62 | ||
| 59 | - void ShadowRealm::MemoryInfo(MemoryTracker* tracker) const { | ||
| 60 | - Realm::MemoryInfo(tracker); | ||
| 63 | + void ShadowRealm::OnEnvironmentDestruct() { | ||
| 64 | + CHECK_NOT_NULL(env_); | ||
| 65 | + env_ = nullptr; // This means that the shadow realm has out-lived the | ||
| 66 | + // environment. | ||
| 61 | 67 | } | |
| 62 | 68 | ||
| 63 | 69 | v8::Local<v8::Context> ShadowRealm::context() const { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,6 @@ class ShadowRealm : public Realm { | |||
| 15 | 15 | ||
| 16 | 16 | SET_MEMORY_INFO_NAME(ShadowRealm) | |
| 17 | 17 | SET_SELF_SIZE(ShadowRealm) | |
| 18 | - void MemoryInfo(MemoryTracker* tracker) const override; | ||
| 19 | 18 | ||
| 20 | 19 | v8::Local<v8::Context> context() const override; | |
| 21 | 20 | ||
@@ -25,6 +24,8 @@ class ShadowRealm : public Realm { | |||
| 25 | 24 | PER_REALM_STRONG_PERSISTENT_VALUES(V) | |
| 26 | 25 | #undef V | |
| 27 | 26 | ||
| 27 | + void OnEnvironmentDestruct(); | ||
| 28 | + | ||
| 28 | 29 | protected: | |
| 29 | 30 | v8::MaybeLocal<v8::Value> BootstrapRealm() override; | |
| 30 | 31 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments