mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-24 04:56:50 +03:00
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>
This commit is contained in:
parent
05ee98d1d6
commit
a911ecaa48
@ -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); \
|
||||
|
@ -21,92 +21,92 @@
|
||||
//#include "content/content.h"
|
||||
#include "utils/log.h"
|
||||
|
||||
static JSBool jsdebug(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(debug, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jsdir(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(dir, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jserror(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(error, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jsgroup(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(group, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jsgroupCollapsed(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(groupCollapsed, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jsgroupEnd(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(groupEnd, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jsinfo(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(info, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jslog(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(log, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jstime(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(time, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jstimeEnd(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(timeEnd, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jstrace(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(trace, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jswarn(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(warn, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSFunctionSpec jsfunctions_console[] = {
|
||||
JS_FS("debug", jsdebug, 1, 0),
|
||||
JS_FS("dir", jsdir, 1, 0),
|
||||
JS_FS("error", jserror, 1, 0),
|
||||
JS_FS("group", jsgroup, 1, 0),
|
||||
JS_FS("groupCollapsed", jsgroupCollapsed, 1, 0),
|
||||
JS_FS("groupEnd", jsgroupEnd, 1, 0),
|
||||
JS_FS("info", jsinfo, 1, 0),
|
||||
JS_FS("log", jslog, 1, 0),
|
||||
JS_FS("time", jstime, 1, 0),
|
||||
JS_FS("timeEnd", jstimeEnd, 1, 0),
|
||||
JS_FS("trace", jstrace, 1, 0),
|
||||
JS_FS("warn", jswarn, 1, 0),
|
||||
JS_FS_END
|
||||
JSAPI_FS(debug, 1, 0),
|
||||
JSAPI_FS(dir, 1, 0),
|
||||
JSAPI_FS(error, 1, 0),
|
||||
JSAPI_FS(group, 1, 0),
|
||||
JSAPI_FS(groupCollapsed, 1, 0),
|
||||
JSAPI_FS(groupEnd, 1, 0),
|
||||
JSAPI_FS(info, 1, 0),
|
||||
JSAPI_FS(log, 1, 0),
|
||||
JSAPI_FS(time, 1, 0),
|
||||
JSAPI_FS(timeEnd, 1, 0),
|
||||
JSAPI_FS(trace, 1, 0),
|
||||
JSAPI_FS(warn, 1, 0),
|
||||
JSAPI_FS_END
|
||||
};
|
||||
|
||||
static JSClass jsclass_console =
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "content/content.h"
|
||||
#include "utils/log.h"
|
||||
|
||||
/* IDL
|
||||
/* IDL
|
||||
|
||||
[NamedPropertiesObject]
|
||||
interface Window : EventTarget {
|
||||
@ -29,7 +29,7 @@ interface Window : EventTarget {
|
||||
[Unforgeable] readonly attribute WindowProxy window;
|
||||
[Replaceable] readonly attribute WindowProxy self;
|
||||
[Unforgeable] readonly attribute Document document;
|
||||
attribute DOMString name;
|
||||
attribute DOMString name;
|
||||
[PutForwards=href, Unforgeable] readonly attribute Location location;
|
||||
readonly attribute History history;
|
||||
|
||||
@ -41,7 +41,7 @@ interface Window : EventTarget {
|
||||
[Replaceable] readonly attribute BarProp scrollbars;
|
||||
[Replaceable] readonly attribute BarProp statusbar;
|
||||
[Replaceable] readonly attribute BarProp toolbar;
|
||||
attribute DOMString status;
|
||||
attribute DOMString status;
|
||||
void close();
|
||||
void stop();
|
||||
void focus();
|
||||
@ -51,7 +51,7 @@ interface Window : EventTarget {
|
||||
[Replaceable] readonly attribute WindowProxy frames;
|
||||
[Replaceable] readonly attribute unsigned long length;
|
||||
[Unforgeable] readonly attribute WindowProxy top;
|
||||
attribute WindowProxy? opener;
|
||||
attribute WindowProxy? opener;
|
||||
readonly attribute WindowProxy parent;
|
||||
readonly attribute Element? frameElement;
|
||||
WindowProxy open(optional DOMString url, optional DOMString target, optional DOMString features, optional boolean replace);
|
||||
@ -59,7 +59,7 @@ interface Window : EventTarget {
|
||||
getter object (DOMString name);
|
||||
|
||||
// the user agent
|
||||
readonly attribute Navigator navigator;
|
||||
readonly attribute Navigator navigator;
|
||||
readonly attribute External external;
|
||||
readonly attribute ApplicationCache applicationCache;
|
||||
|
||||
@ -147,77 +147,88 @@ interface Window : EventTarget {
|
||||
*/
|
||||
|
||||
|
||||
static JSBool jsnative_alert(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(alert, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JSString* u16_txt;
|
||||
char *txt;
|
||||
unsigned long length;
|
||||
|
||||
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &u16_txt))
|
||||
if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
|
||||
return JS_FALSE;
|
||||
|
||||
JSString_to_char(u16_txt, txt, length);
|
||||
|
||||
warn_user(txt, NULL);
|
||||
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jsnative_confirm(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(confirm, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JSString* u16_txt;
|
||||
char *txt;
|
||||
unsigned long length;
|
||||
JSBool result = JS_FALSE;
|
||||
|
||||
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &u16_txt))
|
||||
if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
|
||||
return JS_FALSE;
|
||||
|
||||
JSString_to_char(u16_txt, txt, length);
|
||||
|
||||
warn_user(txt, NULL);
|
||||
|
||||
JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(result));
|
||||
|
||||
JSAPI_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(result));
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jsnative_prompt(JSContext *cx, uintN argc, jsval *vp)
|
||||
static JSBool JSAPI_NATIVE(prompt, JSContext *cx, uintN argc, jsval *vp)
|
||||
{
|
||||
JSString* u16_txt;
|
||||
char *txt;
|
||||
unsigned long length;
|
||||
|
||||
if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &u16_txt))
|
||||
if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
|
||||
return JS_FALSE;
|
||||
|
||||
JSString_to_char(u16_txt, txt, length);
|
||||
|
||||
warn_user(txt, NULL);
|
||||
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
|
||||
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSFunctionSpec jsfunctions_window[] =
|
||||
{
|
||||
JS_FN("alert", jsnative_alert, 1, 0),
|
||||
JS_FN("confirm", jsnative_confirm, 1, 0),
|
||||
JS_FN("prompt", jsnative_prompt, 1, 0),
|
||||
JS_FS_END
|
||||
JSAPI_FS(alert, 1, 0),
|
||||
JSAPI_FS(confirm, 1, 0),
|
||||
JSAPI_FS(prompt, 1, 0),
|
||||
JSAPI_FS_END
|
||||
};
|
||||
|
||||
|
||||
static JSBool jsproperty_get_window(JSContext *ctx, JSObject *obj, jsid id, jsval *vp)
|
||||
static JSBool JSAPI_PROPERTYGET(window, JSContext *cx, JSObject *obj, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool jsproperty_set_window(JSContext *ctx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
|
||||
static JSBool JSAPI_PROPERTYSET(window, JSContext *cx, JSObject *obj, jsval *vp)
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
static JSBool JSAPI_PROPERTYGET(self, JSContext *cx, JSObject *obj, jsval *vp)
|
||||
{
|
||||
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool JSAPI_PROPERTYSET(self, JSContext *cx, JSObject *obj, jsval *vp)
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
@ -225,32 +236,22 @@ static JSBool jsproperty_set_window(JSContext *ctx, JSObject *obj, jsid id, JSBo
|
||||
|
||||
static JSPropertySpec jsproperties_window[] =
|
||||
{
|
||||
{ "window",
|
||||
0,
|
||||
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED,
|
||||
jsproperty_get_window,
|
||||
jsproperty_set_window
|
||||
},
|
||||
{ "self",
|
||||
0,
|
||||
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED,
|
||||
jsproperty_get_window,
|
||||
jsproperty_set_window
|
||||
},
|
||||
{ NULL, 0,0,NULL,NULL }
|
||||
JSAPI_PS(window, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
|
||||
JSAPI_PS(self, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_SHARED),
|
||||
JSAPI_PS_END
|
||||
};
|
||||
|
||||
/* The class of the global object. */
|
||||
static JSClass jsclass_window = {
|
||||
"window",
|
||||
"window",
|
||||
JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
JS_StrictPropertyStub,
|
||||
JS_EnumerateStub,
|
||||
JS_ResolveStub,
|
||||
JS_ConvertStub,
|
||||
JS_EnumerateStub,
|
||||
JS_ResolveStub,
|
||||
JS_ConvertStub,
|
||||
JS_FinalizeStub,
|
||||
JSCLASS_NO_OPTIONAL_MEMBERS
|
||||
};
|
||||
@ -259,7 +260,7 @@ static JSClass jsclass_window = {
|
||||
JSObject * jsapi_new_window(JSContext *cx, JSObject *parent, void *win_priv)
|
||||
{
|
||||
JSObject *window = NULL;
|
||||
|
||||
|
||||
if (parent == NULL) {
|
||||
window = JS_NewCompartmentAndGlobalObject(cx, &jsclass_window, NULL);
|
||||
if (window == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user