summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorShelley Vohr <shelley.vohr@gmail.com>2019-10-22 11:11:25 -0700
committerShelley Vohr <shelley.vohr@gmail.com>2019-10-29 08:11:19 -0700
commitb086e38d858950dac3ea0774bf587aeef4a950e9 (patch)
tree483cd22d5448646b54ca2b1f13bd16bbf19c5790 /src/api
parent009952935f253405ac095a4aaaa762fb080b7cb9 (diff)
downloadandroid-node-v8-b086e38d858950dac3ea0774bf587aeef4a950e9.tar.gz
android-node-v8-b086e38d858950dac3ea0774bf587aeef4a950e9.tar.bz2
android-node-v8-b086e38d858950dac3ea0774bf587aeef4a950e9.zip
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 <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>
Diffstat (limited to 'src/api')
-rw-r--r--src/api/environment.cc16
1 files changed, 13 insertions, 3 deletions
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<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);
@@ -370,8 +373,6 @@ Local<Context> NewContext(Isolate* isolate,
return Local<Context>();
}
- InitializeContextRuntime(context);
-
return context;
}
@@ -405,7 +406,7 @@ void InitializeContextRuntime(Local<Context> context) {
}
}
-bool InitializeContext(Local<Context> context) {
+bool InitializeContextForSnapshot(Local<Context> context) {
Isolate* isolate = context->GetIsolate();
HandleScope handle_scope(isolate);
@@ -459,6 +460,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();