Skip to content

Conversation

@mcollina
Copy link
Member

@mcollina mcollina commented Nov 2, 2025

Make --disallow-code-generation-from-strings a per-isolate option instead of a V8-only option, allowing it to be passed via worker execArgv.

Fixes: #60371

Make --disallow-code-generation-from-strings a per-isolate option
instead of a V8-only option, allowing it to be passed via worker
execArgv.

Fixes: nodejs#60371
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/config

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Nov 2, 2025
NODE_EXTERN v8::Maybe<bool> InitializeContext(v8::Local<v8::Context> context);
NODE_EXTERN v8::Maybe<bool> InitializeContext(
v8::Local<v8::Context> context,
IsolateData* isolate_data = nullptr);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell I think this likely incorrect. Can you recommend a different implementation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcollina You can look up the current Environment from a Local<Context> via Environment::GetCurrent(), and then use env->isolate_data(); no need to pass this parameter separately

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax Unfortunately, Environment::GetCurrent() doesn't work in this scenario because InitializeContextRuntime is called during context initialization, before the Environment is created and attached to the context.

The call flow for workers is:

  1. Context::FromSnapshot() or Context::New() creates the V8 context
  2. InitializeContextRuntime(context) is called to set up Node.js-specific runtime settings
  3. At this point, Environment::GetCurrent(context) returns nullptr because the Environment hasn't been created yet
  4. Later, Environment is created and attached to the context

@mcollina
Copy link
Member Author

mcollina commented Nov 2, 2025

cc @legendecas I presume this is incorrect then.

// node::ModifyCodeGenerationFromStrings.
// The `IsCodeGenerationFromStringsAllowed` can be refreshed by V8 according
// to the runtime flags, propagate the value to the embedder data.
bool is_code_generation_from_strings_allowed =
Copy link
Member

@legendecas legendecas Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The V8Option{} is removed in node_options.cc for --disallow-code-generation-from-strings, this will always be true. Because the flag is not set in V8.

@legendecas
Copy link
Member

legendecas commented Nov 2, 2025

I presume this is incorrect then.

My comment at #60371 (comment) was answering the question "why aren't v8 options supported for a worker thread?" and to most V8 options, we should not change them for a single worker.

However, we declared a same name flag --disallow-code-generation-from-strings in Node.js (it was derived from the V8 flag). It is safe if we didn't use the APIs like V8::SetFlagsFromString, which sets the per-process V8 flag storage.

In short, I think this PR should be good.

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A side-effect of this could be add-ons using v8::Context::New API directly, and these contexts will always allow code generation regardless if --disallow-code-generation-from-strings is specified or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for "--disallow-code-generation-from-strings" flag to workers

4 participants