Skip to content

Commit 98b6cf5

Browse files
src: expose MaybeInitializeContext to allow existing contexts
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.
1 parent 8619b19 commit 98b6cf5

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/api/environment.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ Local<Context> NewContext(Isolate* isolate,
362362
Local<ObjectTemplate> object_template) {
363363
auto context = Context::New(isolate, nullptr, object_template);
364364
if (context.IsEmpty()) return context;
365+
366+
return MaybeInitializeContext(context, object_template);
367+
}
368+
369+
Local<Context> MaybeInitializeContext(Local<Context> context,
370+
Local<ObjectTemplate> object_template) {
371+
Isolate* isolate = context->GetIsolate();
365372
HandleScope handle_scope(isolate);
366373

367374
context->SetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration,

src/node.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ NODE_EXTERN v8::Local<v8::Context> NewContext(
305305
v8::Local<v8::ObjectTemplate> object_template =
306306
v8::Local<v8::ObjectTemplate>());
307307

308+
// Runs Node.js-specific tweaks on an already constructed context
309+
NODE_EXTERN v8::Local<v8::Context> MaybeInitializeContext(
310+
v8::Local<v8::Context> context,
311+
v8::Local<v8::ObjectTemplate> object_template =
312+
v8::Local<v8::ObjectTemplate>());
313+
308314
// If `platform` is passed, it will be used to register new Worker instances.
309315
// It can be `nullptr`, in which case creating new Workers inside of
310316
// Environments that use this `IsolateData` will not work.

0 commit comments

Comments
 (0)