Skip to content

Commit

Permalink
src: expose MaybeInitializeContext to allow existing contexts
Browse files Browse the repository at this point in the history
Splits the node.js specific tweak intialization of NewContext into a new
helper MaybeInitializeContext so that embedders with existing contexts
can still use them in a node Environment now that primordials are
initialized and required so early.
  • Loading branch information
MarshallOfSound committed Jul 4, 2019
1 parent 8619b19 commit 98b6cf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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(
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

0 comments on commit 98b6cf5

Please sign in to comment.