Skip to content

Commit b215b16

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 <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 8a31136 commit b215b16

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/api/environment.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
349349
return handle_scope.Escape(exports);
350350
}
351351

352+
// Any initialization logic should be performed in
353+
// InitializeContext, because embedders don't necessarily
354+
// call NewContext and so they will experience breakages.
352355
Local<Context> NewContext(Isolate* isolate,
353356
Local<ObjectTemplate> object_template) {
354357
auto context = Context::New(isolate, nullptr, object_template);
@@ -358,8 +361,6 @@ Local<Context> NewContext(Isolate* isolate,
358361
return Local<Context>();
359362
}
360363

361-
InitializeContextRuntime(context);
362-
363364
return context;
364365
}
365366

@@ -393,7 +394,7 @@ void InitializeContextRuntime(Local<Context> context) {
393394
}
394395
}
395396

396-
bool InitializeContext(Local<Context> context) {
397+
bool InitializeContextForSnapshot(Local<Context> context) {
397398
Isolate* isolate = context->GetIsolate();
398399
HandleScope handle_scope(isolate);
399400

@@ -447,6 +448,15 @@ bool InitializeContext(Local<Context> context) {
447448
return true;
448449
}
449450

451+
bool InitializeContext(Local<Context> context) {
452+
if (!InitializeContextForSnapshot(context)) {
453+
return false;
454+
}
455+
456+
InitializeContextRuntime(context);
457+
return true;
458+
}
459+
450460
uv_loop_t* GetCurrentEventLoop(Isolate* isolate) {
451461
HandleScope handle_scope(isolate);
452462
Local<Context> context = isolate->GetCurrentContext();

0 commit comments

Comments
 (0)