isolate_holder.patch 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 7d9068b87eee4dbc3435ed6f67285d428dc85f52..c0b8c6e5b49390b8a87d6a9d19605f6b6a1c3562 100644
  16. --- a/gin/isolate_holder.cc
  17. +++ b/gin/isolate_holder.cc
  18. @@ -59,7 +59,8 @@ IsolateHolder::IsolateHolder(
  19. IsolateType isolate_type,
  20. IsolateCreationMode isolate_creation_mode,
  21. v8::CreateHistogramCallback create_histogram_callback,
  22. - v8::AddHistogramSampleCallback add_histogram_sample_callback)
  23. + v8::AddHistogramSampleCallback add_histogram_sample_callback,
  24. + v8::Isolate* isolate)
  25. : access_mode_(access_mode), isolate_type_(isolate_type) {
  26. CHECK(Initialized())
  27. << "You need to invoke gin::IsolateHolder::Initialize first";
  28. @@ -70,7 +71,7 @@ IsolateHolder::IsolateHolder(
  29. v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
  30. DCHECK(allocator);
  31. - isolate_ = v8::Isolate::Allocate();
  32. + isolate_ = isolate ? isolate : v8::Isolate::Allocate();
  33. isolate_data_ = std::make_unique<PerIsolateData>(isolate_, allocator,
  34. access_mode_, task_runner);
  35. if (isolate_creation_mode == IsolateCreationMode::kCreateSnapshot) {
  36. diff --git a/gin/public/isolate_holder.h b/gin/public/isolate_holder.h
  37. index 4efc13c79ae742fa1925d064318627452ba852b2..978c0d144370162e65038cf8a2e125fbfd0f7ebf 100644
  38. --- a/gin/public/isolate_holder.h
  39. +++ b/gin/public/isolate_holder.h
  40. @@ -82,7 +82,8 @@ class GIN_EXPORT IsolateHolder {
  41. IsolateType isolate_type,
  42. IsolateCreationMode isolate_creation_mode = IsolateCreationMode::kNormal,
  43. v8::CreateHistogramCallback create_histogram_callback = nullptr,
  44. - v8::AddHistogramSampleCallback add_histogram_sample_callback = nullptr);
  45. + v8::AddHistogramSampleCallback add_histogram_sample_callback = nullptr,
  46. + v8::Isolate* isolate = nullptr);
  47. IsolateHolder(const IsolateHolder&) = delete;
  48. IsolateHolder& operator=(const IsolateHolder&) = delete;
  49. ~IsolateHolder();