summaryrefslogtreecommitdiff
path: root/javascript/jsapi.h
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2012-06-30 17:38:12 +0100
committerVincent Sanders <vince@kyllikki.org>2012-06-30 17:38:12 +0100
commita911ecaa4815300f6185ca3ed7fbe1954ef512bc (patch)
treec7f56514672e6165d0d797ca351e3cfd2cd5fc14 /javascript/jsapi.h
parent05ee98d1d6a36e7c945879684e669c9ae1699b02 (diff)
downloadnetsurf-a911ecaa4815300f6185ca3ed7fbe1954ef512bc.tar.gz
netsurf-a911ecaa4815300f6185ca3ed7fbe1954ef512bc.tar.bz2
Add compatability code to allow compilation with earlier Spidermonky versions
By using carefuly built macros we can make the spidermonkey binding work on earlier editions of spidermonkey. Some ideas taken from Chris Young and Ole Signed-off-by: Vincent Sanders <vince@netsurf-browser.org>
Diffstat (limited to 'javascript/jsapi.h')
-rw-r--r--javascript/jsapi.h84
1 files changed, 80 insertions, 4 deletions
diff --git a/javascript/jsapi.h b/javascript/jsapi.h
index 82f5f032a..4024d267b 100644
--- a/javascript/jsapi.h
+++ b/javascript/jsapi.h
@@ -30,9 +30,48 @@
#endif
#if JS_VERSION <= 180
-inline JSObject *
-JS_NewCompartmentAndGlobalObject(JSContext *cx,
- JSClass *jsclass,
+
+#include <string.h>
+
+/* *CAUTION* these macros introduce and use jsthis and jsrval
+ * parameters, native function code should not conflict with these
+ */
+
+/* five parameter jsapi native call */
+#define JSAPI_NATIVE(name, cx, argc, vp) \
+ jsapi_native_##name(cx, JSObject *jsthis, argc, vp, jsval *jsrval)
+
+/* five parameter function descriptor */
+#define JSAPI_FS(name, nargs, flags) \
+ JS_FS(#name, jsapi_native_##name, nargs, flags, 0)
+
+/* function descriptor end */
+#define JSAPI_FS_END JS_FS_END
+
+/* return value */
+#define JSAPI_RVAL(cx, vp) JS_RVAL(cx, jsrval)
+
+/* return value setter */
+#define JSAPI_SET_RVAL(cx, vp, v) JS_SET_RVAL(cx, jsrval, v)
+
+/* arguments */
+#define JSAPI_ARGV(cx, vp) (vp)
+
+/* proprty native calls */
+#define JSAPI_PROPERTYGET(name, cx, obj, vp) \
+ jsapi_property_##name##_get(cx, obj, jsval id, vp)
+#define JSAPI_PROPERTYSET(name, cx, obj, vp) \
+ jsapi_property_##name##_set(cx, obj, jsval id, vp)
+
+/* property specifier */
+#define JSAPI_PS(name, tinyid, flags) \
+ { #name , tinyid , flags , jsapi_property_##name##_get , jsapi_property_##name##_set }
+
+#define JSAPI_PS_END { NULL, 0, 0, NULL, NULL }
+
+static inline JSObject *
+JS_NewCompartmentAndGlobalObject(JSContext *cx,
+ JSClass *jsclass,
JSPrincipals *principals)
{
JSObject *global;
@@ -50,7 +89,44 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
txt = JS_GetStringBytes(u16_txt); \
outlen = strlen(txt)
-#else
+#else /* #if JS_VERSION <= 180 */
+
+/* three parameter jsapi native call */
+#define JSAPI_NATIVE(name, cx, argc, vp) jsnative_##name(cx, argc, vp)
+
+/* three parameter function descriptor */
+#define JSAPI_FS(name, nargs, flags) \
+ JS_FS(#name, jsapi_native_##name, nargs, flags)
+
+/* function descriptor end */
+#define JSAPI_FS_END JS_FS_END
+
+/* return value */
+#define JSAPI_RVAL JS_RVAL
+
+/* return value setter */
+#define JSAPI_SET_RVAL JS_SET_RVAL
+
+/* arguments */
+#define JSAPI_ARGV(cx, vp) JS_ARGV(cx,vp)
+
+/* proprty native calls */
+#define JSAPI_PROPERTYGET(name, cx, obj, vp) \
+ jsapi_property_##name##_get(cx, obj, jsid id, vp)
+#define JSAPI_PROPERTYSET(name, cx, obj, vp) \
+ jsapi_property_##name##_set(cx, obj, jsid id, JSBool strict, vp)
+
+/* property specifier */
+#define JSAPI_PS(name, tinyid, flags) { \
+ #name , \
+ tinyid , \
+ flags , \
+ jsapi_property_##name##_get , \
+ jsapi_property_##name##_set \
+ }
+
+#define JSAPI_PS_END { NULL, 0,0,NULL,NULL }
+
#define JSString_to_char(injsstring, outchar, outlen) \
outlen = JS_GetStringLength(injsstring); \