diff --git a/src/api/environment.cc b/src/api/environment.cc index 2c0fe1306319b2..138f9ada984a95 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -349,6 +349,9 @@ MaybeLocal GetPerContextExports(Local 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 NewContext(Isolate* isolate, Local object_template) { auto context = Context::New(isolate, nullptr, object_template); @@ -358,8 +361,6 @@ Local NewContext(Isolate* isolate, return Local(); } - InitializeContextRuntime(context); - return context; } @@ -393,7 +394,7 @@ void InitializeContextRuntime(Local context) { } } -bool InitializeContext(Local context) { +bool InitializeContextForSnapshot(Local context) { Isolate* isolate = context->GetIsolate(); HandleScope handle_scope(isolate); @@ -447,6 +448,15 @@ bool InitializeContext(Local context) { return true; } +bool InitializeContext(Local context) { + if (!InitializeContextForSnapshot(context)) { + return false; + } + + InitializeContextRuntime(context); + return true; +} + uv_loop_t* GetCurrentEventLoop(Isolate* isolate) { HandleScope handle_scope(isolate); Local context = isolate->GetCurrentContext();