summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2013-04-12 12:29:07 -0400
committerColin Walters <walters@verbum.org>2013-04-23 10:49:12 -0400
commit0966ffc16bbd2998d7dad3064506e7a998d54bbb (patch)
tree76c18c886920bdf5d1190056056442b098589216
parent8ed4cb000ed420bf2f899770cab098dde96621f2 (diff)
downloadpolkit-0966ffc16bbd2998d7dad3064506e7a998d54bbb.tar.gz
jsauthority: Work with mozjs-17.0 too
Based on work by Tim Lunn <tim@feathertop.org>, reworked on top of a regular dynamically-linked js. https://bugs.freedesktop.org/show_bug.cgi?id=59830
-rw-r--r--configure.ac13
-rw-r--r--src/polkitbackend/polkitbackendjsauthority.c51
2 files changed, 57 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac
index 73a978e..d2eea92 100644
--- a/configure.ac
+++ b/configure.ac
@@ -129,7 +129,18 @@ AC_DEFINE([GLIB_VERSION_MIN_REQUIRED], [GLIB_VERSION_2_30],
AC_DEFINE([GLIB_VERSION_MAX_ALLOWED], [G_ENCODE_VERSION(2,34)],
[Notify us when we'll need to transition away from g_type_init()])
-PKG_CHECK_MODULES(LIBJS, [mozjs185])
+AC_ARG_WITH(mozjs, AS_HELP_STRING([--with-mozjs=@<:@mozjs185/mozjs-17.0|auto@:>@],
+ [Specify version of Spidermonkey to use]),,
+ with_mozjs=auto)
+AS_IF([test x${with_mozjs} != xauto], [
+ PKG_CHECK_MODULES(LIBJS, ${with_mozjs})
+], [
+ PKG_CHECK_MODULES(LIBJS, [mozjs185], have_mozjs185=yes, have_mozjs185=no)
+ AS_IF([test x${have_mozjs185} = xno], [
+ PKG_CHECK_MODULES(LIBJS, [mozjs-17.0], have_mozjs17=yes,
+ [AC_MSG_ERROR([Could not find mozjs185 or mozjs-17.0; see http://ftp.mozilla.org/pub/mozilla.org/js/])])
+ ])
+])
AC_SUBST(LIBJS_CFLAGS)
AC_SUBST(LIBJS_LIBS)
diff --git a/src/polkitbackend/polkitbackendjsauthority.c b/src/polkitbackend/polkitbackendjsauthority.c
index 05302b5..3eeca21 100644
--- a/src/polkitbackend/polkitbackendjsauthority.c
+++ b/src/polkitbackend/polkitbackendjsauthority.c
@@ -79,7 +79,11 @@ struct _PolkitBackendJsAuthorityPrivate
};
static JSBool execute_script_with_runaway_killer (PolkitBackendJsAuthority *authority,
+#if JS_VERSION == 186
+ JSScript *script,
+#else
JSObject *script,
+#endif
jsval *rval);
static void utils_spawn (const gchar *const *argv,
@@ -146,7 +150,11 @@ static JSClass js_global_class = {
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
+#if JS_VERSION == 186
+ NULL,
+#else
JS_FinalizeStub,
+#endif
JSCLASS_NO_OPTIONAL_MEMBERS
};
@@ -162,7 +170,11 @@ static JSClass js_polkit_class = {
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
+#if JS_VERSION == 186
+ NULL,
+#else
JS_FinalizeStub,
+#endif
JSCLASS_NO_OPTIONAL_MEMBERS
};
@@ -274,11 +286,22 @@ load_scripts (PolkitBackendJsAuthority *authority)
for (l = files; l != NULL; l = l->next)
{
const gchar *filename = l->data;
+#if JS_VERSION == 186
+ JSScript *script;
+#else
JSObject *script;
-
+#endif
+
+#if JS_VERSION == 186
+ script = JS_CompileUTF8File (authority->priv->cx,
+ authority->priv->js_global,
+ filename);
+
+#else
script = JS_CompileFile (authority->priv->cx,
- authority->priv->js_global,
- filename);
+ authority->priv->js_global,
+ filename);
+#endif
if (script == NULL)
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
@@ -330,7 +353,11 @@ reload_scripts (PolkitBackendJsAuthority *authority)
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
"Collecting garbage unconditionally...");
+#if JS_VERSION == 186
+ JS_GC (authority->priv->rt);
+#else
JS_GC (authority->priv->cx);
+#endif
load_scripts (authority);
@@ -439,9 +466,13 @@ polkit_backend_js_authority_constructed (GObject *object)
JS_SetErrorReporter(authority->priv->cx, report_error);
JS_SetContextPrivate (authority->priv->cx, authority);
- authority->priv->js_global = JS_NewCompartmentAndGlobalObject (authority->priv->cx,
- &js_global_class,
- NULL);
+ authority->priv->js_global =
+#if JS_VERSION == 186
+ JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL);
+#else
+ JS_NewCompartmentAndGlobalObject (authority->priv->cx, &js_global_class, NULL);
+#endif
+
if (authority->priv->js_global == NULL)
goto fail;
@@ -918,7 +949,11 @@ rkt_on_timeout (gpointer user_data)
PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (user_data);
/* Supposedly this is thread-safe... */
+#if JS_VERSION == 186
+ JS_TriggerOperationCallback (authority->priv->rt);
+#else
JS_TriggerOperationCallback (authority->priv->cx);
+#endif
/* keep source around so we keep trying to kill even if the JS bit catches the exception
* thrown in js_operation_callback()
@@ -953,7 +988,11 @@ runaway_killer_teardown (PolkitBackendJsAuthority *authority)
static JSBool
execute_script_with_runaway_killer (PolkitBackendJsAuthority *authority,
+#if JS_VERSION == 186
+ JSScript *script,
+#else
JSObject *script,
+#endif
jsval *rval)
{
JSBool ret;