-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
src: allow --disallow-code-generation-from-strings in workers #60549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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
|
Review requested:
|
| 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
Context::FromSnapshot()orContext::New()creates the V8 contextInitializeContextRuntime(context)is called to set up Node.js-specific runtime settings- At this point,
Environment::GetCurrent(context)returnsnullptrbecause the Environment hasn't been created yet - Later,
Environmentis created and attached to the context
|
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 = |
There was a problem hiding this comment.
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.
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 In short, I think this PR should be good. |
There was a problem hiding this 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.
Make
--disallow-code-generation-from-stringsa per-isolate option instead of a V8-only option, allowing it to be passed via workerexecArgv.Fixes: #60371