From b086e38d858950dac3ea0774bf587aeef4a950e9 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 22 Oct 2019 11:11:25 -0700 Subject: 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: https://github.com/nodejs/node/pull/30067 Reviewed-By: Anna Henningsen Reviewed-By: Joyee Cheung Reviewed-By: David Carlier Reviewed-By: James M Snell Reviewed-By: Franziska Hinkelmann Reviewed-By: Colin Ihrig --- src/api/environment.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/api') diff --git a/src/api/environment.cc b/src/api/environment.cc index 3c5665a2d2..e6a87d5a93 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -361,6 +361,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); @@ -370,8 +373,6 @@ Local NewContext(Isolate* isolate, return Local(); } - InitializeContextRuntime(context); - return context; } @@ -405,7 +406,7 @@ void InitializeContextRuntime(Local context) { } } -bool InitializeContext(Local context) { +bool InitializeContextForSnapshot(Local context) { Isolate* isolate = context->GetIsolate(); HandleScope handle_scope(isolate); @@ -459,6 +460,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(); -- cgit v1.2.3