isolate_holder.patch 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Samuel Attard <[email protected]>
  3. Date: Thu, 18 Oct 2018 17:07:27 -0700
  4. Subject: isolate_holder.patch
  5. Pass pre allocated isolate for initialization, node platform
  6. needs to register on an isolate so that it can be used later
  7. down in the initialization process of an isolate.
  8. Specifically, v8::Isolate::Initialize ends up calling
  9. NodePlatform::GetForegroundTaskRunner, which requires that the
  10. isolate has previously been registered with NodePlatform::RegisterIsolate.
  11. However, if we let gin allocate the isolate, there's no opportunity
  12. for us to register the isolate in between Isolate::Allocate and
  13. Isolate::Initialize.
  14. diff --git a/gin/isolate_holder.cc b/gin/isolate_holder.cc
  15. index cb2529a65f62c40e39d7cd4c96e50e1b72abbd53..da16bf73c566b3fce3708ad0609c49c5841c8811 100644
  16. --- a/gin/isolate_holder.cc
  17. +++ b/gin/isolate_holder.cc
  18. @@ -75,7 +75,8 @@ IsolateHolder::IsolateHolder(
  19. IsolateCreationMode isolate_creation_mode,
  20. v8::CreateHistogramCallback create_histogram_callback,
  21. v8::AddHistogramSampleCallback add_histogram_sample_callback,
  22. - scoped_refptr<base::SingleThreadTaskRunner> low_priority_task_runner)
  23. + scoped_refptr<base::SingleThreadTaskRunner> low_priority_task_runner,
  24. + v8::Isolate* isolate)
  25. : IsolateHolder(std::move(task_runner),
  26. access_mode,
  27. isolate_type,
  28. @@ -84,7 +85,8 @@ IsolateHolder::IsolateHolder(
  29. create_histogram_callback,
  30. add_histogram_sample_callback),
  31. isolate_creation_mode,
  32. - std::move(low_priority_task_runner)) {}
  33. + std::move(low_priority_task_runner),
  34. + isolate) {}
  35. IsolateHolder::IsolateHolder(
  36. scoped_refptr<base::SingleThreadTaskRunner> task_runner,
  37. @@ -92,7 +94,8 @@ IsolateHolder::IsolateHolder(
  38. IsolateType isolate_type,
  39. std::unique_ptr<v8::Isolate::CreateParams> params,
  40. IsolateCreationMode isolate_creation_mode,
  41. - scoped_refptr<base::SingleThreadTaskRunner> low_priority_task_runner)
  42. + scoped_refptr<base::SingleThreadTaskRunner> low_priority_task_runner,
  43. + v8::Isolate* isolate)
  44. : access_mode_(access_mode), isolate_type_(isolate_type) {
  45. CHECK(Initialized())
  46. << "You need to invoke gin::IsolateHolder::Initialize first";
  47. @@ -103,7 +106,7 @@ IsolateHolder::IsolateHolder(
  48. v8::ArrayBuffer::Allocator* allocator = params->array_buffer_allocator;
  49. DCHECK(allocator);
  50. - isolate_ = v8::Isolate::Allocate();
  51. + isolate_ = isolate ? isolate : v8::Isolate::Allocate();
  52. isolate_data_ = std::make_unique<PerIsolateData>(
  53. isolate_, allocator, access_mode_, task_runner,
  54. std::move(low_priority_task_runner));
  55. diff --git a/gin/public/isolate_holder.h b/gin/public/isolate_holder.h
  56. index a5db8841773618814ac90f740201d4d7e9057b3c..1368ab8bfbf9e69437b394a8376bf7c956ca13ce 100644
  57. --- a/gin/public/isolate_holder.h
  58. +++ b/gin/public/isolate_holder.h
  59. @@ -85,7 +85,8 @@ class GIN_EXPORT IsolateHolder {
  60. v8::CreateHistogramCallback create_histogram_callback = nullptr,
  61. v8::AddHistogramSampleCallback add_histogram_sample_callback = nullptr,
  62. scoped_refptr<base::SingleThreadTaskRunner> low_priority_task_runner =
  63. - nullptr);
  64. + nullptr,
  65. + v8::Isolate* isolate = nullptr);
  66. IsolateHolder(
  67. scoped_refptr<base::SingleThreadTaskRunner> task_runner,
  68. AccessMode access_mode,
  69. @@ -93,7 +94,8 @@ class GIN_EXPORT IsolateHolder {
  70. std::unique_ptr<v8::Isolate::CreateParams> params,
  71. IsolateCreationMode isolate_creation_mode = IsolateCreationMode::kNormal,
  72. scoped_refptr<base::SingleThreadTaskRunner> low_priority_task_runner =
  73. - nullptr);
  74. + nullptr,
  75. + v8::Isolate* isolate = nullptr);
  76. IsolateHolder(const IsolateHolder&) = delete;
  77. IsolateHolder& operator=(const IsolateHolder&) = delete;
  78. ~IsolateHolder();