couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r885041 - /couchdb/trunk/src/couchdb/priv/couch_js/main.c
Date Fri, 27 Nov 2009 22:43:59 GMT
Author: davisp
Date: Fri Nov 27 22:43:59 2009
New Revision: 885041

URL: http://svn.apache.org/viewvc?rev=885041&view=rev
Log:
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.


Modified:
    couchdb/trunk/src/couchdb/priv/couch_js/main.c

Modified: couchdb/trunk/src/couchdb/priv/couch_js/main.c
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/priv/couch_js/main.c?rev=885041&r1=885040&r2=885041&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/priv/couch_js/main.c (original)
+++ couchdb/trunk/src/couchdb/priv/couch_js/main.c Fri Nov 27 22:43:59 2009
@@ -276,7 +276,8 @@
 {
     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 @@
     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))



Mime
View raw message