From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Samuel Attard 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 c254b045494936eca14ce947e1c2de3327820aa2..63c9b9681fcc4e1e9a9590d59d74349bb8aee3b1 100644 --- a/gin/isolate_holder.cc +++ b/gin/isolate_holder.cc @@ -73,7 +73,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) : IsolateHolder(task_runner, access_mode, isolate_type, @@ -81,14 +82,16 @@ IsolateHolder::IsolateHolder( atomics_wait_mode, create_histogram_callback, add_histogram_sample_callback), - isolate_creation_mode) {} + isolate_creation_mode, + isolate) {} IsolateHolder::IsolateHolder( scoped_refptr task_runner, AccessMode access_mode, IsolateType isolate_type, std::unique_ptr params, - IsolateCreationMode isolate_creation_mode) + IsolateCreationMode isolate_creation_mode, + v8::Isolate* isolate) : access_mode_(access_mode), isolate_type_(isolate_type) { CHECK(Initialized()) << "You need to invoke gin::IsolateHolder::Initialize first"; @@ -99,7 +102,7 @@ IsolateHolder::IsolateHolder( v8::ArrayBuffer::Allocator* allocator = params->array_buffer_allocator; DCHECK(allocator); - isolate_ = v8::Isolate::Allocate(); + isolate_ = isolate ? isolate : v8::Isolate::Allocate(); isolate_data_ = std::make_unique(isolate_, allocator, access_mode_, task_runner); // TODO(https://crbug.com/1347092): Refactor such that caller need not diff --git a/gin/public/isolate_holder.h b/gin/public/isolate_holder.h index f8e5d0246b92fd2f1316313e13ccda7ef6c57495..196e030be4ba5bb5f04aaef0acf8cabe0de93a67 100644 --- a/gin/public/isolate_holder.h +++ b/gin/public/isolate_holder.h @@ -83,13 +83,15 @@ class GIN_EXPORT IsolateHolder { IsolateType isolate_type, 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( scoped_refptr task_runner, AccessMode access_mode, IsolateType isolate_type, std::unique_ptr params, - IsolateCreationMode isolate_creation_mode = IsolateCreationMode::kNormal); + IsolateCreationMode isolate_creation_mode = IsolateCreationMode::kNormal, + v8::Isolate* isolate = nullptr); IsolateHolder(const IsolateHolder&) = delete; IsolateHolder& operator=(const IsolateHolder&) = delete; ~IsolateHolder();