@@ -488,7 +488,7 @@ Environment* CreateEnvironment(
488488 CHECK (!context.IsEmpty ());
489489 Context::Scope context_scope (context);
490490
491- if (InitializeContextRuntime (context).IsNothing ()) {
491+ if (InitializeContextRuntime (context, isolate_data ).IsNothing ()) {
492492 FreeEnvironment (env);
493493 return nullptr ;
494494 }
@@ -669,11 +669,12 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context,
669669// InitializeContext, because embedders don't necessarily
670670// call NewContext and so they will experience breakages.
671671Local<Context> NewContext (Isolate* isolate,
672- Local<ObjectTemplate> object_template) {
672+ Local<ObjectTemplate> object_template,
673+ IsolateData* isolate_data) {
673674 auto context = Context::New (isolate, nullptr , object_template);
674675 if (context.IsEmpty ()) return context;
675676
676- if (InitializeContext (context).IsNothing ()) {
677+ if (InitializeContext (context, isolate_data ).IsNothing ()) {
677678 return Local<Context>();
678679 }
679680
@@ -686,7 +687,8 @@ void ProtoThrower(const FunctionCallbackInfo<Value>& info) {
686687
687688// This runs at runtime, regardless of whether the context
688689// is created from a snapshot.
689- Maybe<void > InitializeContextRuntime (Local<Context> context) {
690+ Maybe<void > InitializeContextRuntime (Local<Context> context,
691+ IsolateData* isolate_data) {
690692 Isolate* isolate = Isolate::GetCurrent ();
691693 HandleScope handle_scope (isolate);
692694
@@ -698,6 +700,18 @@ Maybe<void> InitializeContextRuntime(Local<Context> context) {
698700 // to the runtime flags, propagate the value to the embedder data.
699701 bool is_code_generation_from_strings_allowed =
700702 context->IsCodeGenerationFromStringsAllowed ();
703+
704+ // Check if the Node.js option --disallow-code-generation-from-strings is set
705+ // Use the isolate-specific options if available, otherwise use per_process
706+ bool disallow_codegen = isolate_data
707+ ? isolate_data->options ()->disallow_code_generation_from_strings
708+ : per_process::cli_options->per_isolate
709+ ->disallow_code_generation_from_strings ;
710+
711+ if (disallow_codegen) {
712+ is_code_generation_from_strings_allowed = false ;
713+ }
714+
701715 context->AllowCodeGenerationFromStrings (false );
702716 context->SetEmbedderData (
703717 ContextEmbedderIndex::kAllowCodeGenerationFromStrings ,
@@ -921,12 +935,13 @@ Maybe<void> InitializePrimordials(Local<Context> context,
921935}
922936
923937// This initializes the main context (i.e. vm contexts are not included).
924- Maybe<bool > InitializeContext (Local<Context> context) {
938+ Maybe<bool > InitializeContext (Local<Context> context,
939+ IsolateData* isolate_data) {
925940 if (InitializeMainContextForSnapshot (context).IsNothing ()) {
926941 return Nothing<bool >();
927942 }
928943
929- if (InitializeContextRuntime (context).IsNothing ()) {
944+ if (InitializeContextRuntime (context, isolate_data ).IsNothing ()) {
930945 return Nothing<bool >();
931946 }
932947 return Just (true );
0 commit comments