[gjs] unit-test-utils: Use a standard gjs context



commit 30d3fc0a297bed026be88ffc7ac36743b25d559e
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Jan 3 22:43:32 2013 -0500

    unit-test-utils: Use a standard gjs context
    
    Rather than construct ourselves our own JSContext, use GjsContext,
    which will initialize the engine and call JS_SetCStringsAreUTF8(),
    which can only be called once.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691108

 gjs/unit-test-utils.c |   11 ++++-------
 gjs/unit-test-utils.h |    4 ++++
 2 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/gjs/unit-test-utils.c b/gjs/unit-test-utils.c
index 97afcf9..c1f4b88 100644
--- a/gjs/unit-test-utils.c
+++ b/gjs/unit-test-utils.c
@@ -35,12 +35,10 @@ test_error_reporter(JSContext     *context,
 void
 _gjs_unit_test_fixture_begin (GjsUnitTestFixture *fixture)
 {
-    JS_SetCStringsAreUTF8();
-    fixture->runtime = JS_NewRuntime(1024*1024 /* max bytes */);
-    fixture->context = JS_NewContext(fixture->runtime, 8192);
+    fixture->gjs_context = gjs_context_new ();
+    fixture->context = (JSContext *) gjs_context_get_native_context (fixture->gjs_context);
+    fixture->runtime = JS_GetRuntime(fixture->context);
     JS_BeginRequest(fixture->context);
-    if (!gjs_init_context_standard(fixture->context))
-        g_error("failed to init context");
     JS_SetErrorReporter(fixture->context, test_error_reporter);
 }
 
@@ -48,6 +46,5 @@ void
 _gjs_unit_test_fixture_finish (GjsUnitTestFixture *fixture)
 {
     JS_EndRequest(fixture->context);
-    JS_DestroyContext(fixture->context);
-    JS_DestroyRuntime(fixture->runtime);
+    g_object_unref(fixture->gjs_context);
 }
diff --git a/gjs/unit-test-utils.h b/gjs/unit-test-utils.h
index be8a205..c0e8c4f 100644
--- a/gjs/unit-test-utils.h
+++ b/gjs/unit-test-utils.h
@@ -24,11 +24,15 @@
 #ifndef _GJS_UNIT_TEST_UTILS_H
 #define _GJS_UNIT_TEST_UTILS_H
 
+#include <gjs/gjs.h>
+
 typedef struct _GjsUnitTestFixture GjsUnitTestFixture;
 
 struct _GjsUnitTestFixture {
     JSRuntime *runtime;
     JSContext *context;
+
+    GjsContext *gjs_context;
 };
 
 void _gjs_unit_test_fixture_begin (GjsUnitTestFixture *fixture);



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