From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <samuel.r.attard@gmail.com>
Date: Thu, 18 Oct 2018 17:07:27 -0700
Subject: isolate_holder.patch
Pass pre allocated isolate for initialization, node platform
needs to register on an isolate so that it can be used later
down in the initialization process of an isolate.
Specifically, v8::Isolate::Initialize ends up calling
NodePlatform::GetForegroundTaskRunner, which requires that the
isolate has previously been registered with NodePlatform::RegisterIsolate.
However, if we let gin allocate the isolate, there's no opportunity
for us to register the isolate in between Isolate::Allocate and
Isolate::Initialize.
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc
index 2bed8f7ce21ab052c0c319775875b9cf008b2636..9aa4536d5c8fb38ac58e41c107b946cf9ba5d738 100644
--- a/gin/isolate_holder.cc
+++ b/gin/isolate_holder.cc
@@ -57,7 +57,8 @@ IsolateHolder::IsolateHolder(
IsolateType isolate_type,
IsolateCreationMode isolate_creation_mode,
v8::CreateHistogramCallback create_histogram_callback,
- v8::AddHistogramSampleCallback add_histogram_sample_callback)
+ v8::AddHistogramSampleCallback add_histogram_sample_callback,
+ v8::Isolate* isolate)
: access_mode_(access_mode), isolate_type_(isolate_type) {
CHECK(Initialized())
<< "You need to invoke gin::IsolateHolder::Initialize first";
@@ -68,7 +69,11 @@ IsolateHolder::IsolateHolder(
v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
DCHECK(allocator);
- isolate_ = v8::Isolate::Allocate();
+ if (!isolate) {
+ isolate_ = v8::Isolate::Allocate();
+ } else {
+ isolate_ = isolate;
+ }
isolate_data_ = std::make_unique<PerIsolateData>(isolate_, allocator,
access_mode_, task_runner);
if (isolate_creation_mode == IsolateCreationMode::kCreateSnapshot) {
diff --git a/gin/public/isolate_holder.h b/gin/public/isolate_holder.h
index cb587f852f230f84db1c50ffd6d41cad447e0949..619982a42c1255c3629da78fd35c82cdcf174b36 100644
--- a/gin/public/isolate_holder.h
+++ b/gin/public/isolate_holder.h
@@ -81,7 +81,8 @@ class GIN_EXPORT IsolateHolder {
IsolateCreationMode isolate_creation_mode = IsolateCreationMode::kNormal,
v8::CreateHistogramCallback create_histogram_callback = nullptr,
- v8::AddHistogramSampleCallback add_histogram_sample_callback = nullptr);
+ v8::AddHistogramSampleCallback add_histogram_sample_callback = nullptr,
+ v8::Isolate* isolate = nullptr);
IsolateHolder(const IsolateHolder&) = delete;
IsolateHolder& operator=(const IsolateHolder&) = delete;
~IsolateHolder();