@@ -1501,24 +1501,22 @@ void ContextifyContext::CompileFunction(
15011501 }
15021502
15031503 TryCatchScope try_catch (env);
1504- Local<Object> result = CompileFunctionAndCacheResult (env,
1505- parsing_context,
1506- &source,
1507- params,
1508- context_extensions,
1509- options,
1510- produce_cached_data,
1511- id_symbol,
1512- try_catch);
1513-
1514- if (try_catch.HasCaught () && !try_catch.HasTerminated ()){
1504+ MaybeLocal<Object> maybe_result =
1505+ CompileFunctionAndCacheResult (env,
1506+ parsing_context,
1507+ &source,
1508+ params,
1509+ context_extensions,
1510+ options,
1511+ produce_cached_data,
1512+ id_symbol,
1513+ try_catch);
1514+ Local<Object> result;
1515+ if (!maybe_result.ToLocal (&result)){
1516+ CHECK (try_catch.HasCaught ());
15151517 try_catch.ReThrow ();
15161518return ;
15171519 }
1518-
1519- if (result.IsEmpty ()){
1520- return ;
1521- }
15221520 args.GetReturnValue ().Set (result);
15231521}
15241522
@@ -1534,7 +1532,7 @@ static LocalVector<String> GetCJSParameters(IsolateData* data){
15341532return result;
15351533}
15361534
1537- Local <Object> ContextifyContext::CompileFunctionAndCacheResult (
1535+ MaybeLocal <Object> ContextifyContext::CompileFunctionAndCacheResult (
15381536 Environment* env,
15391537 Local<Context> parsing_context,
15401538 ScriptCompiler::Source* source,
@@ -1556,28 +1554,29 @@ Local<Object> ContextifyContext::CompileFunctionAndCacheResult(
15561554
15571555 Local<Function> fn;
15581556if (!maybe_fn.ToLocal (&fn)){
1559- if (try_catch.HasCaught () && !try_catch.HasTerminated ()){
1557+ CHECK (try_catch.HasCaught ());
1558+ if (!try_catch.HasTerminated ()){
15601559errors::DecorateErrorStack (env, try_catch);
1561- return Object::New (env->isolate ());
15621560 }
1561+ return {};
15631562 }
15641563
15651564 Local<Context> context = env->context ();
15661565if (fn->SetPrivate (context, env->host_defined_option_symbol (), id_symbol)
15671566 .IsNothing ()){
1568- return Object::New (env-> isolate ()) ;
1567+ return {} ;
15691568 }
15701569
15711570 Isolate* isolate = env->isolate ();
15721571 Local<Object> result = Object::New (isolate);
15731572if (result->Set (parsing_context, env->function_string (), fn).IsNothing ())
1574- return Object::New (env-> isolate ()) ;
1573+ return {} ;
15751574if (result
15761575 ->Set (parsing_context,
15771576 env->source_map_url_string (),
15781577 fn->GetScriptOrigin ().SourceMapUrl ())
15791578 .IsNothing ())
1580- return Object::New (env-> isolate ()) ;
1579+ return {} ;
15811580
15821581 std::unique_ptr<ScriptCompiler::CachedData> new_cached_data;
15831582if (produce_cached_data){
@@ -1590,7 +1589,7 @@ Local<Object> ContextifyContext::CompileFunctionAndCacheResult(
15901589 produce_cached_data,
15911590std::move (new_cached_data))
15921591 .IsNothing ()){
1593- return Object::New (env-> isolate ()) ;
1592+ return {} ;
15941593 }
15951594
15961595return result;
0 commit comments