[gjs] context: Move gjs_get_import_global to jsapi-util



commit 0c13b1533a80cf657ef64cc44bd989062b7f0bd1
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Sep 24 01:05:54 2019 +0200

    context: Move gjs_get_import_global to jsapi-util
    
    This method has not link dependency on GjsContext, so we can move
    it safely to jsapi-util.
    
    In order not to redefine the GjsContextPrivate::from_cx body inside
    this function, adding an inline parameter to make clear that this
    has to be inlined by the compiler.

 gjs/context-private.h |  2 +-
 gjs/context.cpp       | 25 -------------------------
 gjs/jsapi-util.cpp    | 23 +++++++++++++++++++++++
 3 files changed, 24 insertions(+), 26 deletions(-)
---
diff --git a/gjs/context-private.h b/gjs/context-private.h
index 68dfb4f7..cb8f9f7a 100644
--- a/gjs/context-private.h
+++ b/gjs/context-private.h
@@ -135,7 +135,7 @@ class GjsContextPrivate {
 
  public:
     /* Retrieving a GjsContextPrivate from JSContext or GjsContext */
-    GJS_USE static GjsContextPrivate* from_cx(JSContext* cx) {
+    GJS_USE GJS_ALWAYS_INLINE static GjsContextPrivate* from_cx(JSContext* cx) {
         return static_cast<GjsContextPrivate*>(JS_GetContextPrivate(cx));
     }
     GJS_USE static GjsContextPrivate* from_object(GObject* public_context);
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 25bdac75..5eae9eac 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -1096,31 +1096,6 @@ gjs_context_make_current (GjsContext *context)
     current_context = context;
 }
 
-/**
- * gjs_get_import_global:
- * @context: a #JSContext
- *
- * Gets the "import global" for the context's runtime. The import
- * global object is the global object for the context. It is used
- * as the root object for the scope of modules loaded by GJS in this
- * runtime, and should also be used as the globals 'obj' argument passed
- * to JS_InitClass() and the parent argument passed to JS_ConstructObject()
- * when creating a native classes that are shared between all contexts using
- * the runtime. (The standard JS classes are not shared, but we share
- * classes such as GObject proxy classes since objects of these classes can
- * easily migrate between contexts and having different classes depending
- * on the context where they were first accessed would be confusing.)
- *
- * Return value: the "import global" for the context's
- *  runtime. Will never return %NULL while GJS has an active context
- *  for the runtime.
- */
-JSObject*
-gjs_get_import_global(JSContext *context)
-{
-    return GjsContextPrivate::from_cx(context)->global();
-}
-
 /**
  * gjs_context_get_profiler:
  * @self: the #GjsContext
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index c365c7f8..6804aeaf 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -638,6 +638,29 @@ size_t gjs_unix_shebang_len(const std::u16string& script,
     return newline_pos + 1;
 }
 
+/**
+ * gjs_get_import_global:
+ * @context: a #JSContext
+ *
+ * Gets the "import global" for the context's runtime. The import
+ * global object is the global object for the context. It is used
+ * as the root object for the scope of modules loaded by GJS in this
+ * runtime, and should also be used as the globals 'obj' argument passed
+ * to JS_InitClass() and the parent argument passed to JS_ConstructObject()
+ * when creating a native classes that are shared between all contexts using
+ * the runtime. (The standard JS classes are not shared, but we share
+ * classes such as GObject proxy classes since objects of these classes can
+ * easily migrate between contexts and having different classes depending
+ * on the context where they were first accessed would be confusing.)
+ *
+ * Return value: the "import global" for the context's
+ *  runtime. Will never return %NULL while GJS has an active context
+ *  for the runtime.
+ */
+JSObject* gjs_get_import_global(JSContext* cx) {
+    return GjsContextPrivate::from_cx(cx)->global();
+}
+
 #if defined(G_OS_WIN32) && (defined(_MSC_VER) && (_MSC_VER >= 1900))
 /* Unfortunately Visual Studio's C++ .lib somehow did not contain the right
  * codecvt stuff that we need to convert from utf8 to utf16 (char16_t), so we


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