Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1511,24 +1511,22 @@ void ContextifyContext::CompileFunction(
}

TryCatchScope try_catch(env);
Local<Object> result = CompileFunctionAndCacheResult(env,
parsing_context,
&source,
params,
context_extensions,
options,
produce_cached_data,
id_symbol,
try_catch);

if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
MaybeLocal<Object> maybe_result =
CompileFunctionAndCacheResult(env,
parsing_context,
&source,
params,
context_extensions,
options,
produce_cached_data,
id_symbol,
try_catch);
Local<Object> result;
if (!maybe_result.ToLocal(&result)) {
CHECK(try_catch.HasCaught());
try_catch.ReThrow();
return;
}

if (result.IsEmpty()) {
return;
}
args.GetReturnValue().Set(result);
}

Expand All @@ -1544,7 +1542,7 @@ static LocalVector<String> GetCJSParameters(IsolateData* data) {
return result;
}

Local<Object> ContextifyContext::CompileFunctionAndCacheResult(
MaybeLocal<Object> ContextifyContext::CompileFunctionAndCacheResult(
Environment* env,
Local<Context> parsing_context,
ScriptCompiler::Source* source,
Expand All @@ -1566,28 +1564,29 @@ Local<Object> ContextifyContext::CompileFunctionAndCacheResult(

Local<Function> fn;
if (!maybe_fn.ToLocal(&fn)) {
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
CHECK(try_catch.HasCaught());
if (!try_catch.HasTerminated()) {
errors::DecorateErrorStack(env, try_catch);
return Object::New(env->isolate());
}
return {};
}

Local<Context> context = env->context();
if (fn->SetPrivate(context, env->host_defined_option_symbol(), id_symbol)
.IsNothing()) {
return Object::New(env->isolate());
return {};
}

Isolate* isolate = env->isolate();
Local<Object> result = Object::New(isolate);
if (result->Set(parsing_context, env->function_string(), fn).IsNothing())
return Object::New(env->isolate());
return {};
if (result
->Set(parsing_context,
env->source_map_url_string(),
fn->GetScriptOrigin().SourceMapUrl())
.IsNothing())
return Object::New(env->isolate());
return {};

std::unique_ptr<ScriptCompiler::CachedData> new_cached_data;
if (produce_cached_data) {
Expand All @@ -1600,7 +1599,7 @@ Local<Object> ContextifyContext::CompileFunctionAndCacheResult(
produce_cached_data,
std::move(new_cached_data))
.IsNothing()) {
return Object::New(env->isolate());
return {};
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/node_contextify.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class ContextifyContext final : CPPGC_MIXIN(ContextifyContext) {
static void IsContext(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CompileFunction(
const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Local<v8::Object> CompileFunctionAndCacheResult(
static v8::MaybeLocal<v8::Object> CompileFunctionAndCacheResult(
Environment* env,
v8::Local<v8::Context> parsing_context,
v8::ScriptCompiler::Source* source,
Expand Down
Loading