8000 fix: inspector and globals (#1811) · NativeScript/android@79ebd18 · GitHub
[go: up one dir, main page]

Skip to content

Commit 79ebd18

Browse files
triniwizrigor789
andauthored
fix: inspector and globals (#1811)
Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
1 parent 9faa25d commit 79ebd18

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "Runtime.h"
1111
#include "NativeScriptException.h"
12+
#include "NativeScriptAssert.h"
1213

1314
#include "ArgConverter.h"
1415
#include "Util.h"
@@ -271,6 +272,13 @@ void JsV8InspectorClient::init() {
271272
createInspectorSession();
272273

273274
tracing_agent_.reset(new tns::inspector::TracingAgentImpl());
275+
276+
try {
277+
this->registerModules();
278+
} catch (NativeScriptException& e) {
279+
// we don't want to throw if registering modules failed.
280+
// e.ReThrowToV8();
281+
}
274282
}
275283

276284
JsV8InspectorClient* JsV8InspectorClient::GetInstance() {
@@ -290,12 +298,10 @@ void JsV8InspectorClient::inspectorSendEventCallback(const FunctionCallbackInfo<
290298
Local<v8::String> arg = args[0].As<v8::String>();
291299
std::string message = ArgConverter::ConvertToString(arg);
292300

293-
/*
294301
JEnv env;
295302
// TODO: Pete: Check if we can use a wide (utf 16) string here
296303
JniLocalRef str(env.NewStringUTF(message.c_str()));
297304
env.CallStaticVoidMethod(instance->inspectorClass_, instance->sendMethod_, instance->connection_, (jstring) str);
298-
*/
299305

300306
// TODO: ios uses this method, but doesn't work on android
301307
// so I'm just sending directly to the socket (which seems to work)
@@ -382,6 +388,7 @@ void JsV8InspectorClient::inspectorTimestampCallback(const FunctionCallbackInfo<
382388
}
383389

384390
void JsV8InspectorClient::registerModules() {
391+
DEBUG_WRITE("Registering inspector modules");
385392
Isolate* isolate = isolate_;
386393
auto rt = Runtime::GetRuntime(isolate);
387394
v8::Locker l(isolate);
@@ -394,21 +401,38 @@ void JsV8InspectorClient::registerModules() {
394401
Local<Object> global = context->Global();
395402
Local<Object> inspectorObject = Object::New(isolate);
396403

397-
assert(global->Set(context, ArgConverter::ConvertToV8String(isolate, "__inspector"), inspectorObject).FromMaybe(false));
404+
bool success;
398405
Local<v8::Function> func;
399-
bool success = v8::Function::New(context, registerDomainDispatcherCallback).ToLocal(&func);
400-
assert(success && global->Set(context, ArgConverter::ConvertToV8String(isolate, "__registerDomainDispatcher"), func).FromMaybe(false));
401406

407+
// __inspector
408+
success = global->Set(context, ArgConverter::ConvertToV8String(isolate, "__inspector"), inspectorObject).FromMaybe(false);
409+
assert(success);
410+
411+
// __registerDomainDispatcher
412+
success = v8::Function::New(context, registerDomainDispatcherCallback).ToLocal(&func);
413+
assert(success);
414+
success = global->Set(context, ArgConverter::ConvertToV8String(isolate, "__registerDomainDispatcher"), func).FromMaybe(false);
415+
assert(success);
416+
417+
// __inspectorSendEvent
402418
Local<External> data = External::New(isolate, this);
403419
success = v8::Function::New(context, inspectorSendEventCallback, data).ToLocal(&func);
404-
assert(success && global->Set(context, ArgConverter::ConvertToV8String(isolate, "__inspectorSendEvent"), func).FromMaybe(false));
420+
assert(success);
421+
success = global->Set(context, ArgConverter::ConvertToV8String(isolate, "__inspectorSendEvent"), func).FromMaybe(false);
422+
assert(success);
405423

424+
// __inspectorTimestamp
406425
success = v8::Function::New(context, inspectorTimestampCallback).ToLocal(&func);
407-
assert(success && global->Set(context, ArgConverter::ConvertToV8String(isolate, "__inspectorTimestamp"), func).FromMaybe(false));
426+
assert(success);
427+
success = global->Set(context, ArgConverter::ConvertToV8String(isolate, "__inspectorTimestamp"), func).FromMaybe(false);
428+
assert(success);
408429

409430
TryCatch tc(isolate);
410431
Runtime::GetRuntime(isolate)->RunModule("inspector_modules");
411432

433+
if(tc.HasCaught()) {
434+
throw NativeScriptException(tc, "Error loading inspector modules");
435+
}
412436
}
413437

414438

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,6 @@ void Runtime::Init(JNIEnv* env, jstring filesPath, jstring nativeLibDir, bool ve
201201

202202
NativeScriptException::Init();
203203
m_isolate = PrepareV8Runtime(filesRoot, nativeLibDirStr, packageNameStr, isDebuggable, callingDirStr, profilerOutputDirStr, maxLogcatObjectSize, forceLog);
204-
205-
#ifdef APPLICATION_IN_DEBUG
206-
/*
207-
* Attach __inspector object with function callbacks that report to the Chrome DevTools frontend
208-
*/
209-
if (isDebuggable) {
210-
JsV8InspectorClient::GetInstance()->registerModules();
211-
// JsV8InspectorClient::attachInspectorCallbacks(isolate, globalTemplate);
212-
}
213-
#endif
214204
}
215205

216206
Runtime::~Runtime() {
@@ -661,7 +651,6 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
661651
});
662652
)js";
663653

664-
665654
auto global = context->Global();
666655

667656
v8::Context::Scope contextScope{context};

0 commit comments

Comments
 (0)
0