Skip to content

Commit 1f0f025

Browse files
authored
Merge pull request #1751 from ptomato/inspector-console-log
Restore Console inspector for V8 10.3
2 parents 5150804 + b9af8ab commit 1f0f025

File tree

234 files changed

+15162
-54778
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+15162
-54778
lines changed

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

+35-35
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

+16-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ endif (CCACHE_FOUND AND (USE_CCACHE))
1818
# "-DANDROID_STL=c++_static" is just not enough for clang++ to find some libraries in the ndk
1919
MESSAGE(STATUS "## ANDROID_NDK_ROOT: " ${ANDROID_NDK_ROOT})
2020

21-
set(COMMON_CMAKE_ARGUMENTS "-std=c++14 -Werror -Wno-unused-result -mstackrealign -fexceptions -fno-builtin-stpcpy -fno-rtti -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_EMBEDDED_BUILTINS")
21+
set(COMMON_CMAKE_ARGUMENTS "-std=c++17 -Werror -Wno-unused-result -mstackrealign -fexceptions -fno-builtin-stpcpy -fno-rtti -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_EMBEDDED_BUILTINS")
2222

2323
if("${ANDROID_ABI}" MATCHES "arm64-v8a$" OR "${ANDROID_ABI}" MATCHES "x86_64$")
2424
# Enable pointer compression on 64 bit platforms
@@ -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/v8_inspector/src/inspector/v8-css-agent-impl.cpp test-app/runtime/src/main/cpp/CSSAgentImpl.cpp

+33-34
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,30 @@
44

55
#include <NativeScriptAssert.h>
66
#include <v8_inspector/third_party/inspector_protocol/crdtp/json.h>
7-
#include <v8_inspector/src/inspector/utils/v8-inspector-common.h>
87
#include <ArgConverter.h>
9-
#include "v8-css-agent-impl.h"
108

11-
namespace v8_inspector {
9+
#include "CSSAgentImpl.h"
10+
#include "utils/InspectorCommon.h"
1211

13-
using tns::ArgConverter;
12+
namespace tns {
1413

1514
namespace CSSAgentState {
1615
static const char cssEnabled[] = "cssEnabled";
1716
}
1817

19-
V8CSSAgentImpl::V8CSSAgentImpl(V8InspectorSessionImpl* session,
20-
protocol::FrontendChannel* frontendChannel,
21-
protocol::DictionaryValue* state)
18+
CSSAgentImpl::CSSAgentImpl(V8InspectorSessionImpl* session,
19+
protocol::FrontendChannel* frontendChannel,
20+
protocol::DictionaryValue* state)
2221
: m_session(session),
2322
m_frontend(frontendChannel),
2423
m_state(state),
2524
m_enabled(false) {
2625
Instance = this;
2726
}
2827

29-
V8CSSAgentImpl::~V8CSSAgentImpl() { }
28+
CSSAgentImpl::~CSSAgentImpl() { }
3029

31-
void V8CSSAgentImpl::enable(std::unique_ptr<EnableCallback> callback) {
30+
void CSSAgentImpl::enable(std::unique_ptr<EnableCallback> callback) {
3231
if (m_enabled) {
3332
callback->sendSuccess();
3433
return;
@@ -40,7 +39,7 @@ void V8CSSAgentImpl::enable(std::unique_ptr<EnableCallback> callback) {
4039
callback->sendSuccess();
4140
}
4241

43-
DispatchResponse V8CSSAgentImpl::disable() {
42+
DispatchResponse CSSAgentImpl::disable() {
4443
if (!m_enabled) {
4544
return DispatchResponse::Success();
4645
}
@@ -53,7 +52,7 @@ DispatchResponse V8CSSAgentImpl::disable() {
5352
}
5453

5554
// Not supported
56-
DispatchResponse V8CSSAgentImpl::getMatchedStylesForNode(int in_nodeId, Maybe<protocol::CSS::CSSStyle>* out_inlineStyle, Maybe<protocol::CSS::CSSStyle>* out_attributesStyle, Maybe<protocol::Array<protocol::CSS::RuleMatch>>* out_matchedCSSRules, Maybe<protocol::Array<protocol::CSS::PseudoElementMatches>>* out_pseudoElements, Maybe<protocol::Array<protocol::CSS::InheritedStyleEntry>>* out_inherited, Maybe<protocol::Array<protocol::CSS::CSSKeyframesRule>>* out_cssKeyframesRules) {
55+
DispatchResponse CSSAgentImpl::getMatchedStylesForNode(int in_nodeId, Maybe<protocol::CSS::CSSStyle>* out_inlineStyle, Maybe<protocol::CSS::CSSStyle>* out_attributesStyle, Maybe<protocol::Array<protocol::CSS::RuleMatch>>* out_matchedCSSRules, Maybe<protocol::Array<protocol::CSS::PseudoElementMatches>>* out_pseudoElements, Maybe<protocol::Array<protocol::CSS::InheritedStyleEntry>>* out_inherited, Maybe<protocol::Array<protocol::CSS::CSSKeyframesRule>>* out_cssKeyframesRules) {
5756
//// out_inlineStyle
5857
// auto cssPropsArr = protocol::Array<protocol::CSS::CSSProperty>::create();
5958
// auto shorthandPropArr = protocol::Array<protocol::CSS::ShorthandEntry>::create();
@@ -114,7 +113,7 @@ DispatchResponse V8CSSAgentImpl::getMatchedStylesForNode(int in_nodeId, Maybe<pr
114113
return DispatchResponse::Success();
115114
}
116115

117-
DispatchResponse V8CSSAgentImpl::getInlineStylesForNode(int in_nodeId, Maybe<protocol::CSS::CSSStyle>* out_inlineStyle, Maybe<protocol::CSS::CSSStyle>* out_attributesStyle) {
116+
DispatchResponse CSSAgentImpl::getInlineStylesForNode(int in_nodeId, Maybe<protocol::CSS::CSSStyle>* out_inlineStyle, Maybe<protocol::CSS::CSSStyle>* out_attributesStyle) {
118117
//// out_inlineStyle
119118
// auto cssPropsArr = protocol::Array<protocol::CSS::CSSProperty>::create();
120119
// auto shorthandPropArr = protocol::Array<protocol::CSS::ShorthandEntry>::create();
@@ -137,7 +136,7 @@ DispatchResponse V8CSSAgentImpl::getInlineStylesForNode(int in_nodeId, Maybe<pro
137136
return DispatchResponse::Success();
138137
}
139138

140-
DispatchResponse V8CSSAgentImpl::getComputedStyleForNode(int in_nodeId, std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>>* out_computedStyle) {
139+
DispatchResponse CSSAgentImpl::getComputedStyleForNode(int in_nodeId, std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>>* out_computedStyle) {
141140
auto computedStylePropertyArr = std::make_unique<protocol::Array<protocol::CSS::CSSComputedStyleProperty>>();
142141

143142
std::string getComputedStylesForNodeString = "getComputedStylesForNode";
@@ -169,7 +168,7 @@ DispatchResponse V8CSSAgentImpl::getComputedStyleForNode(int in_nodeId, std::uni
169168

170169
if (maybeResult.ToLocal(&outResult)) {
171170
auto resultString = outResult->ToString(context).ToLocalChecked();
172-
String16 resultProtocolString = toProtocolString(isolate, resultString);
171+
v8_inspector::String16 resultProtocolString = v8_inspector::toProtocolString(isolate, resultString);
173172
std::vector<uint8_t> cbor;
174173
v8_crdtp::json::ConvertJSONToCBOR(v8_crdtp::span<uint16_t>(resultProtocolString.characters16(), resultProtocolString.length()), &cbor);
175174
std::unique_ptr<protocol::Value> resultJson = protocol::Value::parseBinary(cbor.data(), cbor.size());
@@ -178,7 +177,7 @@ DispatchResponse V8CSSAgentImpl::getComputedStyleForNode(int in_nodeId, std::uni
178177

179178
std::vector<uint8_t> json;
180179
v8_crdtp::json::ConvertCBORToJSON(errorSupport.Errors(), &json);
181-
auto errorSupportString = String16(reinterpret_cast<const char*>(json.data()), json.size()).utf8();
180+
auto errorSupportString = v8_inspector::String16(reinterpret_cast<const char*>(json.data()), json.size()).utf8();
182181
if (!errorSupportString.empty()) {
183182
auto errorMessage = "Error while parsing CSSComputedStyleProperty object. ";
184183
DEBUG_WRITE_FORCE("%s Error: %s", errorMessage, errorSupportString.c_str());
@@ -197,7 +196,7 @@ DispatchResponse V8CSSAgentImpl::getComputedStyleForNode(int in_nodeId, std::uni
197196
return DispatchResponse::Success();
198197
}
199198

200-
DispatchResponse V8CSSAgentImpl::getPlatformFontsForNode(int in_nodeId, std::unique_ptr<protocol::Array<protocol::CSS::PlatformFontUsage>>* out_fonts) {
199+
DispatchResponse CSSAgentImpl::getPlatformFontsForNode(int in_nodeId, std::unique_ptr<protocol::Array<protocol::CSS::PlatformFontUsage>>* out_fonts) {
201200
auto fontsArr = std::make_unique<protocol::Array<protocol::CSS::PlatformFontUsage>>();
202201
auto defaultFont = "System Font";
203202
fontsArr->emplace_back(std::move(protocol::CSS::PlatformFontUsage::create()
@@ -210,71 +209,71 @@ DispatchResponse V8CSSAgentImpl::getPlatformFontsForNode(int in_nodeId, std::uni
210209
return DispatchResponse::Success();
211210
}
212211

213-
DispatchResponse V8CSSAgentImpl::getStyleSheetText(const String& in_styleSheetId, String* out_text) {
212+
DispatchResponse CSSAgentImpl::getStyleSheetText(const String& in_styleSheetId, String* out_text) {
214213
*out_text = "";
215214

216215
return utils::Common::protocolCommandNotSupportedDispatchResponse();
217216
}
218217

219-
DispatchResponse V8CSSAgentImpl::addRule(const String& in_styleSheetId, const String& in_ruleText, std::unique_ptr<protocol::CSS::SourceRange> in_location, std::unique_ptr<protocol::CSS::CSSRule>* out_rule) {
218+
DispatchResponse CSSAgentImpl::addRule(const String& in_styleSheetId, const String& in_ruleText, std::unique_ptr<protocol::CSS::SourceRange> in_location, std::unique_ptr<protocol::CSS::CSSRule>* out_rule) {
220219
return utils::Common::protocolCommandNotSupportedDispatchResponse();
221220
}
222221

223-
DispatchResponse V8CSSAgentImpl::collectClassNames(const String& in_styleSheetId, std::unique_ptr<protocol::Array<String>>* out_classNames) {
222+
DispatchResponse CSSAgentImpl::collectClassNames(const String& in_styleSheetId, std::unique_ptr<protocol::Array<String>>* out_classNames) {
224223
return utils::Common::protocolCommandNotSupportedDispatchResponse();
225224
}
226225

227-
DispatchResponse V8CSSAgentImpl::createStyleSheet(const String& in_frameId, String* out_styleSheetId) {
226+
DispatchResponse CSSAgentImpl::createStyleSheet(const String& in_frameId, String* out_styleSheetId) {
228227
return utils::Common::protocolCommandNotSupportedDispatchResponse();
229228
}
230229

231-
DispatchResponse V8CSSAgentImpl::forcePseudoState(int in_nodeId, std::unique_ptr<protocol::Array<String>> in_forcedPseudoClasses) {
230+
DispatchResponse CSSAgentImpl::forcePseudoState(int in_nodeId, std::unique_ptr<protocol::Array<String>> in_forcedPseudoClasses) {
232231
return utils::Common::protocolCommandNotSupportedDispatchResponse();
233232
}
234233

235-
DispatchResponse V8CSSAgentImpl::getBackgroundColors(int in_nodeId, Maybe<protocol::Array<String>>* out_backgroundColors, Maybe<String>* out_computedFontSize, Maybe<String>* out_computedFontWeight) {
234+
DispatchResponse CSSAgentImpl::getBackgroundColors(int in_nodeId, Maybe<protocol::Array<String>>* out_backgroundColors, Maybe<String>* out_computedFontSize, Maybe<String>* out_computedFontWeight) {
236235
return utils::Common::protocolCommandNotSupportedDispatchResponse();
237236
}
238237

239-
DispatchResponse V8CSSAgentImpl::getMediaQueries(std::unique_ptr<protocol::Array<protocol::CSS::CSSMedia>>* out_medias) {
238+
DispatchResponse CSSAgentImpl::getMediaQueries(std::unique_ptr<protocol::Array<protocol::CSS::CSSMedia>>* out_medias) {
240239
return utils::Common::protocolCommandNotSupportedDispatchResponse();
241240
}
242241

243-
DispatchResponse V8CSSAgentImpl::setEffectivePropertyValueForNode(int in_nodeId, const String& in_propertyName, const String& in_value) {
242+
DispatchResponse CSSAgentImpl::setEffectivePropertyValueForNode(int in_nodeId, const String& in_propertyName, const String& in_value) {
244243
return utils::Common::protocolCommandNotSupportedDispatchResponse();
245244
}
246245

247-
DispatchResponse V8CSSAgentImpl::setKeyframeKey(const String& in_styleSheetId, std::unique_ptr<protocol::CSS::SourceRange> in_range, const String& in_keyText, std::unique_ptr<protocol::CSS::Value>* out_keyText) {
246+
DispatchResponse CSSAgentImpl::setKeyframeKey(const String& in_styleSheetId, std::unique_ptr<protocol::CSS::SourceRange> in_range, const String& in_keyText, std::unique_ptr<protocol::CSS::Value>* out_keyText) {
248247
return utils::Common::protocolCommandNotSupportedDispatchResponse();
249248
}
250249

251-
DispatchResponse V8CSSAgentImpl::setMediaText(const String& in_styleSheetId, std::unique_ptr<protocol::CSS::SourceRange> in_range, const String& in_text, std::unique_ptr<protocol::CSS::CSSMedia>* out_media) {
250+
DispatchResponse CSSAgentImpl::setMediaText(const String& in_styleSheetId, std::unique_ptr<protocol::CSS::SourceRange> in_range, const String& in_text, std::unique_ptr<protocol::CSS::CSSMedia>* out_media) {
252251
return utils::Common::protocolCommandNotSupportedDispatchResponse();
253252
}
254253

255-
DispatchResponse V8CSSAgentImpl::setRuleSelector(const String& in_styleSheetId, std::unique_ptr<protocol::CSS::SourceRange> in_range, const String& in_selector, std::unique_ptr<protocol::CSS::SelectorList>* out_selectorList) {
254+
DispatchResponse CSSAgentImpl::setRuleSelector(const String& in_styleSheetId, std::unique_ptr<protocol::CSS::SourceRange> in_range, const String& in_selector, std::unique_ptr<protocol::CSS::SelectorList>* out_selectorList) {
256255
return utils::Common::protocolCommandNotSupportedDispatchResponse();
257256
}
258257

259-
DispatchResponse V8CSSAgentImpl::setStyleSheetText(const String& in_styleSheetId, const String& in_text, Maybe<String>* out_sourceMapURL) {
258+
DispatchResponse CSSAgentImpl::setStyleSheetText(const String& in_styleSheetId, const String& in_text, Maybe<String>* out_sourceMapURL) {
260259
return utils::Common::protocolCommandNotSupportedDispatchResponse();
261260
}
262261

263-
DispatchResponse V8CSSAgentImpl::setStyleTexts(std::unique_ptr<protocol::Array<protocol::CSS::StyleDeclarationEdit>> in_edits, std::unique_ptr<protocol::Array<protocol::CSS::CSSStyle>>* out_styles) {
262+
DispatchResponse CSSAgentImpl::setStyleTexts(std::unique_ptr<protocol::Array<protocol::CSS::StyleDeclarationEdit>> in_edits, std::unique_ptr<protocol::Array<protocol::CSS::CSSStyle>>* out_styles) {
264263
return utils::Common::protocolCommandNotSupportedDispatchResponse();
265264
}
266265

267-
DispatchResponse V8CSSAgentImpl::startRuleUsageTracking() {
266+
DispatchResponse CSSAgentImpl::startRuleUsageTracking() {
268267
return utils::Common::protocolCommandNotSupportedDispatchResponse();
269268
}
270269

271-
DispatchResponse V8CSSAgentImpl::stopRuleUsageTracking(std::unique_ptr<protocol::Array<protocol::CSS::RuleUsage>>* out_ruleUsage) {
270+
DispatchResponse CSSAgentImpl::stopRuleUsageTracking(std::unique_ptr<protocol::Array<protocol::CSS::RuleUsage>>* out_ruleUsage) {
272271
return utils::Common::protocolCommandNotSupportedDispatchResponse();
273272
}
274273

275-
DispatchResponse V8CSSAgentImpl::takeCoverageDelta(std::unique_ptr<protocol::Array<protocol::CSS::RuleUsage>>* out_coverage) {
274+
DispatchResponse CSSAgentImpl::takeCoverageDelta(std::unique_ptr<protocol::Array<protocol::CSS::RuleUsage>>* out_coverage) {
276275
return utils::Common::protocolCommandNotSupportedDispatchResponse();
277276
}
278277

279-
V8CSSAgentImpl* V8CSSAgentImpl::Instance = 0;
280-
}
278+
CSSAgentImpl* CSSAgentImpl::Instance = 0;
279+
} // namespace tns

0 commit comments

Comments
 (0)