Skip to content

Commit

Permalink
src: add unique_ptr equivalent of CreatePlatform
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
addaleax committed Mar 21, 2020
1 parent 2561484 commit 821e21d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,20 @@ MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() {
MultiIsolatePlatform* CreatePlatform(
int thread_pool_size,
node::tracing::TracingController* tracing_controller) {
return new NodePlatform(thread_pool_size, tracing_controller);
return MultiIsolatePlatform::Create(thread_pool_size, tracing_controller)
.release();
}

void FreePlatform(MultiIsolatePlatform* platform) {
delete platform;
}

std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
int thread_pool_size,
node::tracing::TracingController* tracing_controller) {
return std::make_unique<NodePlatform>(thread_pool_size, tracing_controller);
}

MaybeLocal<Object> GetPerContextExports(Local<Context> context) {
Isolate* isolate = context->GetIsolate();
EscapableHandleScope handle_scope(isolate);
Expand Down
5 changes: 5 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform {
virtual void AddIsolateFinishedCallback(v8::Isolate* isolate,
void (*callback)(void*),
void* data) = 0;

static std::unique_ptr<MultiIsolatePlatform> Create(
int thread_pool_size,
node::tracing::TracingController* tracing_controller = nullptr);
};

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

// Legacy variants of MultiIsolatePlatform::Create().
NODE_EXTERN MultiIsolatePlatform* CreatePlatform(
int thread_pool_size,
node::tracing::TracingController* tracing_controller);
Expand Down

0 comments on commit 821e21d

Please sign in to comment.