[gjs] importer: Move import_file up here



commit 05460307c8cff4963e9ad2c644b9a467e7443456
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Sep 27 17:04:09 2013 -0400

    importer: Move import_file up here
    
    We're going to use it to refactor load_module_init

 gjs/importer.c |  122 ++++++++++++++++++++++++++++----------------------------
 1 files changed, 61 insertions(+), 61 deletions(-)
---
diff --git a/gjs/importer.c b/gjs/importer.c
index d02b3eb..2301513 100644
--- a/gjs/importer.c
+++ b/gjs/importer.c
@@ -262,6 +262,67 @@ import_native_file(JSContext  *context,
     return retval;
 }
 
+static JSBool
+import_file(JSContext  *context,
+            const char *name,
+            const char *full_path,
+            JSObject  **module_out)
+{
+    JSBool ret = JS_FALSE;
+    JSObject *module_obj;
+    char *script = NULL;
+    gsize script_len = 0;
+    jsval script_retval;
+    GError *error = NULL;
+
+    module_obj = JS_NewObject(context, NULL, NULL, NULL);
+    if (module_obj == NULL)
+        return JS_FALSE;
+
+    if (!(g_file_get_contents(full_path, &script, &script_len, &error))) {
+        if (!g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_ISDIR) &&
+            !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOTDIR) &&
+            !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
+            gjs_throw_g_error(context, error);
+        else
+            g_error_free(error);
+
+        goto out;
+    }
+
+    if (!JS_EvaluateScript(context,
+                           module_obj,
+                           script,
+                           script_len,
+                           full_path,
+                           1, /* line number */
+                           &script_retval)) {
+
+        /* If JSOPTION_DONT_REPORT_UNCAUGHT is set then the exception
+         * would be left set after the evaluate and not go to the error
+         * reporter function.
+         */
+        if (JS_IsExceptionPending(context)) {
+            gjs_debug(GJS_DEBUG_IMPORTER,
+                      "Module '%s' left an exception set",
+                      name);
+            gjs_log_and_keep_exception(context);
+        } else {
+            gjs_throw(context,
+                         "JS_EvaluateScript() returned FALSE but did not set exception");
+        }
+
+        goto out;
+    }
+
+    ret = JS_TRUE;
+
+ out:
+    g_free(script);
+    *module_out = module_obj;
+    return ret;
+}
+
 static JSObject *
 load_module_init(JSContext  *context,
                  JSObject   *in_object,
@@ -395,67 +456,6 @@ load_module_elements(JSContext *context,
 }
 
 static JSBool
-import_file(JSContext  *context,
-            const char *name,
-            const char *full_path,
-            JSObject  **module_out)
-{
-    JSBool ret = JS_FALSE;
-    JSObject *module_obj;
-    char *script = NULL;
-    gsize script_len = 0;
-    jsval script_retval;
-    GError *error = NULL;
-
-    module_obj = JS_NewObject(context, NULL, NULL, NULL);
-    if (module_obj == NULL)
-        return JS_FALSE;
-
-    if (!(g_file_get_contents(full_path, &script, &script_len, &error))) {
-        if (!g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_ISDIR) &&
-            !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOTDIR) &&
-            !g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
-            gjs_throw_g_error(context, error);
-        else
-            g_error_free(error);
-
-        goto out;
-    }
-
-    if (!JS_EvaluateScript(context,
-                           module_obj,
-                           script,
-                           script_len,
-                           full_path,
-                           1, /* line number */
-                           &script_retval)) {
-
-        /* If JSOPTION_DONT_REPORT_UNCAUGHT is set then the exception
-         * would be left set after the evaluate and not go to the error
-         * reporter function.
-         */
-        if (JS_IsExceptionPending(context)) {
-            gjs_debug(GJS_DEBUG_IMPORTER,
-                      "Module '%s' left an exception set",
-                      name);
-            gjs_log_and_keep_exception(context);
-        } else {
-            gjs_throw(context,
-                         "JS_EvaluateScript() returned FALSE but did not set exception");
-        }
-
-        goto out;
-    }
-
-    ret = JS_TRUE;
-
- out:
-    g_free(script);
-    *module_out = module_obj;
-    return ret;
-}
-
-static JSBool
 import_file_on_module(JSContext  *context,
                       JSObject   *obj,
                       const char *name,


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