Commits

Sebastien Pahl committed cc78b54

wrap functions coming from spidermonkey

Comments (0)

Files changed (2)

 
 import js.config
 
-if js.config.jsengine == 'v8':
-    from .v8 import Context
-elif js.config.jsengine == 'spidermonkey':
-    from .sm import Context
+# Disabled since v8 is out of date for now
+#if dotcloud.config.jsengine == 'v8':
+#    from .v8 import Context
+#elif dotcloud.config.jsengine == 'spidermonkey':
+#    from .sm import Context
+from .sm import Context
 from error import JSError
 
 __all__ = ["Context", "JSError"]
 # js.py: Python loves Javascript!
 #
 #  Copyright (C) 2009       dotCloud SARL <contact@dotcloud.com>
+#  Copyright (C) 2010       dotCloud Inc. <contact@dotcloud.com>
 #
 #  This file is part of js.py.
 #
 from interfaces import IContext
 
 def convert(obj):
+    if isinstance(obj, spidermonkey.Function):
+        def js_proxy(fn):
+            def proxy(*args, **kwargs):
+                if kwargs:
+                    args = list(args) + [kwargs]
+                return convert(fn(*args))
+            return proxy
+        return js_proxy(obj)
     if isinstance(obj, spidermonkey.Array):
-        return [convert(v) for v in obj]
+        return map(convert, obj)
     if isinstance(obj, spidermonkey.Object):
         return dict((k, convert(obj[k])) for k in obj)
     return obj
     def eval(self, code):
         try:
             return convert(self.__cx.execute(code))
-        except spidermonkey.JSError, e:
+        except spidermonkey.JSError as e:
             raise JSError(e)
-