[gjs/april-maintenance: 5/11] importer: Use is_root field in toString()



commit ef8a29c047a23822f913aa1a515c2809531adffb
Author: Philip Chimento <philip chimento gmail com>
Date:   Tue Apr 28 17:33:04 2020 -0700

    importer: Use is_root field in toString()
    
    We already keep a flag in the private data to tell whether the importer
    is the root importer, so it's not necessary to infer it by checking the
    __modulePath__ property.

 gjs/importer.cpp | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 372cdfc6..ba07beb4 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -93,19 +93,22 @@ importer_to_string(JSContext *cx,
                    unsigned   argc,
                    JS::Value *vp)
 {
-    GJS_GET_THIS(cx, argc, vp, args, importer);
-    const JSClass *klass = JS_GetClass(importer);
-
-    const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
-    JS::RootedValue module_path(cx);
-    if (!JS_GetPropertyById(cx, importer, atoms.module_path(), &module_path))
-        return false;
+    GJS_GET_PRIV(cx, argc, vp, args, importer, Importer, priv);
 
     GjsAutoChar output;
 
-    if (module_path.isNull()) {
+    const JSClass* klass = JS_GetClass(importer);
+
+    if (!priv) {
+        output = g_strdup_printf("[%s prototype]", klass->name);
+    } else if (priv->is_root) {
         output = g_strdup_printf("[%s root]", klass->name);
     } else {
+        const GjsAtoms& atoms = GjsContextPrivate::atoms(cx);
+        JS::RootedValue module_path(cx);
+        if (!JS_GetPropertyById(cx, importer, atoms.module_path(),
+                                &module_path))
+            return false;
         JS::UniqueChars path = gjs_string_to_utf8(cx, module_path);
         if (!path)
             return false;


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