fix: Use the new isolate initialization api

1015020
This commit is contained in:
deepak1556 2018-10-06 00:10:17 +05:30 committed by Jeremy Apthorp
parent fb4b50c8c9
commit be719a1ec3
6 changed files with 39 additions and 121 deletions

View file

@ -467,6 +467,6 @@ patches:
author: Samuel Attard <samuel.r.attard@gmail.com>
file: isolate_holder.patch
description: |
Expose a hook that allows embedders to intercept allocated isolates
before they are initialized or used so they can be added to the correct
platform. (In our case, node_platform)
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.

View file

@ -1,94 +1,41 @@
diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc
index e099fd3f03e5..46b5ea629d3a 100644
index e099fd3f03e5..4b362843e4f8 100644
--- a/gin/isolate_holder.cc
+++ b/gin/isolate_holder.cc
@@ -30,23 +30,31 @@ v8::ArrayBuffer::Allocator* g_array_buffer_allocator = nullptr;
const intptr_t* g_reference_table = nullptr;
} // namespace
+v8::Isolate* IsolateAllocater::Allocate() {
+ return nullptr;
+}
+
IsolateHolder::IsolateHolder(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : IsolateHolder(std::move(task_runner), AccessMode::kSingleThread) {}
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ IsolateAllocater* isolate_allocator)
+ : IsolateHolder(std::move(task_runner), AccessMode::kSingleThread, isolate_allocator) {}
IsolateHolder::IsolateHolder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
- AccessMode access_mode)
+ AccessMode access_mode,
+ IsolateAllocater* isolate_allocator)
: IsolateHolder(std::move(task_runner),
access_mode,
kAllowAtomicsWait,
- IsolateCreationMode::kNormal) {}
+ IsolateCreationMode::kNormal,
+ isolate_allocator) {}
IsolateHolder::IsolateHolder(
@@ -46,7 +46,8 @@ IsolateHolder::IsolateHolder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode,
AllowAtomicsWaitMode atomics_wait_mode,
- IsolateCreationMode isolate_creation_mode)
+ IsolateCreationMode isolate_creation_mode,
+ IsolateAllocater* isolate_allocator)
+ v8::Isolate* isolate)
: access_mode_(access_mode) {
DCHECK(task_runner);
DCHECK(task_runner->BelongsToCurrentThread());
@@ -54,7 +62,11 @@ IsolateHolder::IsolateHolder(
@@ -54,7 +55,11 @@ IsolateHolder::IsolateHolder(
v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first";
- isolate_ = v8::Isolate::Allocate();
+ if (isolate_allocator) {
+ isolate_ = isolate_allocator->Allocate();
+ } else {
+ if (!isolate) {
+ isolate_ = v8::Isolate::Allocate();
+ } else {
+ isolate_ = isolate;
+ }
isolate_data_.reset(
new 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 84cf66e6e9cd..2d5ebb76f050 100644
index 84cf66e6e9cd..cc0d65e4e4be 100644
--- a/gin/public/isolate_holder.h
+++ b/gin/public/isolate_holder.h
@@ -22,6 +22,14 @@ namespace gin {
class PerIsolateData;
class V8IsolateMemoryDumpProvider;
+class GIN_EXPORT IsolateAllocater {
+ public:
+ explicit IsolateAllocater() {};
+ virtual ~IsolateAllocater() {};
+
+ virtual v8::Isolate* Allocate();
+};
+
// To embed Gin, first initialize gin using IsolateHolder::Initialize and then
// create an instance of IsolateHolder to hold the v8::Isolate in which you
// will execute JavaScript. You might wish to subclass IsolateHolder if you
@@ -59,14 +67,17 @@ class GIN_EXPORT IsolateHolder {
};
explicit IsolateHolder(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ IsolateAllocater* isolate_allocator = nullptr);
IsolateHolder(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
- AccessMode access_mode);
+ AccessMode access_mode,
+ IsolateAllocater* isolate_allocator = nullptr);
IsolateHolder(
@@ -66,7 +66,8 @@ class GIN_EXPORT IsolateHolder {
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
AccessMode access_mode,
AllowAtomicsWaitMode atomics_wait_mode,
- IsolateCreationMode isolate_creation_mode = IsolateCreationMode::kNormal);
+ IsolateCreationMode isolate_creation_mode = IsolateCreationMode::kNormal,
+ IsolateAllocater* isolate_allocator = nullptr);
+ v8::Isolate* isolate = nullptr);
~IsolateHolder();
// Should be invoked once before creating IsolateHolder instances to