@@ -77,6 +77,7 @@ using v8::Uint32;
77
77
using v8::UnboundScript;
78
78
using v8::Value;
79
79
using v8::WeakCallbackInfo;
80
+ using v8::WeakCallbackType;
80
81
81
82
// The vm module executes code in a sandboxed environment with a different
82
83
// global object than the rest of the code. This is achieved by applying
@@ -1262,7 +1263,8 @@ void ContextifyContext::CompileFunction(
1262
1263
context).ToLocal (&cache_key)) {
1263
1264
return ;
1264
1265
}
1265
- new CompiledFnEntry (env, cache_key, id, fn);
1266
+ CompiledFnEntry* entry = new CompiledFnEntry (env, cache_key, id, fn);
1267
+ env->id_to_function_map .emplace (id, entry);
1266
1268
1267
1269
Local<Object> result = Object::New (isolate);
1268
1270
if (result->Set (parsing_context, env->function_string (), fn).IsNothing ())
@@ -1294,18 +1296,23 @@ void ContextifyContext::CompileFunction(
1294
1296
args.GetReturnValue ().Set (result);
1295
1297
}
1296
1298
1299
+ void CompiledFnEntry::WeakCallback (
1300
+ const WeakCallbackInfo<CompiledFnEntry>& data) {
1301
+ CompiledFnEntry* entry = data.GetParameter ();
1302
+ delete entry;
1303
+ }
1304
+
1297
1305
CompiledFnEntry::CompiledFnEntry (Environment* env,
1298
1306
Local<Object> object,
1299
1307
uint32_t id,
1300
1308
Local<Function> fn)
1301
- : BaseObject(env, object), id_(id) {
1302
- MakeWeak ();
1303
- fn->SetPrivate (env->context (), env->compiled_function_entry (), object);
1304
- env->id_to_function_map .emplace (id, this );
1309
+ : BaseObject(env, object), id_(id), fn_(env->isolate (), fn) {
1310
+ fn_.SetWeak (this , WeakCallback, v8::WeakCallbackType::kParameter );
1305
1311
}
1306
1312
1307
1313
CompiledFnEntry::~CompiledFnEntry () {
1308
1314
env ()->id_to_function_map .erase (id_);
1315
+ fn_.ClearWeak ();
1309
1316
}
1310
1317
1311
1318
static void StartSigintWatchdog (const FunctionCallbackInfo<Value>& args) {
0 commit comments