Skip to content

Commit 98c8f76

Browse files
codebyteretargos
authored andcommitted
src: split up InitializeContext
This splits out code from InitializeContext into a new function InitializeContextForSnapshot and moves the callsite of InitializeContextRuntime from NewContext to InitializeContext - embedders don't necessarily call NewContext and so need to be able to guarantee these functions are called regardless. PR-URL: #30067 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 87f14e1 commit 98c8f76

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/api/environment.cc

+13-3
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
361361
return handle_scope.Escape(exports);
362362
}
363363

364+
// Any initialization logic should be performed in
365+
// InitializeContext, because embedders don't necessarily
366+
// call NewContext and so they will experience breakages.
364367
Local<Context> NewContext(Isolate* isolate,
365368
Local<ObjectTemplate> object_template) {
366369
auto context = Context::New(isolate, nullptr, object_template);
@@ -370,8 +373,6 @@ Local<Context> NewContext(Isolate* isolate,
370373
return Local<Context>();
371374
}
372375

373-
InitializeContextRuntime(context);
374-
375376
return context;
376377
}
377378

@@ -405,7 +406,7 @@ void InitializeContextRuntime(Local<Context> context) {
405406
}
406407
}
407408

408-
bool InitializeContext(Local<Context> context) {
409+
bool InitializeContextForSnapshot(Local<Context> context) {
409410
Isolate* isolate = context->GetIsolate();
410411
HandleScope handle_scope(isolate);
411412

@@ -459,6 +460,15 @@ bool InitializeContext(Local<Context> context) {
459460
return true;
460461
}
461462

463+
bool InitializeContext(Local<Context> context) {
464+
if (!InitializeContextForSnapshot(context)) {
465+
return false;
466+
}
467+
468+
InitializeContextRuntime(context);
469+
return true;
470+
}
471+
462472
uv_loop_t* GetCurrentEventLoop(Isolate* isolate) {
463473
HandleScope handle_scope(isolate);
464474
Local<Context> context = isolate->GetCurrentContext();

0 commit comments

Comments
 (0)