Skip to content

Commit d6f46a4

Browse files
joyeecheungrichardlau
authored andcommitted
src: make ModifyCodeGenerationFromStrings more robust
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]>
1 parent 37979d7 commit d6f46a4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/node_errors.cc

+11-1
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,18 @@ v8::ModifyCodeGenerationFromStringsResult ModifyCodeGenerationFromStrings(
608608
bool is_code_like) {
609609
HandleScope scope(context->GetIsolate());
610610

611+
if (context->GetNumberOfEmbedderDataFields() <=
612+
ContextEmbedderIndex::kAllowCodeGenerationFromStrings) {
613+
// The context is not (yet) configured by Node.js for this. We don't
614+
// have enough information to make a decision, just allow it which is
615+
// the default.
616+
return {true, {}};
617+
}
611618
Environment* env = Environment::GetCurrent(context);
612-
if (env->source_maps_enabled()) {
619+
if (env == nullptr) {
620+
return {true, {}};
621+
}
622+
if (env->source_maps_enabled() && env->can_call_into_js()) {
613623
// We do not expect the maybe_cache_generated_source_map to throw any more
614624
// exceptions. If it does, just ignore it.
615625
errors::TryCatchScope try_catch(env);

0 commit comments

Comments
 (0)