Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Copy Markdown
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