Skip to content
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

src: expose MaybeInitializeContext to allow existing contexts #28544

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/api/environment.cc
Expand Up @@ -362,6 +362,13 @@ Local<Context> NewContext(Isolate* isolate,
Local<ObjectTemplate> object_template) {
auto context = Context::New(isolate, nullptr, object_template);
if (context.IsEmpty()) return context;

return MaybeInitializeContext(context, object_template);
}

Local<Context> MaybeInitializeContext(Local<Context> context,
Local<ObjectTemplate> object_template) {
Isolate* isolate = context->GetIsolate();
HandleScope handle_scope(isolate);

context->SetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration,
Expand Down
6 changes: 6 additions & 0 deletions src/node.h
Expand Up @@ -305,6 +305,12 @@ NODE_EXTERN v8::Local<v8::Context> NewContext(
v8::Local<v8::ObjectTemplate> object_template =
v8::Local<v8::ObjectTemplate>());

// Runs Node.js-specific tweaks on an already constructed context
NODE_EXTERN v8::Local<v8::Context> MaybeInitializeContext(
Copy link
Member

Choose a reason for hiding this comment

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

For legacy reasons NewContext still need to return a Local, but for a new API I think we should return a MaybeLocal here. I would drop the word Maybe in the function name in favor of a more practical signature.

v8::Local<v8::Context> context,
v8::Local<v8::ObjectTemplate> object_template =
v8::Local<v8::ObjectTemplate>());

// If `platform` is passed, it will be used to register new Worker instances.
// It can be `nullptr`, in which case creating new Workers inside of
// Environments that use this `IsolateData` will not work.
Expand Down