JS API has changed since version 2.0 in xulrunner. JSClass and callbacks
follow different definitions. Backwark compatibility is kept via an ugly
macros and #ifdef...#else...#endif statement. Let's remove this one once
everyone will have moved to version 2.0 and later for xulrunner.
---
configure.ac | 7 ++++++
plugins/mozjs.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index eabdcc9..4e9681f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,11 +62,18 @@ AC_ARG_ENABLE(mozjs, AC_HELP_STRING([--enable-mozjs],
if (test "${enable_mozjs}" = "yes"); then
PKG_CHECK_MODULES(MOZJS, mozilla-js >= 1.9, dummy=yes,
AC_MSG_ERROR(Mozilla Javascript >= 1.9 is required))
+
+ mozjs_version=`pkg-config --modversion mozilla-js | cut -d '.' -f 1`
+ if test ${mozjs_version} -gt 1; then
+ MOZJS_CFLAGS="${MOZJS_CFLAGS} -DMOZJS_VERSION_2_OR_SUPERIOR=1"
+ fi
+
AC_SUBST(MOZJS_CFLAGS)
AC_SUBST(MOZJS_LIBS)
fi
AM_CONDITIONAL(MOZJS, test "${enable_mozjs}" = "yes")
+
AC_ARG_ENABLE(v8, AC_HELP_STRING([--enable-v8],
[enable V8 Javascript plugin support]))
if (test "${enable_v8}" = "yes"); then
diff --git a/plugins/mozjs.c b/plugins/mozjs.c
index 9f18d33..ae5033d 100644
--- a/plugins/mozjs.c
+++ b/plugins/mozjs.c
@@ -88,6 +88,59 @@ static int resolve(const char *node, char *host, size_t
hostlen)
return 0;
}
+#ifdef MOZJS_VERSION_2_OR_SUPERIOR
+
+static JSBool myipaddress(JSContext *ctx, uintN argc, jsval *vp)
+{
+ const char *interface;
+ char address[NI_MAXHOST];
+
+ DBG("");
+
+ JS_SET_RVAL(ctx, vp, JSVAL_NULL);
+
+ if (current_proxy == NULL)
+ return JS_TRUE;
+
+ interface = pacrunner_proxy_get_interface(current_proxy);
+ if (interface == NULL)
+ return JS_TRUE;
+
+ if (getaddr(interface, address, sizeof(address)) < 0)
+ return JS_TRUE;
+
+ DBG("address %s", address);
+
+ JS_SET_RVAL(ctx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(ctx, address)));
+
+ return JS_TRUE;
+}
+
+static JSBool dnsresolve(JSContext *ctx, uintN argc, jsval *vp)
+{
+ char address[NI_MAXHOST];
+ jsval *argv = JS_ARGV(ctx, vp);
+ char *host = JS_EncodeString(ctx, JS_ValueToString(ctx, argv[0]));
+
+ DBG("host %s", host);
+
+ JS_SET_RVAL(ctx, vp, JSVAL_NULL);
+
+ if (resolve(host, address, sizeof(address)) < 0)
+ goto out;
+
+ DBG("address %s", address);
+
+ JS_SET_RVAL(ctx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(ctx, address)));
+
+ out:
+ JS_free(ctx, host);
+ return JS_TRUE;
+
+}
+
+#else
+
static JSBool myipaddress(JSContext *ctx, JSObject *obj, uintN argc,
jsval *argv, jsval *rval)
{
@@ -136,10 +189,16 @@ static JSBool dnsresolve(JSContext *ctx, JSObject *obj,
uintN argc,
JS_free(ctx, host);
return JS_TRUE;
}
+#endif
static JSClass jscls = {
"global", JSCLASS_GLOBAL_FLAGS,
+#ifdef MOZJS_VERSION_2_OR_SUPERIOR
+ JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
+ JS_StrictPropertyStub,
+#else
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
+#endif
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
--
1.7.8
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman