Skip to content

Commit 7460511

Browse files
authored
Merge pull request #671 from NativeScript/attach-start-fix
recreate debugger session to fix client reattach
2 parents 842e5f0 + 9e782ec commit 7460511

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

runtime/src/main/java/com/tns/AndroidJsV8Inspector.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class AndroidJsV8Inspector
1616
{
1717
private static boolean DEBUG_LOG_ENABLED = false;
1818

19-
public static final String DISCONNECT_MESSAGE = "nativescript-inspector-disconnect";
2019
private JsV8InspectorServer server;
2120
private Logger logger;
2221
private Context context;
@@ -107,16 +106,14 @@ protected void onOpen()
107106
Log.d("V8Inspector", "onOpen: ThreadID: " + Thread.currentThread().getId());
108107
}
109108

110-
final Object waitObject = new Object();
111-
112109
mainHandler.post(new Runnable()
113110
{
114111
@Override
115112
public void run()
116113
{
117114
if (DEBUG_LOG_ENABLED)
118115
{
119-
Log.d("V8Inspector", "onOpen: runnable ThreadID : " + Thread.currentThread().getId());
116+
Log.d("V8Inspector", "Connecting. threadID : " + Thread.currentThread().getId());
120117
}
121118

122119
connect(JsV8InspectorWebSocket.this);
@@ -137,11 +134,13 @@ protected void onClose(NanoWSD.WebSocketFrame.CloseCode code, String reason, boo
137134
@Override
138135
public void run()
139136
{
137+
if (DEBUG_LOG_ENABLED)
138+
{
139+
Log.d("V8Inspector", "Disconnecting");
140+
}
140141
disconnect();
141142
}
142143
});
143-
144-
inspectorMessages.offer(DISCONNECT_MESSAGE);
145144
}
146145

147146
@Override
@@ -151,6 +150,7 @@ protected void onMessage(final NanoWSD.WebSocketFrame message)
151150
{
152151
Log.d("V8Inspector", "To dbg backend: " + message.getTextPayload() + " ThreadId:" + Thread.currentThread().getId());
153152
}
153+
154154
inspectorMessages.offer(message.getTextPayload());
155155

156156
mainHandler.post(new Runnable()
@@ -184,17 +184,6 @@ public String getInspectorMessage()
184184
try
185185
{
186186
String message = inspectorMessages.take();
187-
188-
if (message != null && message.equalsIgnoreCase(DISCONNECT_MESSAGE))
189-
{
190-
if (DEBUG_LOG_ENABLED)
191-
{
192-
Log.d("V8Inspector", "disconecting");
193-
}
194-
disconnect();
195-
return null;
196-
}
197-
198187
return message;
199188
}
200189
catch (InterruptedException e)

runtime/src/main/jni/JsV8InspectorClient.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void JsV8InspectorClient::connect(jobject connection)
4343
this->connection = env.NewGlobalRef(connection);
4444
}
4545

46-
void JsV8InspectorClient::doConnect(v8::Isolate *isolate, const v8::Local<v8::Context> &context)
46+
void JsV8InspectorClient::createInspectorSession(v8::Isolate *isolate, const v8::Local<v8::Context> &context)
4747
{
4848
session_ = inspector_->connect(0, this, v8_inspector::StringView());
4949
}
@@ -58,11 +58,14 @@ void JsV8InspectorClient::disconnect()
5858
Isolate::Scope isolate_scope(isolate_);
5959
v8::HandleScope handleScope(isolate_);
6060

61+
session_->resume();
6162
session_.reset();
6263

6364
JEnv env;
6465
env.DeleteGlobalRef(this->connection);
6566
this->connection = nullptr;
67+
68+
this->createInspectorSession(isolate_, JsV8InspectorClient::PersistentToLocal(isolate_, context_));
6669
}
6770

6871

@@ -74,8 +77,6 @@ void JsV8InspectorClient::dispatchMessage(const std::string &message)
7477

7578
void JsV8InspectorClient::runMessageLoopOnPause(int context_group_id)
7679
{
77-
78-
7980
if (running_nested_loop_)
8081
{
8182
return;
@@ -204,7 +205,7 @@ void JsV8InspectorClient::init()
204205
v8::Persistent<v8::Context> persistentContext(context->GetIsolate(), context);
205206
context_.Reset(isolate_, persistentContext);
206207

207-
this->doConnect(isolate_, JsV8InspectorClient::PersistentToLocal(isolate_, context_));
208+
this->createInspectorSession(isolate_, JsV8InspectorClient::PersistentToLocal(isolate_, context_));
208209
}
209210

210211
JsV8InspectorClient *JsV8InspectorClient::GetInstance()

runtime/src/main/jni/JsV8InspectorClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace tns
2626

2727
void init();
2828
void connect(jobject connection);
29-
void doConnect(v8::Isolate *isolate, const v8::Local<v8::Context>& context);
29+
void createInspectorSession(v8::Isolate *isolate, const v8::Local<v8::Context> &context);
3030
void disconnect();
3131
void dispatchMessage(const std::string& message);
3232
void doDispatchMessage(v8::Isolate *isolate, const std::string& message);

0 commit comments

Comments
 (0)