@@ -3101,8 +3101,9 @@ class CustomPlatform : public v8::platform::DefaultPlatform {
31013101
31023102 public:
31033103 CustomPlatform (int thread_pool_size, IdleTaskSupport idle_task_support,
3104- void * context)
3104+ bool unprotected, void * context)
31053105 : DefaultPlatform(thread_pool_size, idle_task_support),
3106+ unprotected_ (unprotected),
31063107 context_(context) {}
31073108
31083109 // SAFETY: The platform is single-owner (via unique_ptr). The destructor
@@ -3128,14 +3129,17 @@ class CustomPlatform : public v8::platform::DefaultPlatform {
31283129 return custom;
31293130 }
31303131
3131- // Disable thread-isolated allocations (same as UnprotectedDefaultPlatform).
3132- // Required when isolates may be created on threads other than the one that
3133- // called v8::V8::Initialize (e.g. worker threads in Deno).
3132+ // When unprotected, disable thread-isolated allocations (same as
3133+ // UnprotectedDefaultPlatform). Required when isolates may be created on
3134+ // threads other than the one that called v8::V8::Initialize (e.g. worker
3135+ // threads in Deno).
31343136 v8::ThreadIsolatedAllocator* GetThreadIsolatedAllocator () override {
3135- return nullptr ;
3137+ if (unprotected_) return nullptr ;
3138+ return DefaultPlatform::GetThreadIsolatedAllocator ();
31363139 }
31373140
31383141 private:
3142+ bool unprotected_;
31393143 void * context_;
31403144 std::mutex mutex_;
31413145 // weak_ptr so runners are kept alive only while V8 holds a reference.
@@ -3202,7 +3206,7 @@ v8::Platform* v8__Platform__NewSingleThreadedDefaultPlatform(
32023206
32033207v8::Platform* v8__Platform__NewCustomPlatform (int thread_pool_size,
32043208 bool idle_task_support,
3205- void * context) {
3209+ bool unprotected, void * context) {
32063210 if (thread_pool_size < 1 ) {
32073211 thread_pool_size = std::thread::hardware_concurrency ();
32083212 }
@@ -3211,7 +3215,7 @@ v8::Platform* v8__Platform__NewCustomPlatform(int thread_pool_size,
32113215 thread_pool_size,
32123216 idle_task_support ? v8::platform::IdleTaskSupport::kEnabled
32133217 : v8::platform::IdleTaskSupport::kDisabled ,
3214- context)
3218+ unprotected, context)
32153219 .release ();
32163220}
32173221
0 commit comments