[gjs/esm/static-imports] Cleanup:



commit 04eb7bc2ee067c64238116d5479d14287decc5ac
Author: Evan Welsh <contact evanwelsh com>
Date:   Sat Jan 2 09:29:11 2021 -0800

    Cleanup:
    
    - don't initialize console with modules
    - expose default objects on modules
    - fixup C++ annotations

 gjs/console.cpp        | 12 ++++++------
 gjs/context-private.h  |  5 ++---
 modules/esm/format.js  | 16 +++++++++++-----
 modules/esm/gettext.js | 16 ++++++++++++++++
 modules/esm/system.js  | 15 +++++++++++++--
 5 files changed, 48 insertions(+), 16 deletions(-)
---
diff --git a/gjs/console.cpp b/gjs/console.cpp
index 3bea5a50..deb00019 100644
--- a/gjs/console.cpp
+++ b/gjs/console.cpp
@@ -290,13 +290,13 @@ main(int argc, char **argv)
         program_name = gjs_argv[0];
     } else if (gjs_argc == 1) {
         if (exec_as_module) {
-            script = g_strdup(
-                "throw new Error('Console interaction is not implemented with "
-                "the --module option. Exiting with error.')");
-        } else {
-            script = g_strdup(
-                "const Console = imports.console; Console.interact();");
+            g_warning(
+                "'-m' requires a file argument.\nExample: gjs -m main.js");
+            exit(1);
         }
+
+        script =
+            g_strdup("const Console = imports.console; Console.interact();");
         len = strlen(script);
         filename = "<stdin>";
         program_name = gjs_argv[0];
diff --git a/gjs/context-private.h b/gjs/context-private.h
index 33df0d77..35c23655 100644
--- a/gjs/context-private.h
+++ b/gjs/context-private.h
@@ -204,9 +204,8 @@ class GjsContextPrivate : public JS::JobQueue {
     bool eval_with_scope(JS::HandleObject scope_object, const char* script,
                          ssize_t script_len, const char* filename,
                          JS::MutableHandleValue retval);
-    GJS_JSAPI_RETURN_CONVENTION
-    bool eval_module(const char* identifier, uint8_t* exit_code_p,
-                     GError** error);
+    [[nodiscard]] bool eval_module(const char* identifier, uint8_t* exit_code_p,
+                                   GError** error);
     GJS_JSAPI_RETURN_CONVENTION
     bool call_function(JS::HandleObject this_obj, JS::HandleValue func_val,
                        const JS::HandleValueArray& args,
diff --git a/modules/esm/format.js b/modules/esm/format.js
index e474a46c..b1768b4a 100644
--- a/modules/esm/format.js
+++ b/modules/esm/format.js
@@ -1,12 +1,18 @@
 // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
 // SPDX-FileCopyrightText: 2020 Evan Welsh <contact evanwelsh com>
 
-export const {vprintf} = imports._format;
+const { vprintf } = imports._format;
 
 /**
- * @param {any[]} args FIXME
+ * @param {string} str the string to format (e.g. '%s is blue')
+ * @param {any...} args the arguments to replace placeholders with
  */
-export function format(...args) {
-    // eslint-disable-next-line no-invalid-this
-    return vprintf(this, args);
+export function sprintf(str, ...args) {
+    return vprintf(str, args);
 }
+
+export let _ = {
+    sprintf,
+};
+
+export default _;
diff --git a/modules/esm/gettext.js b/modules/esm/gettext.js
index 4c05e551..79b66718 100644
--- a/modules/esm/gettext.js
+++ b/modules/esm/gettext.js
@@ -14,3 +14,19 @@ export let {
     dpgettext,
     domain,
 } = imports._gettext;
+
+let _ = {
+    setlocale,
+    textdomain,
+    bindtextdomain,
+    gettext,
+    dgettext,
+    dcgettext,
+    ngettext,
+    dngettext,
+    pgettext,
+    dpgettext,
+    domain,
+};
+
+export default _;
diff --git a/modules/esm/system.js b/modules/esm/system.js
index cf9b98e0..e0b43e57 100644
--- a/modules/esm/system.js
+++ b/modules/esm/system.js
@@ -3,8 +3,6 @@
 
 const system = import.meta.importSync('system');
 
-export default system;
-
 export let {
     addressOf,
     refcount,
@@ -15,3 +13,16 @@ export let {
     programInvocationName,
     clearDateCaches,
 } = system;
+
+let _ = {
+    addressOf,
+    refcount,
+    breakpoint,
+    gc,
+    exit,
+    version,
+    programInvocationName,
+    clearDateCaches,
+};
+
+export default _;


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