From 1e7d101428e8098a12b9004c21e465958ba664da Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 4 Dec 2023 13:29:39 +0100 Subject: [PATCH] src: make ModifyCodeGenerationFromStrings more robust MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/50763 Refs: https://github.com/nodejs/node/issues/50761 Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: James M Snell Reviewed-By: Chengzhong Wu --- src/node_errors.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index 4dfecbaa5a94f7..50618e6c716f0b 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -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);