Skip to content

Commit cf36b9c

Browse files
author
Mihail Slavchev
committed
rename global functions
1 parent 9197143 commit cf36b9c

29 files changed

+318
-309
lines changed

src/assets/app/bootstrap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
global.__onUncaughtError = function(error){
22
if(error.nativeException){
3-
Log("err.message: " + error.message);
4-
Log("err.stackTrace: " + error.stackTrace);
3+
__log("err.message: " + error.message);
4+
__log("err.stackTrace: " + error.stackTrace);
55
// false == do not continue execution
66
return false;
77
}

src/assets/internal/prepareExtend.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var __extends = function(Child, Parent) {
5757
}
5858

5959
function extend(child, parent) {
60-
Log("TS extend called");
60+
__log("TS extend called");
6161
if (!child.__extended) {
6262
child.__extended = parent.extend(child.name, child.prototype);
6363
}
@@ -66,7 +66,7 @@ var __extends = function(Child, Parent) {
6666
};
6767

6868
Parent.__activityExtend = function(parent, name, implementationObject) {
69-
Log("__activityExtend called");
69+
__log("__activityExtend called");
7070
return parent.extend(name, implementationObject);
7171
};
7272

src/jni/JsDebugger.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ void JsDebugger::Init(v8::Isolate *isolate, const string& packageName)
2121

2222
s_EnqueueMessage = env.GetStaticMethodID(s_JsDebuggerClass, "enqueueMessage", "(Ljava/lang/String;)V");
2323
assert(s_EnqueueMessage != nullptr);
24+
25+
s_EnableAgent = env.GetStaticMethodID(s_JsDebuggerClass, "enableAgent", "(Ljava/lang/String;IZ)V");
26+
assert(s_EnqueueMessage != nullptr);
2427
}
2528

2629
string JsDebugger::GetPackageName()
@@ -82,8 +85,27 @@ void JsDebugger::SendCommand(uint16_t *cmd, int length)
8285
v8::Debug::SendCommand(isolate, cmd, length, nullptr);
8386
}
8487

88+
void JsDebugger::DebugBreakCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
89+
{
90+
JEnv env;
91+
JniLocalRef packageName(env.NewStringUTF(s_packageName.c_str()));
92+
93+
jint port = 8181;
94+
if ((args.Length() > 0) && args[0]->IsInt32())
95+
{
96+
port = args[0]->Int32Value();
97+
}
98+
jboolean jniFalse = JNI_FALSE;
99+
100+
env.CallStaticVoidMethod(s_JsDebuggerClass, s_EnableAgent, (jstring)packageName, port, jniFalse);
101+
102+
DebugBreak();
103+
}
104+
105+
85106
v8::Isolate* JsDebugger::s_isolate = nullptr;
86107
string JsDebugger::s_packageName = "";
87108
jclass JsDebugger::s_JsDebuggerClass = nullptr;
88109
jmethodID JsDebugger::s_EnqueueMessage = nullptr;
110+
jmethodID JsDebugger::s_EnableAgent = nullptr;
89111

src/jni/JsDebugger.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace tns
2525

2626
static void SendCommand(uint16_t *cmd, int length);
2727

28+
static void DebugBreakCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
29+
2830
private:
2931
JsDebugger();
3032

@@ -33,6 +35,7 @@ namespace tns
3335
static std::string s_packageName;
3436
static jclass s_JsDebuggerClass;
3537
static jmethodID s_EnqueueMessage;
38+
static jmethodID s_EnableAgent;
3639
static v8::Isolate *s_isolate;
3740

3841
static const int INVALID_PORT = -1;

src/jni/NativeScriptRuntime.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,6 @@ void NativeScriptRuntime::DumpReferenceTablesMethodCallback(const v8::FunctionCa
688688
}
689689
}
690690

691-
void NativeScriptRuntime::WaitForDebuggerMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
692-
{
693-
// TODO:
694-
}
695-
696691
void NativeScriptRuntime::EnableVerboseLoggingMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
697692
{
698693
JEnv env;
@@ -705,7 +700,7 @@ void NativeScriptRuntime::DisableVerboseLoggingMethodCallback(const v8::Function
705700
env.CallStaticVoidMethod(PlatformClass, DISABLE_VERBOSE_LOGGING_METHOD_ID);
706701
}
707702

708-
void NativeScriptRuntime::FailMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
703+
void NativeScriptRuntime::ExitMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
709704
{
710705
auto msg = ConvertToString(args[0].As<String>());
711706
ASSERT_MESSAGE(false, "%s", msg.c_str());

src/jni/NativeScriptRuntime.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ namespace tns
6161

6262
static void DumpReferenceTablesMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
6363

64-
static void WaitForDebuggerMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
65-
66-
static void FailMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
64+
static void ExitMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
6765

6866
static void OverridesWeakCallback(v8::Isolate* isolate, v8::Persistent<v8::Object>* target, void* arg);
6967

src/jni/com_tns_Platform.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ void PrepareExtendFunction(Isolate *isolate, jstring filesPath)
9999
DEBUG_WRITE("Executed prepareExtend.js script");
100100
}
101101

102-
void PrintHashCallback(const FunctionCallbackInfo<Value>& args)
103-
{
104-
DEBUG_WRITE("%s, hashid=%d", ConvertToString(args[0]->ToString()).c_str(), args[1].As<Object>()->GetIdentityHash());
105-
}
106-
107102
void PrepareV8Runtime(Isolate *isolate, JEnv& env, jstring filesPath, jstring packageName)
108103
{
109104
const char v8flags[] = "--expose_gc";
@@ -120,16 +115,14 @@ void PrepareV8Runtime(Isolate *isolate, JEnv& env, jstring filesPath, jstring pa
120115
globalTemplate->Set(ConvertToV8String("__startCPUProfiler"), FunctionTemplate::New(isolate, Profiler::StartCPUProfilerCallback));
121116
globalTemplate->Set(ConvertToV8String("__stopCPUProfiler"), FunctionTemplate::New(isolate, Profiler::StopCPUProfilerCallback));
122117
globalTemplate->Set(ConvertToV8String("__heapSnapshot"), FunctionTemplate::New(isolate, Profiler::HeapSnapshotMethodCallback));
123-
globalTemplate->Set(ConvertToV8String("Log"), FunctionTemplate::New(isolate, NativeScriptRuntime::LogMethodCallback));
124-
globalTemplate->Set(ConvertToV8String("dumpReferenceTables"), FunctionTemplate::New(isolate, NativeScriptRuntime::DumpReferenceTablesMethodCallback));
125-
globalTemplate->Set(ConvertToV8String("waitForDebugger"), FunctionTemplate::New(isolate, NativeScriptRuntime::WaitForDebuggerMethodCallback));
126-
globalTemplate->Set(ConvertToV8String("enableVerboseLogging"), FunctionTemplate::New(isolate, NativeScriptRuntime::EnableVerboseLoggingMethodCallback));
127-
globalTemplate->Set(ConvertToV8String("disableVerboseLogging"), FunctionTemplate::New(isolate, NativeScriptRuntime::DisableVerboseLoggingMethodCallback));
128-
globalTemplate->Set(ConvertToV8String("fail"), FunctionTemplate::New(isolate, NativeScriptRuntime::FailMethodCallback));
118+
globalTemplate->Set(ConvertToV8String("__log"), FunctionTemplate::New(isolate, NativeScriptRuntime::LogMethodCallback));
119+
globalTemplate->Set(ConvertToV8String("__dumpReferenceTables"), FunctionTemplate::New(isolate, NativeScriptRuntime::DumpReferenceTablesMethodCallback));
120+
globalTemplate->Set(ConvertToV8String("__debugbreak"), FunctionTemplate::New(isolate, JsDebugger::DebugBreakCallback));
121+
globalTemplate->Set(ConvertToV8String("__enableVerboseLogging"), FunctionTemplate::New(isolate, NativeScriptRuntime::EnableVerboseLoggingMethodCallback));
122+
globalTemplate->Set(ConvertToV8String("__disableVerboseLogging"), FunctionTemplate::New(isolate, NativeScriptRuntime::DisableVerboseLoggingMethodCallback));
123+
globalTemplate->Set(ConvertToV8String("__exit"), FunctionTemplate::New(isolate, NativeScriptRuntime::ExitMethodCallback));
129124
globalTemplate->Set(ConvertToV8String("require"), FunctionTemplate::New(isolate, NativeScriptRuntime::RequireCallback));
130125
globalTemplate->Set(ConvertToV8String("WeakRef"), FunctionTemplate::New(isolate, WeakRef::ConstructorCallback));
131-
//
132-
globalTemplate->Set(ConvertToV8String("printhash"), FunctionTemplate::New(isolate, PrintHashCallback));
133126

134127
SimpleProfiler::Init(isolate, globalTemplate);
135128

src/src/com/tns/JsDebugger.java

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public class JsDebugger
3333
private static native void processDebugMessages();
3434

3535
private static native void enable();
36-
36+
3737
private static native void disable();
38-
38+
3939
private static native void debugBreak();
40-
40+
4141
private static native void sendCommand(byte[] command, int length);
4242

4343
private final Context context;
@@ -51,9 +51,9 @@ public class JsDebugger
5151
private static final String portEnvOutputFile = "envDebug.out";
5252

5353
private static int currentPort = INVALID_PORT;
54-
54+
5555
private static LinkedBlockingQueue<String> dbgMessages = new LinkedBlockingQueue<String>();
56-
56+
5757
private static void enqueueMessage(String message)
5858
{
5959
dbgMessages.add(message);
@@ -63,24 +63,24 @@ public JsDebugger(Context context)
6363
{
6464
this.context = context;
6565
}
66-
66+
6767
private static ServerSocket serverSocket;
6868
private static ServerThread serverThread = null;
6969
private static Thread javaServerThread = null;
70-
70+
7171
private static class ServerThread implements Runnable
7272
{
7373
private volatile boolean running;
7474
private final int port;
7575
private ResponseWorker responseWorker;
7676
private ListenerWorker commThread;
77-
77+
7878
public ServerThread(int port)
7979
{
8080
this.port = port;
8181
this.running = false;
8282
}
83-
83+
8484
public void stop()
8585
{
8686
this.running = false;
@@ -94,7 +94,7 @@ public void stop()
9494
e.printStackTrace();
9595
}
9696
}
97-
97+
9898
public void run()
9999
{
100100
try
@@ -113,10 +113,10 @@ public void run()
113113
try
114114
{
115115
Socket socket = serverSocket.accept();
116-
116+
117117
this.responseWorker = new ResponseWorker(socket);
118118
new Thread(this.responseWorker).start();
119-
119+
120120
commThread = new ListenerWorker(socket.getInputStream());
121121
new Thread(commThread).start();
122122
}
@@ -127,13 +127,12 @@ public void run()
127127
}
128128
}
129129
}
130-
130+
131131
private static class ListenerWorker implements Runnable
132132
{
133133
private enum State
134134
{
135-
Header,
136-
Message
135+
Header, Message
137136
}
138137

139138
private BufferedReader input;
@@ -142,20 +141,20 @@ public ListenerWorker(InputStream inputStream)
142141
{
143142
this.input = new BufferedReader(new InputStreamReader(inputStream));
144143
}
145-
144+
146145
private volatile boolean running = true;
147-
146+
148147
public void run()
149148
{
150149
Scanner scanner = new Scanner(this.input);
151150
scanner.useDelimiter("\r\n");
152-
151+
153152
ArrayList<String> headers = new ArrayList<String>();
154153
String line;
155154
State state = State.Header;
156155
int messageLength = -1;
157156
String leftOver = null;
158-
157+
159158
Runnable dispatchProcessDebugMessages = new Runnable()
160159
{
161160
@Override
@@ -196,7 +195,7 @@ public void run()
196195
leftOver = line.substring(messageLength);
197196
state = State.Header;
198197
headers.clear();
199-
198+
200199
try
201200
{
202201
byte[] cmdBytes = msg.getBytes("UTF-16LE");
@@ -237,32 +236,32 @@ public void run()
237236
}
238237
}
239238
}
240-
239+
241240
private static class ResponseWorker implements Runnable
242241
{
243242
private Socket socket;
244-
243+
245244
private final static String END_MSG = "#end#";
246-
245+
247246
private OutputStream output;
248-
247+
249248
public ResponseWorker(Socket clientSocket) throws IOException
250249
{
251250
this.socket = clientSocket;
252251
this.output = this.socket.getOutputStream();
253252
}
254-
253+
255254
public void stop()
256255
{
257256
dbgMessages.add(END_MSG);
258257
}
259-
258+
260259
@Override
261260
public void run()
262261
{
263262
byte[] LINE_END_BYTES = new byte[2];
264-
LINE_END_BYTES[0] = (byte)'\r';
265-
LINE_END_BYTES[1] = (byte)'\n';
263+
LINE_END_BYTES[0] = (byte) '\r';
264+
LINE_END_BYTES[1] = (byte) '\n';
266265
while (true)
267266
{
268267
try
@@ -271,7 +270,7 @@ public void run()
271270

272271
if (msg.equals(END_MSG))
273272
break;
274-
273+
275274
byte[] utf8;
276275
try
277276
{
@@ -282,7 +281,7 @@ public void run()
282281
utf8 = null;
283282
e1.printStackTrace();
284283
}
285-
284+
286285
if (utf8 != null)
287286
{
288287
try
@@ -310,7 +309,6 @@ public void run()
310309
}
311310
}
312311

313-
314312
int getDebuggerPortFromEnvironment()
315313
{
316314
int port = INVALID_PORT;
@@ -345,7 +343,7 @@ int getDebuggerPortFromEnvironment()
345343
}
346344
w = null;
347345
}
348-
346+
349347
try
350348
{
351349
Thread.sleep(3 * 1000);
@@ -354,7 +352,7 @@ int getDebuggerPortFromEnvironment()
354352
{
355353
e1.printStackTrace();
356354
}
357-
355+
358356
File envInFile = new File(baseDir, portEnvInputFile);
359357
if (envInFile.exists())
360358
{
@@ -372,7 +370,7 @@ int getDebuggerPortFromEnvironment()
372370
{
373371
requestedPort = INVALID_PORT;
374372
}
375-
373+
376374
w = new OutputStreamWriter(new FileOutputStream(envOutFile, true));
377375
int localPort = (requestedPort != INVALID_PORT) ? requestedPort : getAvailablePort();
378376
String strLocalPort = "PORT=" + localPort + "\n";
@@ -449,7 +447,7 @@ private static int getAvailablePort()
449447
return port;
450448
}
451449

452-
static void enableAgent(String packageName, int port, boolean waitForConnection)
450+
private static void enableAgent(String packageName, int port, boolean waitForConnection)
453451
{
454452
enable();
455453
if (serverThread == null)
@@ -460,7 +458,7 @@ static void enableAgent(String packageName, int port, boolean waitForConnection)
460458
javaServerThread.start();
461459
}
462460

463-
static void disableAgent()
461+
private static void disableAgent()
464462
{
465463
disable();
466464
if (serverThread != null)

test-app/assets/app/bootstrap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
global.__onUncaughtError = function(error){
22
if(error.nativeException){
3-
Log("err.message: " + error.message);
4-
Log("err.stackTrace: " + error.stackTrace);
3+
__log("err.message: " + error.message);
4+
__log("err.stackTrace: " + error.stackTrace);
55
// false == do not continue execution
66
return false;
77
}

0 commit comments

Comments
 (0)