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
276284JsV8InspectorClient* 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
384390void 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
0 commit comments