summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Joseph Davis <davisp@apache.org>2009-11-27 22:43:59 +0000
committerPaul Joseph Davis <davisp@apache.org>2009-11-27 22:43:59 +0000
commit685c4a2023bfae17220fb20b9ee6e72f44b019ec (patch)
treeaff0f277a015f09426d7b6add570e6de8a28594a /src
parent32bf31cc5af8bc87aae1b787fe83140fb7d9a9e1 (diff)
Fix weird error with JS_DefineFunctions call.
I found a fairly odd case with JS_DefineFunctions returning success without actually having defined any functions on the global object. This was happening on an Ubuntu 9.10 machine with Spidermonkey 1.7 which is most odd. I refactored the code to iterate over the JSFunctionSpec array and define the functions one by one which appears to alleviate the issue. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@885041 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/priv/couch_js/main.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/couchdb/priv/couch_js/main.c b/src/couchdb/priv/couch_js/main.c
index f8578375..376aa15b 100644
--- a/src/couchdb/priv/couch_js/main.c
+++ b/src/couchdb/priv/couch_js/main.c
@@ -276,7 +276,8 @@ main(int argc, const char * argv[])
{
JSRuntime* rt = NULL;
JSContext* cx = NULL;
- JSObject *global = NULL;
+ JSObject* global = NULL;
+ JSFunctionSpec* sp = NULL;
int i = 0;
rt = JS_NewRuntime(64L * 1024L * 1024L);
@@ -293,10 +294,15 @@ main(int argc, const char * argv[])
global = JS_NewObject(cx, &global_class, NULL, NULL);
if (!global) return 1;
if (!JS_InitStandardClasses(cx, global)) return 1;
-
- if(!JS_DefineFunctions(cx, global, global_functions))
+
+ for(sp = global_functions; sp->name != NULL; sp++)
{
- return 1;
+ if(!JS_DefineFunction(cx, global,
+ sp->name, sp->call, sp->nargs, sp->flags))
+ {
+ fprintf(stderr, "Failed to create function: %s\n", sp->name);
+ return 1;
+ }
}
if(!install_http(cx, global))