Skip to content

Commit

Permalink
src: split up InitializeContext
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
codebytere authored and targos committed Nov 10, 2019
1 parent 20f74ec commit eb31b62
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
return handle_scope.Escape(exports);
}

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

InitializeContextRuntime(context);

return context;
}

Expand Down Expand Up @@ -393,7 +394,7 @@ void InitializeContextRuntime(Local<Context> context) {
}
}

bool InitializeContext(Local<Context> context) {
bool InitializeContextForSnapshot(Local<Context> context) {
Isolate* isolate = context->GetIsolate();
HandleScope handle_scope(isolate);

Expand Down Expand Up @@ -447,6 +448,15 @@ bool InitializeContext(Local<Context> context) {
return true;
}

bool InitializeContext(Local<Context> context) {
if (!InitializeContextForSnapshot(context)) {
return false;
}

InitializeContextRuntime(context);
return true;
}

uv_loop_t* GetCurrentEventLoop(Isolate* isolate) {
HandleScope handle_scope(isolate);
Local<Context> context = isolate->GetCurrentContext();
Expand Down

0 comments on commit eb31b62

Please sign in to comment.