From a911ecaa4815300f6185ca3ed7fbe1954ef512bc Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 30 Jun 2012 17:38:12 +0100 Subject: 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 --- javascript/jsapi.h | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 4 deletions(-) (limited to 'javascript/jsapi.h') 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 + +/* *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); \ -- cgit v1.2.3