Files
electron/patches/node/src_expose_maybeinitializecontext_to_allow_existing_contexts.patch
Samuel Attard 9a7426dc25 build: use our patch system to apply patches to upstream node (#19270)
This points our node repo at upstream (nodejs/node) and uses the base node tag as the target ref.  We then use our existing patch system and patch files to apply our changes on top of node.  This unifies how we patch upstream repos and makes our node patches easier to reason, view, understand and most importantly reduce.
2019-07-16 10:23:04 -07:00

48 lines
2.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@slack-corp.com>
Date: Thu, 4 Jul 2019 15:57:09 -0700
Subject: src: expose MaybeInitializeContext to allow existing contexts
Splits the node.js specific tweak intialization of NewContext into a new
helper MaybeInitializeContext so that embedders with existing contexts
can still use them in a node Environment now that primordials are
initialized and required so early.
diff --git a/src/api/environment.cc b/src/api/environment.cc
index bfc849d362a18bc7cd499584a439a1d29f0864f8..e313460a13ced7e7a9982db6f4a988699ec56111 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -362,6 +362,13 @@ Local<Context> NewContext(Isolate* isolate,
Local<ObjectTemplate> object_template) {
auto context = Context::New(isolate, nullptr, object_template);
if (context.IsEmpty()) return context;
+
+ return MaybeInitializeContext(context, object_template);
+}
+
+Local<Context> MaybeInitializeContext(Local<Context> context,
+ Local<ObjectTemplate> object_template) {
+ Isolate* isolate = context->GetIsolate();
HandleScope handle_scope(isolate);
context->SetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration,
diff --git a/src/node.h b/src/node.h
index dca89e212c89df19d0b97d748e3649392fec000c..de007ed97a52c17cff8b8917d25f2383d5bbae6a 100644
--- a/src/node.h
+++ b/src/node.h
@@ -303,6 +303,14 @@ NODE_EXTERN v8::Local<v8::Context> NewContext(
v8::Local<v8::ObjectTemplate> object_template =
v8::Local<v8::ObjectTemplate>());
+// Runs Node.js-specific tweaks on an already constructed context
+// This is not dead code, it is exposed for embedders so that they
+// can construct their own context and still use it in a node Environment.
+NODE_EXTERN v8::Local<v8::Context> MaybeInitializeContext(
+ v8::Local<v8::Context> context,
+ v8::Local<v8::ObjectTemplate> object_template =
+ v8::Local<v8::ObjectTemplate>());
+
// If `platform` is passed, it will be used to register new Worker instances.
// It can be `nullptr`, in which case creating new Workers inside of
// Environments that use this `IsolateData` will not work.