[gjs] context: Remove RuntimeData and gjs_runtime_init/gjs_runtime_destroy



commit baf096b9242cde494c83acef2e348a7f314b41ce
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Jan 3 23:39:26 2013 -0500

    context: Remove RuntimeData and gjs_runtime_init/gjs_runtime_destroy
    
    Now that RuntimeData only contains one pointer, we can just swap
    out the allocation with a direct reference to the pointer instead.
    The leftover initialization functions, not needing to do memory management,
    become one-liners and we can simply squash them where used.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691109

 gjs/context.c    |    4 +-
 gjs/jsapi-util.c |   73 +-----------------------------------------------------
 gjs/jsapi-util.h |    4 ---
 3 files changed, 3 insertions(+), 78 deletions(-)
---
diff --git a/gjs/context.c b/gjs/context.c
index 68643dd..3ebfc97 100644
--- a/gjs/context.c
+++ b/gjs/context.c
@@ -374,7 +374,7 @@ gjs_context_dispose(GObject *object)
 
     if (js_context->runtime != NULL) {
         /* Cleans up data as well as destroying the runtime. */
-        gjs_runtime_destroy(js_context->runtime);
+        JS_DestroyRuntime(js_context->runtime);
         js_context->runtime = NULL;
     }
 
@@ -549,7 +549,7 @@ gjs_context_constructor (GType                  type,
     if (js_context->context == NULL)
         gjs_fatal("Failed to create javascript context");
 
-    gjs_runtime_init(js_context->runtime, js_context->context);
+    JS_SetRuntimePrivate(js_context->runtime, js_context->context);
 
     JS_BeginRequest(js_context->context);
 
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index 61b07ac..6eab2ed 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -41,11 +41,6 @@ gjs_util_error_quark (void)
     return g_quark_from_static_string ("gjs-util-error-quark");
 }
 
-typedef struct {
-    JSContext *context;
-} RuntimeData;
-
-static RuntimeData* get_data_from_runtime(JSRuntime *runtime);
 
 /**
  * gjs_get_import_global:
@@ -84,9 +79,7 @@ gjs_get_import_global(JSContext *context)
 JSContext *
 gjs_runtime_get_context(JSRuntime *runtime)
 {
-    RuntimeData *rd;
-    rd = get_data_from_runtime(runtime);
-    return rd->context;
+    return (JSContext *) JS_GetRuntimePrivate (runtime);
 }
 
 static JSClass global_class = {
@@ -117,70 +110,6 @@ gjs_init_context_standard (JSContext       *context)
     return TRUE;
 }
 
-/**
- * gjs_runtime_init:
- * @runtime: a #JSRuntime
- *
- * Initializes a #JSRuntime for use with GJS
- *
- * This should only be called by GJS, not by applications.
- */
-void
-gjs_runtime_init(JSRuntime *runtime,
-                 JSContext *context)
-{
-    RuntimeData *rd;
-
-    if (JS_GetRuntimePrivate(runtime) != NULL)
-        gjs_fatal("JSRuntime already initialized or private data in use by someone else");
-
-    rd = g_slice_new0(RuntimeData);
-    rd->context = context;
-    JS_SetRuntimePrivate(runtime, rd);
-}
-
-/**
- * gjs_runtime_destroy:
- * @runtime: a #JSRuntime
- *
- * Calls JS_DestroyRuntime() on runtime and frees data allocated by
- * gjs_runtime_init(); these are unified into a single call because we
- * need to order things so that the allocated data is cleaned up
- * after JS_DestroyRuntime(). We might have finalizers run by
- * JS_DestroyRuntime() that rely on the information stored in the data,
- * such as the dynamic class structs.
- *
- * This should only be called by GJS, not by applications.
- */
-void
-gjs_runtime_destroy(JSRuntime *runtime)
-{
-    RuntimeData *rd;
-
-    rd = JS_GetRuntimePrivate(runtime);
-
-    gjs_debug(GJS_DEBUG_CONTEXT,
-              "Destroying JS runtime");
-
-    JS_DestroyRuntime(runtime);
-
-    gjs_debug(GJS_DEBUG_CONTEXT,
-              "Destroying any remaining dataset items on runtime");
-
-    g_slice_free(RuntimeData, rd);
-}
-
-static RuntimeData*
-get_data_from_runtime(JSRuntime *runtime)
-{
-    RuntimeData *rd;
-
-    rd = JS_GetRuntimePrivate(runtime);
-    if (G_UNLIKELY(rd == NULL))
-        gjs_fatal("JSRuntime not initialized for use with GJS");
-
-    return rd;
-}
 
 /* Checks whether an object has a property; unlike JS_GetProperty(),
  * never sets an exception. Treats a property with a value of JSVAL_VOID
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index e825b5f..e53ce2e 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -181,10 +181,6 @@ jsval gjs_##cname##_create_proto(JSContext *context, JSObject *module, const cha
 
 gboolean    gjs_init_context_standard        (JSContext       *context);
 
-void        gjs_runtime_init                 (JSRuntime       *runtime,
-                                              JSContext       *context);
-void        gjs_runtime_destroy              (JSRuntime       *runtime);
-
 JSContext*  gjs_runtime_get_context          (JSRuntime       *runtime);
 JSObject*   gjs_get_import_global            (JSContext       *context);
 gboolean    gjs_object_has_property          (JSContext       *context,



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