Skip to content

Commit 821e21d

Browse files
committed
src: add unique_ptr equivalent of CreatePlatform
This makes this bit of the embedder situation a bit easier to use. PR-URL: #30467 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent 2561484 commit 821e21d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/api/environment.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,20 @@ MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() {
490490
MultiIsolatePlatform* CreatePlatform(
491491
int thread_pool_size,
492492
node::tracing::TracingController* tracing_controller) {
493-
return new NodePlatform(thread_pool_size, tracing_controller);
493+
return MultiIsolatePlatform::Create(thread_pool_size, tracing_controller)
494+
.release();
494495
}
495496

496497
void FreePlatform(MultiIsolatePlatform* platform) {
497498
delete platform;
498499
}
499500

501+
std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
502+
int thread_pool_size,
503+
node::tracing::TracingController* tracing_controller) {
504+
return std::make_unique<NodePlatform>(thread_pool_size, tracing_controller);
505+
}
506+
500507
MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
501508
Isolate* isolate = context->GetIsolate();
502509
EscapableHandleScope handle_scope(isolate);

src/node.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform {
316316
virtual void AddIsolateFinishedCallback(v8::Isolate* isolate,
317317
void (*callback)(void*),
318318
void* data) = 0;
319+
320+
static std::unique_ptr<MultiIsolatePlatform> Create(
321+
int thread_pool_size,
322+
node::tracing::TracingController* tracing_controller = nullptr);
319323
};
320324

321325
enum IsolateSettingsFlags {
@@ -467,6 +471,7 @@ NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> context);
467471
// it returns nullptr.
468472
NODE_EXTERN MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform();
469473

474+
// Legacy variants of MultiIsolatePlatform::Create().
470475
NODE_EXTERN MultiIsolatePlatform* CreatePlatform(
471476
int thread_pool_size,
472477
node::tracing::TracingController* tracing_controller);

0 commit comments

Comments
 (0)