9
9
10
10
#include " Runtime.h"
11
11
#include " NativeScriptException.h"
12
+ #include " NativeScriptAssert.h"
12
13
13
14
#include " ArgConverter.h"
14
15
#include " Util.h"
@@ -271,6 +272,13 @@ void JsV8InspectorClient::init() {
271
272
createInspectorSession ();
272
273
273
274
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
+ }
274
282
}
275
283
276
284
JsV8InspectorClient* JsV8InspectorClient::GetInstance () {
@@ -290,12 +298,10 @@ void JsV8InspectorClient::inspectorSendEventCallback(const FunctionCallbackInfo<
290
298
Local<v8::String> arg = args[0 ].As <v8::String>();
291
299
std::string message = ArgConverter::ConvertToString (arg);
292
300
293
- /*
294
301
JEnv env;
295
302
// TODO: Pete: Check if we can use a wide (utf 16) string here
296
303
JniLocalRef str (env.NewStringUTF (message.c_str ()));
297
304
env.CallStaticVoidMethod (instance->inspectorClass_ , instance->sendMethod_ , instance->connection_ , (jstring) str);
298
- */
299
305
300
306
// TODO: ios uses this method, but doesn't work on android
301
307
// so I'm just sending directly to the socket (which seems to work)
@@ -382,6 +388,7 @@ void JsV8InspectorClient::inspectorTimestampCallback(const FunctionCallbackInfo<
382
388
}
383
389
384
390
void JsV8InspectorClient::registerModules () {
391
+ DEBUG_WRITE (" Registering inspector modules" );
385
392
Isolate* isolate = isolate_;
386
393
auto rt = Runtime::GetRuntime (isolate);
387
394
v8::Locker l (isolate);
@@ -394,21 +401,38 @@ void JsV8InspectorClient::registerModules() {
394
401
Local<Object> global = context->Global ();
395
402
Local<Object> inspectorObject = Object::New (isolate);
396
403
397
- assert (global-> Set (context, ArgConverter::ConvertToV8String (isolate, " __inspector " ), inspectorObject). FromMaybe ( false )) ;
404
+ bool success ;
398
405
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 ));
401
406
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
402
418
Local<External> data = External::New (isolate, this );
403
419
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);
405
423
424
+ // __inspectorTimestamp
406
425
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);
408
429
409
430
TryCatch tc (isolate);
410
431
Runtime::GetRuntime (isolate)->RunModule (" inspector_modules" );
411
432
433
+ if (tc.HasCaught ()) {
434
+ throw NativeScriptException (tc, " Error loading inspector modules" );
435
+ }
412
436
}
413
437
414
438
0 commit comments