Skip to content

Commit

Permalink
src, tools: replace raw ptr with smart ptr
Browse files Browse the repository at this point in the history
NodeMainInstance::Create will now returrn
an instance of NodeMainInstance in a
unique_ptr.

PR-URL: #28577
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
GauthamBanasandra authored and targos committed Jul 20, 2019
1 parent c50e235 commit d34c256
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ NodeMainInstance::NodeMainInstance(Isolate* isolate,
SetIsolateUpForNode(isolate_, IsolateSettingCategories::kMisc);
}

NodeMainInstance* NodeMainInstance::Create(
std::unique_ptr<NodeMainInstance> NodeMainInstance::Create(
Isolate* isolate,
uv_loop_t* event_loop,
MultiIsolatePlatform* platform,
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args) {
return new NodeMainInstance(isolate, event_loop, platform, args, exec_args);
return std::unique_ptr<NodeMainInstance>(
new NodeMainInstance(isolate, event_loop, platform, args, exec_args));
}

NodeMainInstance::NodeMainInstance(
Expand Down Expand Up @@ -81,7 +82,6 @@ NodeMainInstance::NodeMainInstance(
void NodeMainInstance::Dispose() {
CHECK(!owns_isolate_);
platform_->DrainTasks(isolate_);
delete this;
}

NodeMainInstance::~NodeMainInstance() {
Expand Down
16 changes: 10 additions & 6 deletions src/node_main_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <cstddef>
#include <memory>

#include "node.h"
#include "util.h"
#include "uv.h"
Expand All @@ -22,7 +24,7 @@ class NodeMainInstance {
// platform->RegisterIsolate(isolate, loop);
// isolate->Initialize(...);
// isolate->Enter();
// NodeMainInstance* main_instance =
// std::unique_ptr<NodeMainInstance> main_instance =
// NodeMainInstance::Create(isolate, loop, args, exec_args);
//
// When tearing it down:
Expand All @@ -33,11 +35,13 @@ class NodeMainInstance {
// platform->UnregisterIsolate(isolate);
//
// After calling Dispose() the main_instance is no longer accessible.
static NodeMainInstance* Create(v8::Isolate* isolate,
uv_loop_t* event_loop,
MultiIsolatePlatform* platform,
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args);
static std::unique_ptr<NodeMainInstance> Create(
v8::Isolate* isolate,
uv_loop_t* event_loop,
MultiIsolatePlatform* platform,
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args);

void Dispose();

// Create a main instance that owns the isolate
Expand Down
2 changes: 1 addition & 1 deletion tools/snapshot/snapshot_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ std::string SnapshotBuilder::Generate(
Isolate* isolate = Isolate::Allocate();
per_process::v8_platform.Platform()->RegisterIsolate(isolate,
uv_default_loop());
NodeMainInstance* main_instance = nullptr;
std::unique_ptr<NodeMainInstance> main_instance;
std::string result;

{
Expand Down

0 comments on commit d34c256

Please sign in to comment.