Skip to content

Commit cc355eb

Browse files
authored
Merge pull request #1386 from NativeScript/trifonov/improve-breakpoint-adding
Added a setting for enabling line breakpoints
2 parents 755dbc9 + 8e0225c commit cc355eb

7 files changed

Lines changed: 90 additions & 3 deletions

File tree

test-app/app/src/main/assets/app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"markingMode": "full",
1010
"maxLogcatObjectSize": 1024,
1111
"forceLog": false,
12-
"suppressCallJSMethodExceptions": false
12+
"suppressCallJSMethodExceptions": false,
13+
"enableLineBreakpoints": false
1314
},
1415
"discardUncaughtJsExceptions": false
1516
}

test-app/runtime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ if (NOT OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
6363
src/main/cpp/JsV8InspectorClient.cpp
6464
src/main/cpp/DOMDomainCallbackHandlers.cpp
6565
src/main/cpp/NetworkDomainCallbackHandlers.cpp
66+
src/main/cpp/NSV8DebuggerAgentImpl.cpp
6667

6768
src/main/cpp/v8_inspector/src/inspector/protocol/CSS.cpp
6869
src/main/cpp/v8_inspector/src/inspector/protocol/Console.cpp
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2015 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "NSV8DebuggerAgentImpl.h"
6+
7+
namespace v8_inspector {
8+
9+
NSV8DebuggerAgentImpl::NSV8DebuggerAgentImpl(
10+
V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel,
11+
protocol::DictionaryValue* state)
12+
: V8DebuggerAgentImpl(session, frontendChannel, state),
13+
m_env(tns::JEnv()){
14+
15+
auto runtimeClass = m_env.FindClass("com/tns/Runtime");
16+
assert(runtimeClass != nullptr);
17+
18+
auto getLineBreakpointsEnabledMethodID = m_env.GetStaticMethodID(runtimeClass, "getLineBreakpointsEnabled", "()Z");
19+
assert(getLineBreakpointsEnabledMethodID != nullptr);
20+
21+
auto lineBreakpointsEnabled = m_env.CallStaticBooleanMethod(runtimeClass, getLineBreakpointsEnabledMethodID);
22+
m_lineBreakpointsEnabled = lineBreakpointsEnabled == JNI_TRUE;
23+
}
24+
25+
Response NSV8DebuggerAgentImpl::getPossibleBreakpoints(
26+
std::unique_ptr<protocol::Debugger::Location> start,
27+
Maybe<protocol::Debugger::Location> end, Maybe<bool> restrictToFunction,
28+
std::unique_ptr<protocol::Array<protocol::Debugger::BreakLocation>>*
29+
locations) {
30+
if(m_lineBreakpointsEnabled) {
31+
return V8DebuggerAgentImpl::getPossibleBreakpoints(std::move(start), std::move(end), std::move(restrictToFunction), locations);
32+
} else {
33+
*locations = protocol::Array<protocol::Debugger::BreakLocation>::create();
34+
return Response::OK();
35+
}
36+
}
37+
38+
} // namespace v8_inspector
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2015 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef V8_INSPECTOR_NS_V8_DEBUGGER_AGENT_IMPL_H_
6+
#define V8_INSPECTOR_NS_V8_DEBUGGER_AGENT_IMPL_H_
7+
8+
#include <JEnv.h>
9+
#include "src/inspector/v8-debugger-agent-impl.h"
10+
11+
namespace v8_inspector {
12+
13+
class NSV8DebuggerAgentImpl : public V8DebuggerAgentImpl {
14+
public:
15+
NSV8DebuggerAgentImpl(V8InspectorSessionImpl *, protocol::FrontendChannel *,
16+
protocol::DictionaryValue *state);
17+
18+
Response getPossibleBreakpoints(
19+
std::unique_ptr<protocol::Debugger::Location> start,
20+
Maybe<protocol::Debugger::Location> end, Maybe<bool> restrictToFunction,
21+
std::unique_ptr<protocol::Array<protocol::Debugger::BreakLocation>> *
22+
locations) override;
23+
DISALLOW_COPY_AND_ASSIGN(NSV8DebuggerAgentImpl);
24+
private:
25+
tns::JEnv m_env;
26+
bool m_lineBreakpointsEnabled;
27+
};
28+
}
29+
#endif // V8_INSPECTOR_NS_V8_DEBUGGER_AGENT_IMPL_H_

test-app/runtime/src/main/cpp/v8_inspector/src/inspector/v8-inspector-session-impl.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "src/inspector/v8-css-agent-impl.h"
2525
#include "src/inspector/v8-overlay-agent-impl.h"
2626
#include "src/inspector/v8-log-agent-impl.h"
27+
#include "NSV8DebuggerAgentImpl.h"
2728

2829
namespace v8_inspector {
2930

@@ -106,7 +107,7 @@ V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector,
106107
this, this, agentState(protocol::Runtime::Metainfo::domainName)));
107108
protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get());
108109

109-
m_debuggerAgent.reset(new V8DebuggerAgentImpl(
110+
m_debuggerAgent.reset(new NSV8DebuggerAgentImpl(
110111
this, this, agentState(protocol::Debugger::Metainfo::domainName)));
111112
protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get());
112113

test-app/runtime/src/main/java/com/tns/AppConfig.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ protected enum KnownKeys {
2020
HandleTimeZoneChanges("handleTimeZoneChanges", false),
2121
MaxLogcatObjectSize("maxLogcatObjectSize", 1024),
2222
ForceLog("forceLog", false),
23-
DiscardUncaughtJsExceptions("discardUncaughtJsExceptions", false);
23+
DiscardUncaughtJsExceptions("discardUncaughtJsExceptions", false),
24+
EnableLineBreakpoins("enableLineBreakpoints", false);
2425

2526
private final String name;
2627
private final Object defaultValue;
@@ -116,6 +117,9 @@ public AppConfig(File appDir) {
116117
if (androidObject.has(KnownKeys.ForceLog.getName())) {
117118
values[KnownKeys.ForceLog.ordinal()] = androidObject.getBoolean(KnownKeys.ForceLog.getName());
118119
}
120+
if (androidObject.has(KnownKeys.EnableLineBreakpoins.getName())) {
121+
values[KnownKeys.EnableLineBreakpoins.ordinal()] = androidObject.getBoolean(KnownKeys.EnableLineBreakpoins.getName());
122+
}
119123
}
120124
}
121125
} catch (Exception e) {
@@ -167,6 +171,10 @@ public boolean getForceLog() {
167171
return (boolean)values[KnownKeys.ForceLog.ordinal()];
168172
}
169173

174+
public boolean getLineBreakpointsEnabled() {
175+
return (boolean)values[KnownKeys.EnableLineBreakpoins.ordinal()];
176+
}
177+
170178
public boolean getDiscardUncaughtJsExceptions() {
171179
return (boolean)values[KnownKeys.DiscardUncaughtJsExceptions.ordinal()];
172180
}

test-app/runtime/src/main/java/com/tns/Runtime.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ public DynamicConfiguration getDynamicConfig() {
272272
return dynamicConfig;
273273
}
274274

275+
@RuntimeCallable
276+
public static boolean getLineBreakpointsEnabled() {
277+
if (staticConfiguration != null && staticConfiguration.appConfig != null) {
278+
return staticConfiguration.appConfig.getLineBreakpointsEnabled();
279+
} else {
280+
return ((boolean) AppConfig.KnownKeys.EnableLineBreakpoins.getDefaultValue());
281+
}
282+
}
283+
275284
@RuntimeCallable
276285
public int getMarkingModeOrdinal() {
277286
if (staticConfiguration != null && staticConfiguration.appConfig != null) {

0 commit comments

Comments
 (0)