@@ -1222,15 +1222,15 @@ void ContextifyContext::CompileFunction(
12221222 false , // is ES Module
12231223 host_defined_options);
12241224
1225- ScriptCompiler::Source source (code, origin, cached_data);
1225+ ScriptCompiler::Source source =
1226+ ScriptCompiler::Source (code, origin, cached_data);
12261227 ScriptCompiler::CompileOptions options;
12271228 if (source.GetCachedData () == nullptr ) {
12281229 options = ScriptCompiler::kNoCompileOptions ;
12291230 } else {
12301231 options = ScriptCompiler::kConsumeCodeCache ;
12311232 }
12321233
1233- TryCatchScope try_catch (env);
12341234 Context::Scope scope (parsing_context);
12351235
12361236 // Read context extensions from buffer
@@ -1255,9 +1255,41 @@ void ContextifyContext::CompileFunction(
12551255 }
12561256 }
12571257
1258+ TryCatchScope try_catch (env);
1259+ Local<Object> result = CompileFunctionAndCacheResult (env,
1260+ parsing_context,
1261+ source,
1262+ params,
1263+ context_extensions,
1264+ options,
1265+ produce_cached_data,
1266+ id_symbol,
1267+ try_catch);
1268+
1269+ if (try_catch.HasCaught () && !try_catch.HasTerminated ()) {
1270+ try_catch.ReThrow ();
1271+ return ;
1272+ }
1273+
1274+ if (result.IsEmpty ()) {
1275+ return ;
1276+ }
1277+ args.GetReturnValue ().Set (result);
1278+ }
1279+
1280+ Local<Object> ContextifyContext::CompileFunctionAndCacheResult (
1281+ Environment* env,
1282+ Local<Context> parsing_context,
1283+ const ScriptCompiler::Source& source,
1284+ std::vector<Local<String>> params,
1285+ std::vector<Local<Object>> context_extensions,
1286+ ScriptCompiler::CompileOptions options,
1287+ bool produce_cached_data,
1288+ Local<Symbol> id_symbol,
1289+ const TryCatchScope& try_catch) {
12581290 MaybeLocal<Function> maybe_fn = ScriptCompiler::CompileFunction (
12591291 parsing_context,
1260- &source,
1292+ const_cast <ScriptCompiler::Source*>( &source) ,
12611293 params.size (),
12621294 params.data (),
12631295 context_extensions.size (),
@@ -1269,24 +1301,26 @@ void ContextifyContext::CompileFunction(
12691301 if (!maybe_fn.ToLocal (&fn)) {
12701302 if (try_catch.HasCaught () && !try_catch.HasTerminated ()) {
12711303 errors::DecorateErrorStack (env, try_catch);
1272- try_catch. ReThrow ( );
1304+ return Object::New (env-> isolate () );
12731305 }
1274- return ;
12751306 }
1307+
1308+ Local<Context> context = env->context ();
12761309 if (fn->SetPrivate (context, env->host_defined_option_symbol (), id_symbol)
12771310 .IsNothing ()) {
1278- return ;
1311+ return Object::New (env-> isolate ()) ;
12791312 }
12801313
1314+ Isolate* isolate = env->isolate ();
12811315 Local<Object> result = Object::New (isolate);
12821316 if (result->Set (parsing_context, env->function_string (), fn).IsNothing ())
1283- return ;
1317+ return Object::New (env-> isolate ()) ;
12841318 if (result
12851319 ->Set (parsing_context,
12861320 env->source_map_url_string (),
12871321 fn->GetScriptOrigin ().SourceMapUrl ())
12881322 .IsNothing ())
1289- return ;
1323+ return Object::New (env-> isolate ()) ;
12901324
12911325 std::unique_ptr<ScriptCompiler::CachedData> new_cached_data;
12921326 if (produce_cached_data) {
@@ -1299,10 +1333,10 @@ void ContextifyContext::CompileFunction(
12991333 produce_cached_data,
13001334 std::move (new_cached_data))
13011335 .IsNothing ()) {
1302- return ;
1336+ return Object::New (env-> isolate ()) ;
13031337 }
13041338
1305- args. GetReturnValue (). Set ( result) ;
1339+ return result;
13061340}
13071341
13081342static void StartSigintWatchdog (const FunctionCallbackInfo<Value>& args) {
0 commit comments