Index: src/d8.cc |
diff --git a/src/d8.cc b/src/d8.cc |
index 32e6636ecb0d9d423e39a15a935e4b4bfb09f258..bd6b7b4fbee90b65c6464701e9630637b4acb349 100644 |
--- a/src/d8.cc |
+++ b/src/d8.cc |
@@ -725,8 +725,12 @@ PerIsolateData::RealmScope::RealmScope(PerIsolateData* data) : data_(data) { |
PerIsolateData::RealmScope::~RealmScope() { |
// Drop realms to avoid keeping them alive. |
- for (int i = 0; i < data_->realm_count_; ++i) |
- data_->realms_[i].Reset(); |
+ for (int i = 0; i < data_->realm_count_; ++i) { |
+ Global<Context>& realm = data_->realms_[i]; |
+ if (realm.IsEmpty()) continue; |
+ DisposeModuleEmbedderData(realm.Get(data_->isolate_)); |
+ realm.Reset(); |
+ } |
delete[] data_->realms_; |
if (!data_->realm_shared_.IsEmpty()) |
data_->realm_shared_.Reset(); |