Skip to content

Commit f357ce6

Browse files
committed
fix: Re-enable inspector code
Uncomment the code that starts the inspector, and compile the inspector client when we are in debug mode. However, comment out the parts that don't work yet. At this point, the JsV8InspectorClient compiles, but doesn't do anything.
1 parent 6a52868 commit f357ce6

File tree

4 files changed

+64
-49
lines changed

4 files changed

+64
-49
lines changed

test-app/app/src/main/java/com/tns/RuntimeHelper.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -163,41 +163,41 @@ public static Runtime initRuntime(Context context) {
163163

164164
runtime = Runtime.initializeRuntimeWithConfiguration(config);
165165
if (isDebuggable) {
166-
// try {
167-
// v8Inspector = new AndroidJsV8Inspector(context.getFilesDir().getAbsolutePath(), context.getPackageName());
168-
// v8Inspector.start();
169-
//
170-
// // the following snippet is used as means to notify the VSCode extension
171-
// // debugger that the debugger agent has started
172-
// File debuggerStartedFile = new File("/data/local/tmp", context.getPackageName() + "-debugger-started");
173-
// if (debuggerStartedFile.exists() && !debuggerStartedFile.isDirectory() && debuggerStartedFile.length() == 0) {
174-
// java.io.FileWriter fileWriter = new java.io.FileWriter(debuggerStartedFile);
175-
// fileWriter.write("started");
176-
// fileWriter.close();
177-
// }
178-
//
179-
// // check if --debug-brk flag has been set. If positive:
180-
// // write to the file to invalidate the flag
181-
// // inform the v8Inspector to pause the main thread
182-
// File debugBreakFile = new File("/data/local/tmp", context.getPackageName() + "-debugbreak");
183-
// boolean shouldBreak = false;
184-
// if (debugBreakFile.exists() && !debugBreakFile.isDirectory() && debugBreakFile.length() == 0) {
185-
// java.io.FileWriter fileWriter = new java.io.FileWriter(debugBreakFile);
186-
// fileWriter.write("started");
187-
// fileWriter.close();
188-
//
189-
// shouldBreak = true;
190-
// }
191-
//
192-
// v8Inspector.waitForDebugger(shouldBreak);
193-
// } catch (IOException e) {
194-
// if (Util.isDebuggableApp(context)) {
195-
// e.printStackTrace();
196-
// }
197-
// }
198-
//
199-
// // if app is in debuggable mode run livesync service
200-
// // runtime needs to be initialized before the NativeScriptSyncService is enabled because it uses runtime.runScript(...)
166+
try {
167+
v8Inspector = new AndroidJsV8Inspector(context.getFilesDir().getAbsolutePath(), context.getPackageName());
168+
v8Inspector.start();
169+
170+
// the following snippet is used as means to notify the VSCode extension
171+
// debugger that the debugger agent has started
172+
File debuggerStartedFile = new File("/data/local/tmp", context.getPackageName() + "-debugger-started");
173+
if (debuggerStartedFile.exists() && !debuggerStartedFile.isDirectory() && debuggerStartedFile.length() == 0) {
174+
java.io.FileWriter fileWriter = new java.io.FileWriter(debuggerStartedFile);
175+
fileWriter.write("started");
176+
fileWriter.close();
177+
}
178+
179+
// check if --debug-brk flag has been set. If positive:
180+
// write to the file to invalidate the flag
181+
// inform the v8Inspector to pause the main thread
182+
File debugBreakFile = new File("/data/local/tmp", context.getPackageName() + "-debugbreak");
183+
boolean shouldBreak = false;
184+
if (debugBreakFile.exists() && !debugBreakFile.isDirectory() && debugBreakFile.length() == 0) {
185+
java.io.FileWriter fileWriter = new java.io.FileWriter(debugBreakFile);
186+
fileWriter.write("started");
187+
fileWriter.close();
188+
189+
shouldBreak = true;
190+
}
191+
192+
v8Inspector.waitForDebugger(shouldBreak);
193+
} catch (IOException e) {
194+
if (Util.isDebuggableApp(context)) {
195+
e.printStackTrace();
196+
}
197+
}
198+
199+
// if app is in debuggable mode run livesync service
200+
// runtime needs to be initialized before the NativeScriptSyncService is enabled because it uses runtime.runScript(...)
201201
initLiveSync(runtime, logger, context);
202202

203203
waitForLiveSync(context);

test-app/runtime/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ else ()
6363
# set(CMAKE_CXX_FLAGS "${COMMON_CMAKE_ARGUMENTS} -O3 -fvisibility=hidden -ffunction-sections -fno-data-sections")
6464
endif ()
6565

66+
if (NOT OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
67+
# Debug builds will include the V8 inspector sources
68+
add_definitions(-DAPPLICATION_IN_DEBUG)
69+
70+
set(
71+
INSPECTOR_SOURCES
72+
73+
src/main/cpp/com_tns_AndroidJsV8Inspector.cpp
74+
src/main/cpp/JsV8InspectorClient.cpp
75+
)
76+
else ()
77+
# When building in Release mode we do not include the V8 inspector sources
78+
set(INSPECTOR_SOURCES)
79+
endif ()
80+
6681
# Command info: https://cmake.org/cmake/help/v3.4/command/add_library.html
6782
# Creates(shared static) and names a library given relative sources
6883
# Gradle automatically packages shared libraries with your APK.

test-app/runtime/src/main/cpp/JsV8InspectorClient.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#include "NativeScriptException.h"
66

77
#include "ArgConverter.h"
8-
#include "DOMDomainCallbackHandlers.h"
9-
#include "LogAgentImpl.h"
10-
#include "NetworkDomainCallbackHandlers.h"
8+
// #include "DOMDomainCallbackHandlers.h"
9+
// #include "LogAgentImpl.h"
10+
// #include "NetworkDomainCallbackHandlers.h"
1111

1212
using namespace std;
1313
using namespace tns;
@@ -242,7 +242,7 @@ void JsV8InspectorClient::consoleLogCallback(Isolate* isolate, const string& mes
242242
auto frame = stack->GetFrame(isolate, 0);
243243

244244
// will be no-op in non-debuggable builds
245-
v8_inspector::V8LogAgentImpl::EntryAdded(message, logLevel, ArgConverter::ConvertToString(frame->GetScriptNameOrSourceURL()), frame->GetLineNumber());
245+
// v8_inspector::V8LogAgentImpl::EntryAdded(message, logLevel, ArgConverter::ConvertToString(frame->GetScriptNameOrSourceURL()), frame->GetLineNumber());
246246
}
247247

248248
void JsV8InspectorClient::attachInspectorCallbacks(Isolate* isolate,
@@ -251,17 +251,17 @@ void JsV8InspectorClient::attachInspectorCallbacks(Isolate* isolate,
251251

252252
auto inspectorJSObject = ObjectTemplate::New(isolate);
253253

254-
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "responseReceived"), FunctionTemplate::New(isolate, NetworkDomainCallbackHandlers::ResponseReceivedCallback));
255-
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "requestWillBeSent"), FunctionTemplate::New(isolate, NetworkDomainCallbackHandlers::RequestWillBeSentCallback));
256-
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "dataForRequestId"), FunctionTemplate::New(isolate, NetworkDomainCallbackHandlers::DataForRequestIdCallback));
257-
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "loadingFinished"), FunctionTemplate::New(isolate, NetworkDomainCallbackHandlers::LoadingFinishedCallback));
254+
// inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "responseReceived"), FunctionTemplate::New(isolate, NetworkDomainCallbackHandlers::ResponseReceivedCallback));
255+
// inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "requestWillBeSent"), FunctionTemplate::New(isolate, NetworkDomainCallbackHandlers::RequestWillBeSentCallback));
256+
// inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "dataForRequestId"), FunctionTemplate::New(isolate, NetworkDomainCallbackHandlers::DataForRequestIdCallback));
257+
// inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "loadingFinished"), FunctionTemplate::New(isolate, NetworkDomainCallbackHandlers::LoadingFinishedCallback));
258258
inspectorJSObject->SetAccessor(ArgConverter::ConvertToV8String(isolate, "isConnected"), JsV8InspectorClient::InspectorIsConnectedGetterCallback);
259259

260-
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "documentUpdated"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::DocumentUpdatedCallback));
261-
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "childNodeInserted"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::ChildNodeInsertedCallback));
262-
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "childNodeRemoved"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::ChildNodeRemovedCallback));
263-
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "attributeModified"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::AttributeModifiedCallback));
264-
inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "attributeRemoved"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::AttributeRemovedCallback));
260+
// inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "documentUpdated"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::DocumentUpdatedCallback));
261+
// inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "childNodeInserted"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::ChildNodeInsertedCallback));
262+
// inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "childNodeRemoved"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::ChildNodeRemovedCallback));
263+
// inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "attributeModified"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::AttributeModifiedCallback));
264+
// inspectorJSObject->Set(ArgConverter::ConvertToV8String(isolate, "attributeRemoved"), FunctionTemplate::New(isolate, DOMDomainCallbackHandlers::AttributeRemovedCallback));
265265

266266
globalObjectTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__inspector"), inspectorJSObject);
267267
}

test-app/runtime/src/main/cpp/Runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "File.h"
3434

3535
#ifdef APPLICATION_IN_DEBUG
36-
#include "NetworkDomainCallbackHandlers.h"
36+
// #include "NetworkDomainCallbackHandlers.h"
3737
#include "JsV8InspectorClient.h"
3838
#endif
3939

0 commit comments

Comments
 (0)