[gjs: 2/6] engine: Use JS_InitWithFailureDiagnostic instead of JS_Init




commit 330ae5d67867ea9fff97f733f9219921ae22bf19
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat May 21 22:53:40 2022 -0700

    engine: Use JS_InitWithFailureDiagnostic instead of JS_Init
    
    No difference between these two, except that JS_InitWithFailureDiagnostic
    returns a descriptive message if it fails, which JS_Init ignores. So, in
    the rare case that it fails, we abort while printing the descriptive
    message instead of just "Could not initialize JavaScript".

 gjs/engine.cpp | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/gjs/engine.cpp b/gjs/engine.cpp
index d0f05e7d5..a8e867a7d 100644
--- a/gjs/engine.cpp
+++ b/gjs/engine.cpp
@@ -89,10 +89,13 @@ LPVOID    lpvReserved)
 {
   switch (fdwReason)
   {
-  case DLL_PROCESS_ATTACH:
-    gjs_dll = hinstDLL;
-    gjs_is_inited = JS_Init();
-    break;
+      case DLL_PROCESS_ATTACH: {
+          gjs_dll = hinstDLL;
+          const char* reason = JS_InitWithFailureDiagnostic();
+          if (reason)
+              g_error("Could not initialize JavaScript: %s", reason);
+          gjs_is_inited = true;
+      } break;
 
   case DLL_THREAD_DETACH:
     JS_ShutDown ();
@@ -110,8 +113,9 @@ LPVOID    lpvReserved)
 class GjsInit {
 public:
     GjsInit() {
-        if (!JS_Init())
-            g_error("Could not initialize Javascript");
+        const char* reason = JS_InitWithFailureDiagnostic();
+        if (reason)
+            g_error("Could not initialize JavaScript: %s", reason);
     }
 
     ~GjsInit() {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]