@@ -66,6 +66,7 @@ using v8::PropertyHandlerFlags;
6666using v8::Script;
6767using v8::ScriptCompiler;
6868using v8::ScriptOrigin;
69+ using v8::ScriptOrModule;
6970using v8::String;
7071using v8::Symbol;
7172using v8::Uint32;
@@ -305,15 +306,6 @@ void ContextifyContext::WeakCallback(
305306 delete context;
306307}
307308
308- void ContextifyContext::WeakCallbackCompileFn (
309- const WeakCallbackInfo<CompileFnEntry>& data) {
310- CompileFnEntry* entry = data.GetParameter ();
311- if (entry->env ->compile_fn_entries .erase (entry) != 0 ) {
312- entry->env ->id_to_function_map .erase (entry->id );
313- delete entry;
314- }
315- }
316-
317309// static
318310ContextifyContext* ContextifyContext::ContextFromContextifiedSandbox (
319311 Environment* env,
@@ -1117,9 +1109,11 @@ void ContextifyContext::CompileFunction(
11171109 }
11181110 }
11191111
1112+ Local<ScriptOrModule> script;
11201113 MaybeLocal<Function> maybe_fn = ScriptCompiler::CompileFunctionInContext (
11211114 parsing_context, &source, params.size (), params.data (),
1122- context_extensions.size (), context_extensions.data (), options);
1115+ context_extensions.size (), context_extensions.data (), options,
1116+ v8::ScriptCompiler::NoCacheReason::kNoCacheNoReason , &script);
11231117
11241118 if (maybe_fn.IsEmpty ()) {
11251119 if (try_catch.HasCaught () && !try_catch.HasTerminated ()) {
@@ -1129,13 +1123,17 @@ void ContextifyContext::CompileFunction(
11291123 return ;
11301124 }
11311125 Local<Function> fn = maybe_fn.ToLocalChecked ();
1132- env->id_to_function_map .emplace (std::piecewise_construct,
1133- std::make_tuple (id),
1134- std::make_tuple (isolate, fn));
1135- CompileFnEntry* gc_entry = new CompileFnEntry (env, id);
1136- env->id_to_function_map [id].SetWeak (gc_entry,
1137- WeakCallbackCompileFn,
1138- v8::WeakCallbackType::kParameter );
1126+
1127+ CompiledFnEntry* entry = new CompiledFnEntry (env, id, script);
1128+ env->id_to_function_map .emplace (id, entry);
1129+ Local<Object> cache_key = entry->cache_key .Get (isolate);
1130+
1131+ Local<Object> result = Object::New (isolate);
1132+ if (result->Set (parsing_context, env->function_string (), fn).IsNothing ())
1133+ return ;
1134+ if (result->Set (parsing_context, env->cache_key_string (), cache_key)
1135+ .IsNothing ())
1136+ return ;
11391137
11401138 if (produce_cached_data) {
11411139 const std::unique_ptr<ScriptCompiler::CachedData> cached_data (
@@ -1146,18 +1144,22 @@ void ContextifyContext::CompileFunction(
11461144 env,
11471145 reinterpret_cast <const char *>(cached_data->data ),
11481146 cached_data->length );
1149- if (fn->Set (
1150- parsing_context,
1151- env->cached_data_string (),
1152- buf.ToLocalChecked ()).IsNothing ()) return ;
1147+ if (result
1148+ ->Set (parsing_context,
1149+ env->cached_data_string (),
1150+ buf.ToLocalChecked ())
1151+ .IsNothing ())
1152+ return ;
11531153 }
1154- if (fn->Set (
1155- parsing_context,
1156- env->cached_data_produced_string (),
1157- Boolean::New (isolate, cached_data_produced)).IsNothing ()) return ;
1154+ if (result
1155+ ->Set (parsing_context,
1156+ env->cached_data_produced_string (),
1157+ Boolean::New (isolate, cached_data_produced))
1158+ .IsNothing ())
1159+ return ;
11581160 }
11591161
1160- args.GetReturnValue ().Set (fn );
1162+ args.GetReturnValue ().Set (result );
11611163}
11621164
11631165static void StartSigintWatchdog (const FunctionCallbackInfo<Value>& args) {
0 commit comments