Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions runtime/src/main/java/com/tns/AndroidJsV8Inspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class AndroidJsV8Inspector
{
private static boolean DEBUG_LOG_ENABLED = false;

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

final Object waitObject = new Object();

mainHandler.post(new Runnable()
{
@Override
public void run()
{
if (DEBUG_LOG_ENABLED)
{
Log.d("V8Inspector", "onOpen: runnable ThreadID : " + Thread.currentThread().getId());
Log.d("V8Inspector", "Connecting. threadID : " + Thread.currentThread().getId());
}

connect(JsV8InspectorWebSocket.this);
Expand All @@ -137,11 +134,13 @@ protected void onClose(NanoWSD.WebSocketFrame.CloseCode code, String reason, boo
@Override
public void run()
{
if (DEBUG_LOG_ENABLED)
{
Log.d("V8Inspector", "Disconnecting");
}
disconnect();
}
});

inspectorMessages.offer(DISCONNECT_MESSAGE);
}

@Override
Expand All @@ -151,6 +150,7 @@ protected void onMessage(final NanoWSD.WebSocketFrame message)
{
Log.d("V8Inspector", "To dbg backend: " + message.getTextPayload() + " ThreadId:" + Thread.currentThread().getId());
}

inspectorMessages.offer(message.getTextPayload());

mainHandler.post(new Runnable()
Expand Down Expand Up @@ -184,17 +184,6 @@ public String getInspectorMessage()
try
{
String message = inspectorMessages.take();

if (message != null && message.equalsIgnoreCase(DISCONNECT_MESSAGE))
{
if (DEBUG_LOG_ENABLED)
{
Log.d("V8Inspector", "disconecting");
}
disconnect();
return null;
}

return message;
}
catch (InterruptedException e)
Expand Down
9 changes: 5 additions & 4 deletions runtime/src/main/jni/JsV8InspectorClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void JsV8InspectorClient::connect(jobject connection)
this->connection = env.NewGlobalRef(connection);
}

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

session_->resume();
session_.reset();

JEnv env;
env.DeleteGlobalRef(this->connection);
this->connection = nullptr;

this->createInspectorSession(isolate_, JsV8InspectorClient::PersistentToLocal(isolate_, context_));
}


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

void JsV8InspectorClient::runMessageLoopOnPause(int context_group_id)
{


if (running_nested_loop_)
{
return;
Expand Down Expand Up @@ -204,7 +205,7 @@ void JsV8InspectorClient::init()
v8::Persistent<v8::Context> persistentContext(context->GetIsolate(), context);
context_.Reset(isolate_, persistentContext);

this->doConnect(isolate_, JsV8InspectorClient::PersistentToLocal(isolate_, context_));
this->createInspectorSession(isolate_, JsV8InspectorClient::PersistentToLocal(isolate_, context_));
}

JsV8InspectorClient *JsV8InspectorClient::GetInstance()
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/main/jni/JsV8InspectorClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace tns

void init();
void connect(jobject connection);
void doConnect(v8::Isolate *isolate, const v8::Local<v8::Context>& context);
void createInspectorSession(v8::Isolate *isolate, const v8::Local<v8::Context> &context);
void disconnect();
void dispatchMessage(const std::string& message);
void doDispatchMessage(v8::Isolate *isolate, const std::string& message);
Expand Down