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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
joyeecheung authored and richardlau committed Mar 25, 2024
1 parent 37979d7 commit d6f46a4
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 d6f46a4

Please sign in to comment.