grafthistory: support curl
[elinks/elinks-j605.git] / src / ecmascript / spidermonkey / util.c
blobccddbcd3dc73f8b4fb08614b76ed85cd70a0d90c
1 /* Better compatibility across versions of SpiderMonkey. */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include "elinks.h"
9 #include "ecmascript/spidermonkey/util.h"
11 /** An ELinks-specific replacement for JS_DefineFunctions().
13 * @relates spidermonkeyFunctionSpec */
14 JSBool
15 spidermonkey_DefineFunctions(JSContext *cx, JSObject *obj,
16 const spidermonkeyFunctionSpec *fs)
18 for (; fs->name; fs++) {
19 if (!JS_DefineFunction(cx, obj, fs->name, fs->call,
20 fs->nargs, 0))
21 return JS_FALSE;
23 return JS_TRUE;
26 /** An ELinks-specific replacement for JS_InitClass().
28 * @relates spidermonkeyFunctionSpec */
29 JSObject *
30 spidermonkey_InitClass(JSContext *cx, JSObject *obj,
31 JSObject *parent_proto, JSClass *clasp,
32 JSNative constructor, uintN nargs,
33 JSPropertySpec *ps,
34 const spidermonkeyFunctionSpec *fs,
35 JSPropertySpec *static_ps,
36 const spidermonkeyFunctionSpec *static_fs)
38 JSObject *proto = JS_InitClass(cx, obj, parent_proto, clasp,
39 constructor, nargs,
40 ps, NULL, static_ps, NULL);
42 if (proto == NULL)
43 return NULL;
45 if (fs) {
46 if (!spidermonkey_DefineFunctions(cx, proto, fs))
47 return NULL;
50 if (static_fs) {
51 JSObject *cons_obj = JS_GetConstructor(cx, proto);
53 if (cons_obj == NULL)
54 return NULL;
55 if (!spidermonkey_DefineFunctions(cx, cons_obj, static_fs))
56 return NULL;
59 return proto;