From 685c4a2023bfae17220fb20b9ee6e72f44b019ec Mon Sep 17 00:00:00 2001 From: Paul Joseph Davis Date: Fri, 27 Nov 2009 22:43:59 +0000 Subject: 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 --- src/couchdb/priv/couch_js/main.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') 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)) -- cgit v1.2.3