Skip to content

Commit 8005e63

Browse files
committed
src: add unique_ptr equivalent of CreatePlatform
This makes this bit of the embedder situation a bit easier to use. Backport-PR-URL: #35241 PR-URL: #30467 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent f325c95 commit 8005e63

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/api/environment.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,20 @@ MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() {
477477
MultiIsolatePlatform* CreatePlatform(
478478
int thread_pool_size,
479479
node::tracing::TracingController* tracing_controller) {
480-
return new NodePlatform(thread_pool_size, tracing_controller);
480+
return MultiIsolatePlatform::Create(thread_pool_size, tracing_controller)
481+
.release();
481482
}
482483

483484
void FreePlatform(MultiIsolatePlatform* platform) {
484485
delete platform;
485486
}
486487

488+
std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
489+
int thread_pool_size,
490+
node::tracing::TracingController* tracing_controller) {
491+
return std::make_unique<NodePlatform>(thread_pool_size, tracing_controller);
492+
}
493+
487494
MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
488495
Isolate* isolate = context->GetIsolate();
489496
EscapableHandleScope handle_scope(isolate);

src/node.h

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform {
298298
virtual void AddIsolateFinishedCallback(v8::Isolate* isolate,
299299
void (*callback)(void*),
300300
void* data) = 0;
301+
302+
static std::unique_ptr<MultiIsolatePlatform> Create(
303+
int thread_pool_size,
304+
node::tracing::TracingController* tracing_controller = nullptr);
301305
};
302306

303307
enum IsolateSettingsFlags {
@@ -446,6 +450,7 @@ NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> context);
446450
// it returns nullptr.
447451
NODE_EXTERN MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform();
448452

453+
// Legacy variants of MultiIsolatePlatform::Create().
449454
NODE_EXTERN MultiIsolatePlatform* CreatePlatform(
450455
int thread_pool_size,
451456
node::tracing::TracingController* tracing_controller);

0 commit comments

Comments
 (0)