@@ -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 }
@@ -670,10 +670,16 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context,
670670// call NewContext and so they will experience breakages.
671671Local<Context> NewContext (Isolate* isolate,
672672 Local<ObjectTemplate> object_template) {
673+ return NewContext (isolate, object_template, nullptr );
674+ }
675+
676+ Local<Context> NewContext (Isolate* isolate,
677+ Local<ObjectTemplate> object_template,
678+ IsolateData* isolate_data) {
673679 auto context = Context::New (isolate, nullptr , object_template);
674680 if (context.IsEmpty ()) return context;
675681
676- if (InitializeContext (context).IsNothing ()) {
682+ if (InitializeContext (context, isolate_data ).IsNothing ()) {
677683 return Local<Context>();
678684 }
679685
@@ -686,7 +692,8 @@ void ProtoThrower(const FunctionCallbackInfo<Value>& info) {
686692
687693// This runs at runtime, regardless of whether the context
688694// is created from a snapshot.
689- Maybe<void > InitializeContextRuntime (Local<Context> context) {
695+ Maybe<void > InitializeContextRuntime (Local<Context> context,
696+ IsolateData* isolate_data) {
690697 Isolate* isolate = Isolate::GetCurrent ();
691698 HandleScope handle_scope (isolate);
692699
@@ -698,6 +705,18 @@ Maybe<void> InitializeContextRuntime(Local<Context> context) {
698705 // to the runtime flags, propagate the value to the embedder data.
699706 bool is_code_generation_from_strings_allowed =
700707 context->IsCodeGenerationFromStringsAllowed ();
708+
709+ // Check if the Node.js option --disallow-code-generation-from-strings is set
710+ // Use isolate_data if provided, otherwise fall back to per_process options
711+ if (isolate_data != nullptr &&
712+ isolate_data->options ()->disallow_code_generation_from_strings ) {
713+ is_code_generation_from_strings_allowed = false ;
714+ } else if (isolate_data == nullptr &&
715+ per_process::cli_options->per_isolate
716+ ->disallow_code_generation_from_strings ) {
717+ is_code_generation_from_strings_allowed = false ;
718+ }
719+
701720 context->AllowCodeGenerationFromStrings (false );
702721 context->SetEmbedderData (
703722 ContextEmbedderIndex::kAllowCodeGenerationFromStrings ,
@@ -922,11 +941,16 @@ Maybe<void> InitializePrimordials(Local<Context> context,
922941
923942// This initializes the main context (i.e. vm contexts are not included).
924943Maybe<bool > InitializeContext (Local<Context> context) {
944+ return InitializeContext (context, nullptr );
945+ }
946+
947+ Maybe<bool > InitializeContext (Local<Context> context,
948+ IsolateData* isolate_data) {
925949 if (InitializeMainContextForSnapshot (context).IsNothing ()) {
926950 return Nothing<bool >();
927951 }
928952
929- if (InitializeContextRuntime (context).IsNothing ()) {
953+ if (InitializeContextRuntime (context, isolate_data ).IsNothing ()) {
930954 return Nothing<bool >();
931955 }
932956 return Just (true );
0 commit comments