@@ -426,39 +426,34 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
426426 Isolate::CreateParams create_params;
427427 bool didInitializeV8 = false ;
428428
429- auto pckName = ArgConverter::jstringToString (packageName);
430- __android_log_print (ANDROID_LOG_INFO, pckName.c_str (), " NativeScript Runtime Version %s, commit %s" , NATIVE_SCRIPT_RUNTIME_VERSION, NATIVE_SCRIPT_RUNTIME_COMMIT_SHA);
431- __android_log_print (ANDROID_LOG_DEBUG, pckName.c_str (), " V8 version %s" , V8::GetVersion ());
432-
433-
434429 create_params.array_buffer_allocator = &g_allocator;
435430
436431 m_startupData = new StartupData ();
437432
438- // Retrieve the device android Sdk version
439- char sdkVersion[PROP_VALUE_MAX];
440- __system_property_get (" ro.build.version.sdk" , sdkVersion);
433+ // Retrieve the device android Sdk version
434+ char sdkVersion[PROP_VALUE_MAX];
435+ __system_property_get (" ro.build.version.sdk" , sdkVersion);
441436
442- auto pckName = ArgConverter::jstringToString (packageName);
443-
444- void * snapshotPtr;
437+ auto pckName = ArgConverter::jstringToString (packageName);
445438
446- // If device isn't running on Sdk 17
447- if (strcmp (sdkVersion, string (" 17" ).c_str ()) != 0 ) {
448- snapshotPtr = dlopen (" libsnapshot.so" , RTLD_LAZY | RTLD_LOCAL);
449- } else {
450- // If device is running on android Sdk 17
451- // dlopen reads relative path to dynamic libraries or reads from folder different than the nativeLibsDirs on the android device
452- string libDir = ArgConverter::jstringToString (nativeLibDir);
453- string snapshotPath = libDir + " /libsnapshot.so" ;
454- snapshotPtr = dlopen (snapshotPath.c_str (), RTLD_LAZY | RTLD_LOCAL);
455- }
439+ void * snapshotPtr;
440+
441+ // If device isn't running on Sdk 17
442+ if (strcmp (sdkVersion, string (" 17" ).c_str ()) != 0 ) {
443+ snapshotPtr = dlopen (" libsnapshot.so" , RTLD_LAZY | RTLD_LOCAL);
444+ } else {
445+ // If device is running on android Sdk 17
446+ // dlopen reads relative path to dynamic libraries or reads from folder different than the nativeLibsDirs on the android device
447+ string libDir = ArgConverter::jstringToString (nativeLibDir);
448+ string snapshotPath = libDir + " /libsnapshot.so" ;
449+ snapshotPtr = dlopen (snapshotPath.c_str (), RTLD_LAZY | RTLD_LOCAL);
450+ }
456451
457- if (snapshotPtr == nullptr ) {
458- DEBUG_WRITE_FORCE (" Failed to load snapshot: %s" , dlerror ());
459- }
452+ if (snapshotPtr == nullptr ) {
453+ DEBUG_WRITE_FORCE (" Failed to load snapshot: %s" , dlerror ());
454+ }
460455
461- if (snapshotPtr)
456+ if (snapshotPtr)
462457 {
463458 m_startupData->data = static_cast <const char *>(dlsym (snapshotPtr, " TNSSnapshot_blob" ));
464459 m_startupData->raw_size = *static_cast <const unsigned int *>(dlsym (snapshotPtr, " TNSSnapshot_blob_len" ));
@@ -487,11 +482,11 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
487482 m_startupData->data = static_cast <const char *>(m_heapSnapshotBlob->memory );
488483 m_startupData->raw_size = m_heapSnapshotBlob->size ;
489484
490- DEBUG_WRITE (" Snapshot read %s (%dB)." , snapshotPath.c_str (), m_heapSnapshotBlob->size );
485+ DEBUG_WRITE_FORCE (" Snapshot read %s (%dB)." , snapshotPath.c_str (), m_heapSnapshotBlob->size );
491486 }
492487 else if (!saveSnapshot)
493488 {
494- DEBUG_WRITE (" No snapshot file found at %s" , snapshotPath.c_str ());
489+ DEBUG_WRITE_FORCE (" No snapshot file found at %s" , snapshotPath.c_str ());
495490
496491 }
497492 else
@@ -509,26 +504,26 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
509504 customScript = File::ReadText (Constants::V8_HEAP_SNAPSHOT_SCRIPT);
510505 }
511506
512- DEBUG_WRITE (" Creating heap snapshot" );
507+ DEBUG_WRITE_FORCE (" Creating heap snapshot" );
513508 *m_startupData = V8::CreateSnapshotDataBlob (customScript.c_str ());
514509
515510 if (m_startupData->raw_size == 0 )
516511 {
517- DEBUG_WRITE (" Failed to create heap snapshot." );
512+ DEBUG_WRITE_FORCE (" Failed to create heap snapshot." );
518513 }
519514 else
520515 {
521516 bool writeSuccess = File::WriteBinary (snapshotPath, m_startupData->data , m_startupData->raw_size );
522517
523518 if (!writeSuccess)
524519 {
525- __android_log_print (ANDROID_LOG_ERROR, pckName. c_str (), " Failed to save created snapshot." );
520+ DEBUG_WRITE_FORCE ( " Failed to save created snapshot." );
526521 }
527522 else
528523 {
529- DEBUG_WRITE (" Saved snapshot of %s (%dB) in %s (%dB)" ,
530- Constants::V8_HEAP_SNAPSHOT_SCRIPT.c_str (), customScript.size (),
531- snapshotPath.c_str (), m_startupData->raw_size );
524+ DEBUG_WRITE_FORCE (" Saved snapshot of %s (%dB) in %s (%dB)" ,
525+ Constants::V8_HEAP_SNAPSHOT_SCRIPT.c_str (), customScript.size (),
526+ snapshotPath.c_str (), m_startupData->raw_size );
532527 }
533528 }
534529 }
@@ -559,6 +554,8 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
559554
560555 isolate->AddMessageListener (NativeScriptException::OnUncaughtError);
561556
557+ __android_log_print (ANDROID_LOG_DEBUG, " TNS.Native" , " V8 version %s" , V8::GetVersion ());
558+
562559 auto globalTemplate = ObjectTemplate::New ();
563560
564561 const auto readOnlyFlags = static_cast <PropertyAttribute>(PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
@@ -591,10 +588,10 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
591588
592589 globalTemplate->Set (ArgConverter::ConvertToV8String (isolate, " Worker" ), workerFuncTemplate);
593590 }
594- /*
595- * Emulate a `WorkerGlobalScope`
596- * Attach postMessage, close to the global object
597- */
591+ /*
592+ * Emulate a `WorkerGlobalScope`
593+ * Attach postMessage, close to the global object
594+ */
598595 else {
599596 auto postMessageFuncTemplate = FunctionTemplate::New (isolate, CallbackHandlers::WorkerGlobalPostMessageCallback);
600597 globalTemplate->Set (ArgConverter::ConvertToV8String (isolate, " postMessage" ), postMessageFuncTemplate);
@@ -661,17 +658,18 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, jstring nativeLibDir
661658
662659jobject Runtime::ConvertJsValueToJavaObject (JEnv& env, const Local<Value>& value, int classReturnType)
663660{
664- JsArgToArrayConverter argConverter (m_isolate, value, false /* is implementation object*/ , classReturnType);
665- jobject jr = argConverter.GetConvertedArg ();
666- jobject javaResult = nullptr ;
667- if (jr != nullptr )
668- {
669- javaResult = env.NewLocalRef (jr);
670- }
661+ JsArgToArrayConverter argConverter (m_isolate, value, false /* is implementation object*/ , classReturnType);
662+ jobject jr = argConverter.GetConvertedArg ();
663+ jobject javaResult = nullptr ;
664+ if (jr != nullptr )
665+ {
666+ javaResult = env.NewLocalRef (jr);
667+ }
671668
672- return javaResult;
669+ return javaResult;
673670}
674671
672+
675673void Runtime::DestroyRuntime () {
676674 s_id2RuntimeCache.erase (m_id);
677675 s_isolate2RuntimesCache.erase (m_isolate);
0 commit comments