mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
src: improve CompileFunctionAndCacheResult error handling
PR-URL: https://github.com/nodejs/node/pull/58434 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
committed by
Node.js GitHub Bot
parent
97cf38dec6
commit
41e4953832
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
@@ -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) {
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user