Skip to content

Commit

Permalink
src: make ModifyCodeGenerationFromStrings more robust
Browse files Browse the repository at this point in the history
1. Fallback to true when the context is not (yet) initialized
   with the kAllowCodeGenerationFromStrings field.
2. Fallback to true when the Environment isn't assigned to
   the context or when the Environment cannot call into
   JavaScript.

PR-URL: #50763
Refs: #50761
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
joyeecheung authored and targos committed Dec 4, 2023
1 parent b281e98 commit 1e7d101
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,18 @@ v8::ModifyCodeGenerationFromStringsResult ModifyCodeGenerationFromStrings(
bool is_code_like) {
HandleScope scope(context->GetIsolate());

if (context->GetNumberOfEmbedderDataFields() <=
ContextEmbedderIndex::kAllowCodeGenerationFromStrings) {
// The context is not (yet) configured by Node.js for this. We don't
// have enough information to make a decision, just allow it which is
// the default.
return {true, {}};
}
Environment* env = Environment::GetCurrent(context);
if (env->source_maps_enabled()) {
if (env == nullptr) {
return {true, {}};
}
if (env->source_maps_enabled() && env->can_call_into_js()) {
// We do not expect the maybe_cache_generated_source_map to throw any more
// exceptions. If it does, just ignore it.
errors::TryCatchScope try_catch(env);
Expand Down

0 comments on commit 1e7d101

Please sign in to comment.