aboutsummaryrefslogtreecommitdiff
path: root/src/inspector_agent.cc
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2017-05-25 19:00:24 -0700
committerSam Roberts <vieuxtech@gmail.com>2017-06-06 14:41:17 -0700
commit2791b360c11324f7c9ed83350f264c500ade4fe8 (patch)
tree32c398bc37f0d864d294cc629167aa577c30f08c /src/inspector_agent.cc
parentdcfbbacba8c22613b956c1a3b9d958676e5d5e87 (diff)
downloadandroid-node-v8-2791b360c11324f7c9ed83350f264c500ade4fe8.tar.gz
android-node-v8-2791b360c11324f7c9ed83350f264c500ade4fe8.tar.bz2
android-node-v8-2791b360c11324f7c9ed83350f264c500ade4fe8.zip
inspector: allow --inspect=host:port from js
PR-URL: https://github.com/nodejs/node/pull/13228 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/inspector_agent.cc')
-rw-r--r--src/inspector_agent.cc49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc
index 8269c9e097..948719ed70 100644
--- a/src/inspector_agent.cc
+++ b/src/inspector_agent.cc
@@ -562,6 +562,7 @@ bool Agent::Start(v8::Platform* platform, const char* path,
// Ignore failure, SIGUSR1 won't work, but that should not block node start.
StartDebugSignalHandler();
if (options.inspector_enabled()) {
+ // This will return false if listen failed on the inspector port.
return StartIoThread(options.wait_for_connect());
}
return true;
@@ -666,6 +667,50 @@ void Agent::PauseOnNextJavascriptStatement(const std::string& reason) {
channel->schedulePauseOnNextStatement(reason);
}
+void Open(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ inspector::Agent* agent = env->inspector_agent();
+ bool wait_for_connect = false;
+
+ if (args.Length() > 0 && args[0]->IsUint32()) {
+ uint32_t port = args[0]->Uint32Value();
+ agent->options().set_port(static_cast<int>(port));
+ }
+
+ if (args.Length() > 1 && args[1]->IsString()) {
+ node::Utf8Value host(env->isolate(), args[1].As<String>());
+ agent->options().set_host_name(*host);
+ }
+
+ if (args.Length() > 2 && args[2]->IsBoolean()) {
+ wait_for_connect = args[2]->BooleanValue();
+ }
+
+ agent->StartIoThread(wait_for_connect);
+}
+
+void Url(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ inspector::Agent* agent = env->inspector_agent();
+ inspector::InspectorIo* io = agent->io();
+
+ if (!io) return;
+
+ std::vector<std::string> ids = io->GetTargetIds();
+
+ if (ids.empty()) return;
+
+ std::string url = "ws://";
+ url += io->host();
+ url += ":";
+ url += std::to_string(io->port());
+ url += "/";
+ url += ids[0];
+
+ args.GetReturnValue().Set(OneByteString(env->isolate(), url.c_str()));
+}
+
+
// static
void Agent::InitInspector(Local<Object> target, Local<Value> unused,
Local<Context> context, void* priv) {
@@ -675,11 +720,13 @@ void Agent::InitInspector(Local<Object> target, Local<Value> unused,
if (agent->debug_options_.wait_for_connect())
env->SetMethod(target, "callAndPauseOnStart", CallAndPauseOnStart);
env->SetMethod(target, "connect", ConnectJSBindingsSession);
+ env->SetMethod(target, "open", Open);
+ env->SetMethod(target, "url", Url);
}
void Agent::RequestIoThreadStart() {
// We need to attempt to interrupt V8 flow (in case Node is running
- // continuous JS code) and to wake up libuv thread (in case Node is wating
+ // continuous JS code) and to wake up libuv thread (in case Node is waiting
// for IO events)
uv_async_send(&start_io_thread_async);
v8::Isolate* isolate = parent_env_->isolate();