Skip to content

Commit

Permalink
src: use unique_ptr for InitializeInspector()
Browse files Browse the repository at this point in the history
This makes more sense than releasing and re-wrapping the raw pointer.

PR-URL: #30229
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Shelley Vohr <[email protected]>
  • Loading branch information
addaleax authored and targos committed Dec 1, 2019
1 parent 79713ed commit b40eede
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ class Environment : public MemoryRetainer {
#if HAVE_INSPECTOR
// If the environment is created for a worker, pass parent_handle and
// the ownership if transferred into the Environment.
int InitializeInspector(inspector::ParentInspectorHandle* parent_handle);
int InitializeInspector(
std::unique_ptr<inspector::ParentInspectorHandle> parent_handle);
#endif

v8::MaybeLocal<v8::Value> BootstrapInternalLoaders();
Expand Down
7 changes: 3 additions & 4 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,12 @@ MaybeLocal<Value> ExecuteBootstrapper(Environment* env,

#if HAVE_INSPECTOR
int Environment::InitializeInspector(
inspector::ParentInspectorHandle* parent_handle) {
std::unique_ptr<inspector::ParentInspectorHandle> parent_handle) {
std::string inspector_path;
if (parent_handle != nullptr) {
if (parent_handle) {
DCHECK(!is_main_thread());
inspector_path = parent_handle->url();
inspector_agent_->SetParentHandle(
std::unique_ptr<inspector::ParentInspectorHandle>(parent_handle));
inspector_agent_->SetParentHandle(std::move(parent_handle));
} else {
inspector_path = argv_.size() > 1 ? argv_[1].c_str() : "";
}
Expand Down
6 changes: 5 additions & 1 deletion src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <sanitizer/lsan_interface.h>
#endif

#if HAVE_INSPECTOR
#include "inspector/worker_inspector.h" // ParentInspectorHandle
#endif

namespace node {

using v8::Context;
Expand Down Expand Up @@ -217,7 +221,7 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment(
// TODO(joyeecheung): when we snapshot the bootstrapped context,
// the inspector and diagnostics setup should after after deserialization.
#if HAVE_INSPECTOR
*exit_code = env->InitializeInspector(nullptr);
*exit_code = env->InitializeInspector({});
#endif
if (*exit_code != 0) {
return env;
Expand Down
2 changes: 1 addition & 1 deletion src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void Worker::Run() {
{
env_->InitializeDiagnostics();
#if HAVE_INSPECTOR
env_->InitializeInspector(inspector_parent_handle_.release());
env_->InitializeInspector(std::move(inspector_parent_handle_));
#endif
HandleScope handle_scope(isolate_);
AsyncCallbackScope callback_scope(env_.get());
Expand Down

0 comments on commit b40eede

Please sign in to comment.