@@ -55,7 +55,10 @@ ModuleWrap::ModuleWrap(Environment* env,
55
55
Local<String> url,
56
56
Local<Object> context_object,
57
57
Local<Value> synthetic_evaluation_step)
58
- : BaseObject(env, object), module_(env->isolate (), module) {
58
+ : BaseObject(env, object),
59
+ module_ (env->isolate (), module),
60
+ module_hash_(module->GetIdentityHash ()) {
61
+ object->SetInternalField (kModuleSlot , module);
59
62
object->SetInternalField (kURLSlot , url);
60
63
object->SetInternalField (kSyntheticEvaluationStepsSlot ,
61
64
synthetic_evaluation_step);
@@ -65,12 +68,12 @@ ModuleWrap::ModuleWrap(Environment* env,
65
68
synthetic_ = true ;
66
69
}
67
70
MakeWeak ();
71
+ module_.SetWeak ();
68
72
}
69
73
70
74
ModuleWrap::~ModuleWrap () {
71
75
HandleScope scope (env ()->isolate ());
72
- Local<Module> module = module_.Get (env ()->isolate ());
73
- auto range = env ()->hash_to_module_map .equal_range (module->GetIdentityHash ());
76
+ auto range = env ()->hash_to_module_map .equal_range (module_hash_);
74
77
for (auto it = range.first ; it != range.second ; ++it) {
75
78
if (it->second == this ) {
76
79
env ()->hash_to_module_map .erase (it);
0 commit comments