Commits

Anonymous committed c3175c8

Removed cruft in the source directory.

Fixed MANIFEST.in with a pointer from Roberto.

Comments (0)

Files changed (24)

 include go
 include go.comm
 include setup.py
-include spidermonkey/*.*
-include spidermonkey/libjs/*.*
+recursive-include spidermonkey *
 include tests/*.py
 Scott T Silliman
     * Provided Gentoo package names.
 
+Roberto De Almeida
+    * Pointer on MANIFEST.in

old-sm/jsapi.pxi

-
-
-ctypedef int uint8
-ctypedef int uint16
-ctypedef int uint32
-ctypedef int uintN
-ctypedef int size_t
-
-ctypedef char jschar
-ctypedef double jsdouble
-ctypedef int jsid
-ctypedef int jsint
-ctypedef int jsuint
-IF UNAME_MACHINE == "x86_64" or UNAME_MACHINE == "amd64":
-    ctypedef long jsval
-ELSE:
-    ctypedef int jsval
-ctypedef int JSBool
-
-cdef extern from "stdio.h":
-    cdef int printf(char* format, ...)
-
-cdef extern from "string.h":
-    cdef char* strcpy(char* restrict, char* restrict)
-    cdef void* memcpy(void* dest, void* src, size_t num)
-
-cdef extern from "stdlib.h":
-    cdef void* malloc(size_t size)
-    cdef void free(void* mem)
-
-cdef extern from "Python.h":
-    cdef struct PyObject
-    cdef void Py_DECREF(PyObject* o)
-    cdef PyObject* PyString_FromStringAndSize(char* buf, size_t length)
-    cdef int PyString_AsStringAndSize(PyObject* str, char** buf, int* length)
-
-cdef extern from "jsapi.h":
-    cdef struct JSClass
-    cdef struct JSContext
-    cdef struct JSErrorReport
-    cdef struct JSFunction
-    cdef struct JSFunctionSpec
-    cdef struct JSString
-    cdef struct JSObject
-    cdef struct JSObjectOps
-    cdef struct JSRuntime
-    cdef struct JSPropertySpec
-    cdef struct JSXDRState
-
-    cdef enum:
-        JS_TRUE
-        JS_FALSE
-        JSVAL_VOID
-        JSVAL_INT
-        JSPROP_ENUMERATE
-        JSPROP_READONLY
-        JS_CLASS_NO_INSTANCE
-        JSCLASS_HAS_PRIVATE
-
-    cdef enum JSType:
-        JSTYPE_VOID
-        JSTYPE_OBJECT
-        JSTYPE_FUNCTION
-        JSTYPE_STRING
-        JSTYPE_NUMBER
-        JSTYPE_BOOLEAN
-        JSTYPE_LIMIT
-
-    cdef enum JSAccessMode:
-        JSACC_PROTO = 0
-        JSACC_PARENT = 1
-        JSACC_IMPORT = 2
-        JSACC_WATCH = 3
-        JSACC_READ = 4
-        JSACC_WRITE = 8
-        JSACC_LIMIT
-
-    ctypedef JSBool (*JSPropertyOp) (JSContext* cx, JSObject* obj, jsval id, jsval* vp)
-    ctypedef JSBool (*JSEnumerateOp) (JSContext* cx, JSObject* obj)
-    ctypedef JSBool (*JSResolveOp) (JSContext* cx, JSObject* obj, jsval id)
-    ctypedef JSBool (*JSConvertOp) (JSContext* cx, JSObject* obj, JSType type, jsval* vp)
-    ctypedef void (*JSFinalizeOp) (JSContext* cx, JSObject* obj)
-    ctypedef JSObjectOps* (*JSGetObjectOps) (JSContext* cx, JSClass* clasp)
-    ctypedef JSBool (*JSCheckAccessOp) (JSContext* cx, JSObject* obj, jsval id, JSAccessMode mode, jsval* vp)
-    ctypedef JSBool (*JSXDRObjectOp) (JSXDRState* xdr, JSObject** objp)
-    ctypedef JSBool (*JSHasInstanceOp) (JSContext* cx, JSObject* obj, jsval v, JSBool* bp)
-    ctypedef uint32 (*JSMarkOp) (JSContext* cx, JSObject* obj, void* arg)
-    ctypedef JSBool (*JSNative) (JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval)
-    ctypedef void (*JSErrorReporter) (JSContext* cx, char* message, JSErrorReport* report)
-    
-    cdef struct JSClass:
-        char *name
-        uint32 flags
-
-        # Mandatory non-null function pointer members.
-        JSPropertyOp addProperty
-        JSPropertyOp delProperty
-        JSPropertyOp getProperty
-        JSPropertyOp setProperty
-        JSEnumerateOp enumerate
-        JSResolveOp resolve
-        JSConvertOp convert
-        JSFinalizeOp finalize
-
-        # Optionally non-null members start here.
-        JSGetObjectOps getObjectOps
-        JSCheckAccessOp checkAccess
-        JSNative call
-        JSNative construct
-        JSXDRObjectOp xdrObject
-        JSHasInstanceOp hasInstance
-        JSMarkOp mark
-        void* reserveSlots
-
-    cdef struct JSErrorReport:
-        char* filename
-        uintN lineno
-        char* linebuf
-        char* tokenptr
-        jschar* uclinebuf
-        jschar* uctokenptr
-        uintN flags
-        uintN errorNumber
-        jschar* ucmessage
-        jschar** messageArgs
-
-    cdef struct JSFunctionSpec:
-        char *name
-        JSNative call
-        uint8 nargs
-        uint8 flags
-        uint16 extra  # number of arg slots for local GC roots
-
-    cdef struct JSIdArray:
-        jsint length
-        jsid  vector[1]  # actually, length jsid words
-
-    cdef JSBool JSVAL_IS_BOOLEAN(jsval v)
-    cdef JSBool JSVAL_IS_DOUBLE(jsval v)
-    cdef JSBool JSVAL_IS_GCTHING(jsval v)
-    cdef JSBool JSVAL_IS_INT(jsval v)
-    cdef JSBool JSVAL_IS_NULL(jsval v)
-    cdef JSBool JSVAL_IS_NUMBER(jsval v)
-    cdef JSBool JSVAL_IS_OBJECT(jsval v)
-    cdef JSBool JSVAL_IS_PRIMITIVE(jsval v)
-    cdef JSBool JSVAL_IS_STRING(jsval v)
-    cdef JSBool JSVAL_IS_VOID(jsval v)
-
-    cdef JSBool JSVAL_TO_BOOLEAN(jsval v)
-    cdef jsdouble* JSVAL_TO_DOUBLE(jsval v)
-    cdef void* JSVAL_TO_GCTHING(jsval v)
-    cdef int JSVAL_TO_INT(jsval v)
-    cdef JSObject* JSVAL_TO_OBJECT(jsval v)
-    cdef JSString* JSVAL_TO_STRING(jsval v)
-    cdef void* JSVAL_TO_PRIVATE(jsval v)
-    cdef JSString* JSVAL_TO_STRING(jsval v)
-
-    cdef jsval BOOLEAN_TO_JSVAL(JSBool b)
-    cdef jsval DOUBLE_TO_JSVAL(jsdouble* dp)
-    cdef jsval INT_TO_JSVAL(int i)
-    cdef jsval OBJECT_TO_JSVAL(JSObject* obj)    
-    cdef jsval PRIVATE_TO_JSVAL(void* p)
-    cdef jsval STRING_TO_JSVAL(JSString* str)
-
-    cdef int JSVAL_TAG(jsval v)
-    cdef void JSVAL_SETTAG(jsval v, int t)
-    cdef void JSVAL_CLRTAG(jsval v)
-
-    # Runtime Functions
-    cdef JSRuntime* JS_NewRuntime(uint32 maxbytes)
-    cdef void JS_DestroyRuntime(JSRuntime* rt)
-    cdef JSContext* JS_ContextIterator(JSRuntime* rt, JSContext** iterp)
-
-    # Context Functions
-    cdef JSContext* JS_NewContext(JSRuntime* rt, size_t stackChunkSize)
-    cdef void JS_DestroyContext(JSContext* cx)
-    cdef JSRuntime* JS_GetRuntime(JSContext* cx)
-    cdef JSObject* JS_GetGlobalObject(JSContext* cx)
-    cdef void* JS_GetContextPrivate(JSContext* cx)
-    cdef void JS_SetContextPrivate(JSContext* cx, void* data)
-    
-    # Type Functions
-    cdef JSType JS_TypeOfValue(JSContext* cx, jsval v)
-
-    # Class Functions
-    cdef JSBool JS_InitStandardClasses(JSContext* cx, JSObject* obj)
-    cdef JSObject* JS_GetClassObject(JSClass* klass)
-
-    cdef JSObject* JS_InitClass(
-        JSContext* cx,
-        JSObject* obj,
-        JSObject* parent_proto,
-        JSClass* clasp,
-        JSNative constructor,
-        uintN nargs,
-        JSPropertySpec* ps,
-        JSFunctionSpec* fs,
-        JSPropertySpec* static_ps,
-        JSFunctionSpec* static_fs
-    )
-
-    cdef JSBool JS_PropertyStub(JSContext* cx, JSObject* obj, jsval id, jsval* vp)
-    cdef JSBool JS_EnumerateStub(JSContext* cx, JSObject* obj)
-    cdef JSBool JS_ResolveStub(JSContext* cx, JSObject* obj, jsval id)
-    cdef JSBool JS_ConvertStub(JSContext* cx, JSObject* obj, JSType type, jsval* vp)
-    cdef void JS_FinalizeStub(JSContext* cx, JSObject* obj)
-
-    # Object Functions
-    # Create an object as a property of another object.
-    cdef JSObject* JS_DefineObject(
-        JSContext* cx,
-        JSObject* obj,
-        char* name,
-        JSClass* clasp,
-        JSObject* proto,
-        uintN attrs
-    )
-    
-    # Create an object
-    cdef JSObject* JS_NewObject(
-        JSContext* cx,
-        JSClass* clasp,
-        JSObject* proto,
-        JSObject* parent
-    )
-    
-    cdef JSClass* JS_GetClass(JSContext* cx, JSObject* obj)
-    cdef JSObject* JS_GetPrototype(JSContext* cx, JSObject* obj)
-    cdef JSIdArray* JS_Enumerate(JSContext* cx, JSObject* obj)
-    cdef void* JS_GetPrivate(JSContext* cx, JSObject* obj)
-    cdef JSBool JS_SetPrivate(JSContext* cx, JSObject* obj, void* data)
-
-    # Property Methods
-    cdef JSBool JS_GetUCProperty(JSContext* cx, JSObject* obj, jschar* name, size_t slen, jsval* vp)
-    cdef JSBool JS_SetUCProperty(JSContext* cx, JSObject* obj, jschar* name, size_t slen, jsval* vp)
-    cdef JSBool JS_DeleteUCProperty2(JSContext* cx, JSObject* obj, jschar* name, size_t slen, jsval* vp)
-
-    cdef JSBool JS_DefineUCProperty(
-        JSContext* cx,
-        JSObject* obj,
-        jschar* name,
-        size_t slen,
-        jsval value,
-        JSPropertyOp getter,
-        JSPropertyOp setter,
-        uintN attrs
-    )
-
-    # Array Functions
-    cdef JSBool JS_IsArrayObject(JSContext* cx, JSObject* obj)
-    cdef JSObject* JS_NewArrayObject(JSContext* cx, jsint length, jsval* vector)
-    cdef JSBool JS_GetArrayLength(JSContext* cx, JSObject* obj, jsuint* lengthp)
-    cdef JSBool JS_GetElement(JSContext* cx, JSObject* obj, jsint index, jsval* vp)
-    cdef JSBool JS_SetElement(JSContext* cx, JSObject* obj, jsint index, jsval* vp)
-
-    cdef JSBool JS_DefineElement(
-        JSContext* cx,
-        JSObject* obj,
-        jsint index,
-        jsval value,
-        JSPropertyOp getter,
-        JSPropertyOp setter,
-        uintN attrs
-    )
-
-    # Function Functions
-    cdef char* JS_GetFunctionName(JSFunction* fun)
-    cdef JSBool JS_ObjectIsFunction(JSContext* cx, JSObject* obj)
-    cdef JSObject* JS_GetFunctionObject(JSFunction* fun)
-    cdef JSFunction* JS_ValueToFunction(JSContext* cx, jsval v)
-    
-    # Not necessarily specific to functions, but used for the undocumented
-    # reserved slots.
-    JSBool JS_GetReservedSlot(JSContext* cx, JSObject* obj, uint32 index, jsval* vp)
-    JSBool JS_SetReservedSlot(JSContext* cx, JSObject* obj, uint32 index, jsval v)
-    
-    # Set a list of functions on an object
-    cdef JSBool JS_DefineFunctions(JSContext* cx, JSObject* obj, JSFunctionSpec* fs)
-    
-    # Create a function property
-    cdef JSFunction* JS_DefineUCFunction(
-        JSContext* cx,
-        JSObject* obj,
-        char* name,
-        JSNative call,
-        uintN nargs,
-        uintN attrs
-    )
-    
-    # Create an anonymous function
-    cdef JSFunction* JS_NewFunction(
-        JSContext* cx,
-        JSNative call,
-        uintN nargs,
-        uintN flags,
-        JSObject* parent,
-        char* name
-    )
-    
-    # Call a named function
-    cdef JSBool JS_CallFunctionName(
-        JSContext* cx,
-        JSObject* obj,
-        char* name,
-        uintN argc,
-        jsval* argv,
-        jsval* rval
-    ) except *
-    
-    # Call a function by jsval reference
-    cdef JSBool JS_CallFunctionValue(
-        JSContext* cx,
-        JSObject* obj,
-        jsval fun,
-        uintN argc,
-        jsval* argv,
-        jsval* rval
-    ) except *
-
-    # String Functions
-    cdef JSString* JS_NewUCStringCopyN(JSContext* cx, jschar* s, size_t n)
-    cdef char* JS_GetStringBytes(JSString* str)
-    cdef jschar* JS_GetStringChars(JSString* str)
-    cdef size_t JS_GetStringLength(JSString* str)
-
-    # Double Functions
-    cdef JSBool JS_NewNumberValue(JSContext* cx, jsdouble d, jsval* rval)
-
-    # IdArray Functions
-    cdef JSBool JS_IdToValue(JSContext* cx, jsid id, jsval* vp)
-    cdef void JS_DestroyIdArray(JSContext* cx, JSIdArray* ida)
-
-    # Memory Functions
-    cdef void JS_GC(JSContext *cx)
-    cdef void JS_MaybeGC(JSContext* cx)
-    cdef void JS_free(JSContext* cx, void* p)
-    cdef JSBool JS_AddRoot(JSContext* cx, void* rp)
-    cdef JSBool JS_AddNamedRoot(JSContext* cx, void* rp, char* name)
-    cdef JSBool JS_RemoveRoot(JSContext* cx, void* rp)
-
-    # Error Reporting
-    cdef JSBool JS_IsExceptionPending(JSContext* cx)
-    cdef JSBool JS_GetPendingException(JSContext* cx, jsval* vp)
-    cdef void JS_SetPendingException(JSContext* cx, jsval v)
-    cdef void JS_ClearPendingException(JSContext* cx)
-    
-    cdef JSErrorReporter JS_SetErrorReporter(JSContext* cx, JSErrorReporter er)
-    cdef void JS_ReportError(JSContext* cx, char* format, ...)
-
-    # Main Entry Functions
-    cdef JSBool JS_EvaluateUCScript(
-        JSContext* cx,
-        JSObject* obj,
-        jschar* bytes,
-        uintN length,
-        char* filename,
-        uintN lineno,
-        jsval* rval
-    )
-
-cdef extern from "jshelpers.c":
-    cdef JSClass js_global_class
-    cdef JSObject* js_make_global_object(JSContext *cx)
-
-    cdef void js_context_attach(JSContext* cx, PyObject* obj)
-    cdef JSBool js_context_has_data(JSContext* cx)
-    cdef object js_context_fetch(JSContext* cx)
-    cdef object js_context_destroy(JSContext* cx)
-
-    cdef void js_object_attach(JSContext* cx, JSObject* js_obj, PyObject* obj)
-    cdef JSBool js_object_has_data(JSContext* cx, JSObject* js_obj)
-    cdef object js_object_fetch(JSContext* cx, JSObject* js_obj)
-    cdef object js_object_destroy(JSContext* cx, JSObject* js_obj)
-
-    cdef void js_function_attach(JSContext* cx, JSObject* js_obj, PyObject* obj)
-    cdef JSBool js_function_has_data(JSContext* cx, JSObject* js_obj)
-    cdef object js_function_fetch(JSContext* cx, JSObject* js_obj)
-    cdef object js_function_destroy(JSContext* cx, JSObject* js_obj)
-
-    cdef JSString* py2js_jsstring_c(JSContext* cx, PyObject* str)
-    cdef PyObject* js2py_jsstring_c(JSString* str)
-
-cdef void* xmalloc(size_t size) except NULL:
-    cdef void* mem
-    mem = malloc(size)
-    if <int>mem == 0:
-        raise MemoryError()
-    return mem
-
-cdef class PyJSString:
-    cdef JSString* data
-    
-    cdef jschar* chars(PyJSString self):
-        return JS_GetStringChars(self.data)
-    
-    cdef size_t length(PyJSString self):
-        return JS_GetStringLength(self.data)
-
-cdef PyJSString py2js_jsstring(JSContext* cx, object str):
-    cdef PyJSString ret
-    cdef JSString* js_str
-    js_str = py2js_jsstring_c(cx, <PyObject*> str)
-    if js_str == NULL:
-        raise UnicodeError("Failed to encode Python string as UTF-16")
-    ret = PyJSString()
-    ret.data = js_str
-    return ret
-
-cdef object js2py_jsstring(JSString* str):
-    cdef PyObject* ret
-    cdef object var
-    if str == NULL:
-        raise TypeError("Unable to convert a NULL JSString.")
-    ret = js2py_jsstring_c(str)
-    if ret != NULL:
-        var = <object> ret
-    return var
-
-# JavaScript -> Python
-cdef class Context
-cdef class Function
-cdef class GC
-cdef class Runtime
-cdef class Value
-
-# Python -> JavaScript
-cdef class ClassAdapter
-cdef class ObjectAdapter
-cdef class FunctionAdapter
-
-def test_utf_16_round_trip(Context cx, data):
-    cdef PyJSString conv
-    conv = py2js_jsstring(cx.cx, data)
-    return js2py_jsstring(conv.data)
-
-import inspect
-import sys
-import traceback
-import types
-
-class JSError(Exception):
-    def __init__(self, mesg):
-        self.mesg = mesg
-    def __str__(self):
-        return repr(self)
-    def __repr__(self):
-        return self.mesg
-

old-sm/jsarray.pxi

-
-def js_is_array(Context cx, jsval v):
-    cdef JSObject* obj
-    if not JSVAL_IS_OBJECT(v):
-        return False
-    obj = JSVAL_TO_OBJECT(v)
-    return JS_IsArrayObject(cx.cx, obj)
-
-def py_is_array(Context cx, object py_obj):
-    return isinstance(py_obj, (types.ListType, types.TupleType))
-
-cdef object js2py_array(Context cx, jsval v):
-    cdef jsuint nr_elems
-    cdef jsval elem
-    cdef JSObject *jsobj
-    cdef int i
-    cdef list ret
-    
-    jsobj = JSVAL_TO_OBJECT(v)
-    JS_GetArrayLength(cx.cx, jsobj, &nr_elems)
-    ret = [None] * nr_elems
-
-    for i from 0 <= i < nr_elems:
-        if not JS_GetElement(cx.cx, jsobj, i, &elem):
-            raise JSError("Failed to convert JavaScript array to Python.")
-        ret[i] = js2py(cx, elem)
-
-    return ret
-
-cdef jsval py2js_array(Context cx, list py_obj, JSObject* parent):
-    cdef int nr_elems, i
-    cdef JSObject* ret
-    cdef jsval elem
-
-    nr_elems = len(py_obj)
-    ret = JS_NewArrayObject(cx.cx, 0, NULL)
-    
-    for i from 0 <= i < nr_elems:
-        elem = py2js(cx, py_obj[i], parent)
-        if not JS_SetElement(cx.cx, ret, i, &elem):
-            raise JSError("Failed to convert Python sequence type to JavaScript.")
-    
-    return OBJECT_TO_JSVAL(ret)

old-sm/jsbool.pxi

-def js_is_bool(Context cx, jsval jsv):
-    return JSVAL_IS_BOOLEAN(jsv)
-
-def py_is_bool(Context cx, object py_obj):
-    return isinstance(py_obj, types.BooleanType)
-
-cdef object js2py_bool(Context cx, jsval jsv):
-    if JSVAL_TO_BOOLEAN(jsv):
-        return True
-    else:
-        return False
-
-cdef jsval py2js_bool(Context cx, object py_obj, JSObject* parent):
-    if py_obj:
-        return BOOLEAN_TO_JSVAL(JS_TRUE)
-    else:
-        return BOOLEAN_TO_JSVAL(JS_FALSE)

old-sm/jsclass.pxi

-
-cdef JSBool __constructor_callback__(JSContext* cx, JSObject* js_obj, uintN argc, jsval* argv, jsval* rval):
-    cdef Context pycx
-    cdef ClassAdapter adapter
-    cdef ObjectAdapter oa
-    cdef JSObject* proto
-    cdef int i
-    
-    try:
-        if not js_context_has_data(cx):
-            raise JSError("Unknown JSContext object.")
-        
-        proto = JS_GetPrototype(cx, js_obj)
-        if proto == NULL:
-            raise JSError("Object has no prototype.")
-        
-        if not js_object_has_data(cx, proto):
-            raise JSError("Unknown constructor callback.")
-        
-        pycx = js_context_fetch(cx)
-        adapter = js_object_fetch(cx, proto)
-        
-        args = []
-        for i from 0 <= i < argc:
-            args.append(js2py(pycx, argv[i]))
-
-        if hasattr(adapter.py_class, unicode("__jsinit__")):
-            py_rval = adapter.py_class.__jsinit__(pycx, *args)
-        else:
-            py_rval = adapter.py_class(*args)
-
-        rval[0] = py2js(pycx, py_rval, NULL)
-
-        # Register after conversion so we don't keep it around
-        # if conversion fails.
-        if JSVAL_IS_OBJECT(rval[0]):
-            oa = ObjectAdapter(pycx, adapter, None, py_rval)
-            oa.js_obj = js_obj
-            js_object_attach(cx, js_obj, <PyObject*> oa)
-        
-        return JS_TRUE
-    except:
-        return report_python_error(cx)
-
-cdef JSBool __resolve_global_callback__(JSContext* cx, JSObject* js_obj, jsval jsv):
-    cdef Context pycx
-    cdef ObjectAdapter adapter
-    cdef object py_obj
-    cdef object key
-    cdef int i
-    
-    try:
-        if not js_context_has_data(cx):
-            raise JSError("Unknown JSContext object.")
-
-        pycx = js_context_fetch(cx)
-        key = js2py(pycx, jsv)
-
-        if not js_object_has_data(cx, js_obj):
-            return JS_TRUE;
-                
-        adapter = js_object_fetch(cx, js_obj)
-        py_obj = adapter.py_obj
-                
-        if isinstance(key, types.UnicodeType) and hasattr(py_obj, key):
-            pycx.bind(key, getattr(py_obj, key))
-
-        return JS_TRUE
-    except:
-        traceback.print_exc()
-        return report_python_error(cx)
-
-cdef JSBool __get_property_callback__(JSContext* cx, JSObject* js_obj, jsval jsv, jsval* rval):
-    cdef Context pycx
-    cdef ObjectAdapter adapter
-    cdef object py_obj
-    cdef object key
-    cdef object attr
-
-
-    try:
-        if not js_context_has_data(cx):
-            raise JSError("Unknown JSContext object.")
-
-        pycx = js_context_fetch(cx)
-        key = js2py(pycx, jsv)
-                
-        if not js_object_has_data(cx, js_obj):
-            return JS_TRUE
-        
-        adapter = js_object_fetch(cx, js_obj)
-        py_obj = adapter.py_obj
-        
-        if isinstance(key, (types.IntType, types.LongType)):
-            try:
-                attr = py_obj[key]
-            except:
-                pass
-            else:
-                rval[0] = py2js(pycx, attr, NULL)
-        elif isinstance(key, types.UnicodeType):
-            if key[:1] != unicode("_"):
-                try:
-                    attr = getattr(py_obj, key)
-                except:
-                    pass
-                else:
-                    rval[0] = py2js(pycx, attr, js_obj)
-        elif key is None:
-            rval[0] = JSVAL_VOID
-        else:
-            raise AssertionError("Invalid key: %r" % key)
-            
-        return JS_TRUE
-    except:
-        traceback.print_exc()
-        return report_python_error(cx)
-
-cdef JSBool __set_property_callback__(JSContext* cx, JSObject* js_obj, jsval jsv, jsval rval[0]):
-    cdef Context pycx
-    cdef ObjectAdapter adapter
-    cdef object py_obj
-    cdef object key
-    cdef object val
-
-    try:
-        if not js_context_has_data(cx):
-            raise JSError("Unknown JSContext object.")
-
-        pycx = js_context_fetch(cx)
-        key = js2py(pycx, jsv)
-        value = js2py(pycx, rval[0])
-                
-        if not js_object_has_data(cx, js_obj):
-            return JS_TRUE
-        
-        adapter = js_object_fetch(cx, js_obj)
-        py_obj = adapter.py_obj
-
-        if isinstance(key, (types.IntType, types.LongType)):
-            py_obj[key] = value
-        elif isinstance(key, types.UnicodeType):
-            if key[:1] != unicode("_") and hasattr(py_obj, key):
-                attr = getattr(py_obj, key)
-                if not callable(attr):
-                    setattr(py_obj, key, value)
-        else:
-            raise AssertionError("Invalid key: %r" % key)
-
-        return JS_TRUE
-    except:
-        traceback.print_exc()
-        return report_python_error(cx)
-
-
-cdef void __finalize_callback__(JSContext* cx, JSObject* js_obj):
-    cdef Context pycx
-    cdef ObjectAdapter py_obj
-
-    try:
-        if not js_context_has_data(cx):
-            raise JSError("Unknown JSContext object.")
-        
-        if not js_object_has_data(cx, js_obj):
-            raise JSError("Unknown JSObject.")
-        
-        pycx = js_context_fetch(cx)
-        py_obj = js_object_destroy(cx, js_obj)
-    except:
-        report_python_error(cx)
-
-def js_classname(obj):
-    if inspect.isclass(obj):
-        return obj.__name__
-    else:
-        return obj.__class__.__name__
-
-cdef class ClassAdapter:
-    cdef Context cx
-    cdef ObjectAdapter parent
-    cdef JSClass* js_class
-    cdef object py_class
-
-    def __cinit__(ClassAdapter self, Context cx, ObjectAdapter parent, py_class, bind_constructor, is_global, flags):
-        cdef JSObject* proto
-        
-        self.cx = cx
-        self.parent = parent
-        self.py_class = py_class
-        
-        if hasattr(py_class, "__jsname__"):
-            name = py_class.__jsname__
-        else:
-            name = js_classname(py_class)
-
-        self.js_class = <JSClass*> xmalloc(sizeof(JSClass))
-        self.js_class.name = <char*> xmalloc((len(name) + 1) * sizeof(char))
-        strcpy(self.js_class.name, name)
-
-        self.js_class.flags = flags | JSCLASS_HAS_PRIVATE
-        self.js_class.addProperty = JS_PropertyStub
-        self.js_class.delProperty = JS_PropertyStub
-        self.js_class.getProperty = __get_property_callback__
-        self.js_class.setProperty = __set_property_callback__
-        self.js_class.enumerate = JS_EnumerateStub
-        self.js_class.convert = JS_ConvertStub
-        self.js_class.finalize = __finalize_callback__
-        self.js_class.getObjectOps = NULL
-        self.js_class.checkAccess = NULL
-        self.js_class.call = NULL
-        self.js_class.construct = NULL
-        self.js_class.xdrObject = NULL
-        self.js_class.hasInstance = NULL
-        self.js_class.mark = NULL
-        self.js_class.reserveSlots = NULL
-        
-        if is_global:
-            self.js_class.resolve = __resolve_global_callback__
-        else:
-            self.js_class.resolve = JS_ResolveStub
-        
-        if bind_constructor:
-            proto = JS_InitClass(self.cx.cx, parent.js_obj, NULL, self.js_class,
-                            __constructor_callback__, 0, NULL, NULL, NULL, NULL)
-            if proto == NULL:
-                raise JSError("Failed to bind Python adapter class.")
-            js_object_attach(cx.cx, proto, <PyObject*> self)
-
-    def __repr__(self):
-        return "<spidermonkey.ClassAdapter: %r>" % self.py_class
-
-    def __dealloc__(self):
-        if self.js_class:
-            if self.js_class.name:
-                free(self.js_class.name)
-            free(self.js_class)

old-sm/jscontext.pxi

-
-class JSRootObject(object):
-    pass
-
-cdef class Context:
-    cdef JSContext* cx
-    cdef Runtime rt
-    cdef ObjectAdapter root
-    cdef GC gc
-    cdef object reg
-    cdef object classes
-    cdef object error
-
-    def __cinit__(self, Runtime rt, root):
-        self.rt = rt
-
-        STACK_CHUNK_SIZE = 8192
-
-        self.cx = JS_NewContext(rt.rt, STACK_CHUNK_SIZE)
-        if self.cx == NULL:
-            raise JSError("Failed to create Context")
-
-    def __init__(Context self, Runtime rt, root):
-        cdef ClassAdapter ca
-        cdef JSObject* js_obj
-        cdef PyObject* py_obj
-
-        self.gc = GC(self)
-        self.reg = {}
-        self.classes = {}
-        self.error = None
-
-        js_context_attach(self.cx, <PyObject*> self)
-
-        if not root:
-            root = JSRootObject()
-    
-        ca = self.install_class(root.__class__, False, True)
-        js_obj = JS_NewObject(self.cx, ca.js_class, NULL, NULL)
-        if js_obj == NULL:
-            raise JSError("Failed to create root object.")
-        self.root = ObjectAdapter(self, ca, None, root)
-        self.root.js_obj = js_obj
-        js_object_attach(self.cx, self.root.js_obj, <PyObject*> self.root)
-        
-        if not JS_InitStandardClasses(self.cx, js_obj):
-            raise JSError("Failed to initialize standard classes.")
-        
-        JS_SetErrorReporter(self.cx, __report_error_callback__)
-        
-    def __dealloc__(self):
-        JS_DestroyContext(self.cx)
-
-    def install_class(self, py_class, bind_constructor=True, is_global=False, flags=0):
-        """\
-        Install a Python class into the JavaScript runtime.
-        """
-        if not inspect.isclass(py_class):
-            raise TypeError("Unable to install %r as a class." % py_class)
-        if not isinstance(flags, (types.IntType, types.LongType)):
-            raise TypeError("Flags is not an integer.")
-
-        if py_class in self.classes:
-            return self.classes[py_class]
-        
-        ca = ClassAdapter(self, self.root, py_class, bind_constructor, is_global, flags)
-        self.classes[py_class] = ca
-        return ca
-
-    def bind(Context self, name, obj):
-        """\
-        Attach a Python object to the JavaScript runtime.
-        
-        You should be able to attach most types of Python objects
-        including builtin types, object instances, functions etc. About
-        the only thing you can't bind is a Python class which should
-        be isntalled into the JavaScript environment using
-        Context.install_class
-        
-        This call will bind the provided object `obj` to the JS root. The
-        Python value is also referenced to keep it from being garbage
-        collected.
-        """
-        cdef ClassAdapter ca
-        cdef jsval jsv
-        cdef PyJSString js_str
-
-        js_str = py2js_jsstring(self.cx, name)
-
-        ca = self.install_class(obj.__class__)
-        jsv = py2js(self, obj, self.root.js_obj)
-        if not JS_DefineUCProperty(self.cx, self.root.js_obj, js_str.chars(), js_str.length(), jsv,
-                                    __get_property_callback__, __set_property_callback__, 0):
-            raise JSError("Failed to bind Python object to the global object.")
-
-    def unbind(Context self, name):
-        cdef jsval rval
-        cdef PyJSString js_str
-
-        js_str = py2js_jsstring(self.cx, name)
-        
-        ret = self.execute(name + unicode(";")) # yeah yeah, I know.
-        if not JS_DeleteUCProperty2(self.cx, self.root.js_obj, js_str.chars(), js_str.length(), &rval):
-            raise JSError("Failed to unbind property: %s" % name)
-        # This always returns True for some reason
-        #return js2py(self, rval)
-        return ret
-
-    def execute(Context self, script):
-        """\
-        Execute JavaScript source code.
-        """
-        cdef jsval rval
-        cdef PyJSString js_str
-
-        js_str = py2js_jsstring(self.cx, script)
-        
-        try:
-            if not JS_EvaluateUCScript(self.cx, self.root.js_obj, js_str.chars(), js_str.length(), "Python", 0, &rval):
-                raise JSError(self.error)
-            return js2py(self, rval)
-        finally:
-            self.gc.run_maybe()
-
-    def set_error(self, mesg):
-        self.error = mesg
-    
-    

old-sm/jsdouble.pxi

-
-def js_is_double(Context cx, jsval jsv):
-    return JSVAL_IS_DOUBLE(jsv)
-
-def py_is_double(Context cx, object py_obj):
-    return isinstance(py_obj, types.FloatType)
-
-cdef object js2py_double(Context cx, jsval jsv):
-    return JSVAL_TO_DOUBLE(jsv)[0]
-
-cdef jsval py2js_double(Context cx, double py_obj, JSObject* parent):
-    cdef jsval ret
-    if not JS_NewNumberValue(cx.cx, py_obj, &ret):
-        raise JSError("Failed to convert double.")
-    return ret

old-sm/jserror.pxi

-
-
-cdef JSBool report_python_error(JSContext* cx):
-    tb = traceback.format_exc()
-    JS_ReportError(cx, tb)
-    return JS_FALSE
-
-cdef void __report_error_callback__(JSContext* cx, char* message, JSErrorReport* report):
-    cdef Context pycx
-    
-    try:
-        if not js_context_has_data(cx):
-            sys.stderr.write("Attempting to report error for an unknown JSContext.\n")
-            return
-        pycx = js_context_fetch(cx)
-        
-        filename = "Unknown"
-        lineno = "Unknown"
-        msg = "Unknown"
-        
-        if report != NULL:
-            if report.filename != NULL:
-                filename = report.filename
-            lineno = report.lineno
-        if message != NULL:
-            msg = message
-        
-        pycx.set_error("%s(%d): %s" % (filename, lineno, message))
-    except:
-        traceback.print_exc()

old-sm/jsfunction.pxi

-
-cdef class Function:
-    cdef Context cx
-    cdef jsval func
-    
-    def __init__(Function self, Context cx):
-        self.cx = cx
-    
-    def __call__(Function self, *args):
-        cdef jsval* argv
-        cdef jsval rval
-        cdef jsval jsarg
-
-        nr_args = len(args)
-        argv = <jsval*> xmalloc(sizeof(jsval) * nr_args)
-        try:
-            for i from 0 <= i < nr_args:
-                arg = args[i]
-                jsarg = py2js(self.cx, arg, NULL)
-                argv[i] = jsarg
-
-            if not JS_CallFunctionValue(self.cx.cx, self.cx.root.js_obj, self.func, nr_args, argv, &rval):
-                raise JSError(self.cx.error)
-        finally:
-            free(argv)
-
-        retval = js2py(self.cx, rval)
-        self.cx.gc.run_maybe()
-                
-        return retval
-
-    def __dealloc__(Function self):
-        JS_RemoveRoot(self.cx.cx, &self.func)
-
-
-cdef class FunctionAdapter:
-    cdef Context cx
-    cdef JSObject* js_obj
-    cdef object py_obj
-
-    def __cinit__(FunctionAdapter self, Context cx, object obj):
-        self.cx = cx
-        self.py_obj = obj
-
-    def __repr__(self):
-        return "<spidermonkey.FunctionAdapter: %r>" % self.py_obj
-
-
-cdef JSBool __bound_method_callback__(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval):
-    cdef Context pycx
-    cdef ObjectAdapter oa
-    cdef JSFunction* jsfunc
-    cdef int i
-
-    try:
-        if not js_context_has_data(cx):
-            raise JSError("Unknown JSContext object.")
-        
-        pycx = js_context_fetch(cx)
-        
-        if not js_object_has_data(cx, obj):
-            return JS_FALSE
-        
-        oa = js_object_fetch(cx, obj)
-        
-        jsfunc = JS_ValueToFunction(cx, argv[-2])
-        method_name = JS_GetFunctionName(jsfunc)
-        method = getattr(oa.py_obj, method_name)
-
-        args = [None] * argc
-        for i from 0 <= i < argc:
-            args[i] = js2py(pycx, argv[i])
-
-        py_rval = method(*args)
-        rval[0] = py2js(pycx, py_rval, obj)
-        
-        return JS_TRUE
-    except:
-        return report_python_error(cx)
-
-cdef JSBool __function_callback__(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval):
-    cdef Context pycx
-    cdef FunctionAdapter fa
-    cdef JSFunction* jsfunc
-    cdef JSObject* jsobj
-    cdef int i
-
-    try:        
-        if not js_context_has_data(cx):
-            raise JSError("Unknown JSContext object.")
-
-        pycx = js_context_fetch(cx)
-        jsfunc = JS_ValueToFunction(cx, argv[-2])
-        jsobj = JS_GetFunctionObject(jsfunc)
-
-        if not js_function_has_data(cx, jsobj):
-            raise JSError("Function call back without attached functor.")
-        
-        fa = js_function_fetch(cx, jsobj)
-        
-        args = [None] * argc
-        for i from 0 <= i < argc:
-            args[i] = js2py(pycx, argv[i])
-
-        py_rval = fa.py_obj(*args)
-        rval[0] = py2js(pycx, py_rval, obj)
-
-        return JS_TRUE
-    except:
-        return report_python_error(cx)
-
-def js_is_function(Context cx, jsval jsv):
-    return JS_TypeOfValue(cx.cx, jsv) == JSTYPE_FUNCTION
-
-def py_is_function(Context cx, object py_obj):
-    return isinstance(py_obj, (types.FunctionType, types.LambdaType))
-
-def py_is_bound_method(Context cx, object py_obj):
-    return isinstance(py_obj, types.MethodType)
-
-cdef object js2py_function(Context cx, jsval jsv):
-    cdef Function ret
-    ret = Function(cx)
-    ret.func = jsv
-    JS_AddRoot(cx.cx, &ret.func)
-    return ret
-
-cdef jsval py2js_bound_method(Context cx, object py_obj, JSObject* parent):
-    cdef FunctionAdapter fa
-    cdef JSFunction* func
-    cdef JSObject* obj
-    
-    if hasattr(py_obj, "func_name"):
-        name = py_obj.func_name
-    elif hasattr(py_obj, "im_fun") and hasattr(py_obj.im_fun, "func_name"):
-        name = py_obj.im_fun.func_name
-    else:
-        raise JSError("Failed to find function name.")
-
-    func = JS_NewFunction(cx.cx, __bound_method_callback__, 0, 0, NULL, name)
-    obj = JS_GetFunctionObject(func)
-    return OBJECT_TO_JSVAL(obj)
-
-cdef jsval py2js_function(Context cx, object py_obj, JSObject* parent):
-    cdef FunctionAdapter fa
-    cdef JSFunction* func
-    cdef JSObject* obj
-    cdef jsval slot
-    
-    if hasattr(py_obj, "func_name"):
-        name = py_obj.func_name
-    elif hasattr(py_obj, "im_fun") and hasattr(py_obj.im_fun, "func_name"):
-        name = py_obj.im_fun.func_name
-    else:
-        raise JSError("Failed to find function name.")
-    
-    func = JS_NewFunction(cx.cx, __function_callback__, 0, 0, NULL, name)
-    fa = FunctionAdapter(cx, py_obj)
-    fa.js_obj = JS_GetFunctionObject(func)
-    
-    js_function_attach(cx.cx, fa.js_obj, <PyObject*> fa)
-
-    return OBJECT_TO_JSVAL(fa.js_obj)
-    

old-sm/jsgc.pxi

-
-cdef class GC:
-    cdef Context cx
-
-    def __cinit__(GC self, Context cx):
-        self.cx = cx
-
-    cdef void run(GC self):
-        JS_GC(self.cx.cx)
-    
-    cdef void run_maybe(GC self):
-        JS_MaybeGC(self.cx.cx)
-    
-    cdef void add_root(GC self, void* rp):
-        if not JS_AddRoot(self.cx.cx, rp):
-            raise JSError("Failed to add a GC root")
-    
-    cdef void add_named_root(GC self, void* rp, char* name):
-        if not JS_AddNamedRoot(self.cx.cx, rp, name):
-            raise JSError("Failed to add a named GC root: %s" % name)
-
-    cdef void rem_root(GC self, void* rp):
-        if not JS_RemoveRoot(self.cx.cx, rp):
-            raise JSError("Failed to remove GC root")

old-sm/jshash.pxi

-
-def js_is_hash(Context cx, jsval v):
-    return JSVAL_IS_OBJECT(v)
-
-def py_is_hash(Context cx, object py_obj):
-    return isinstance(py_obj, (types.DictionaryType, types.DictType))
-
-cdef object js2py_hash(Context cx, jsval v):
-    cdef JSObject* hash
-    cdef JSObject *obj
-    cdef JSIdArray *props
-    cdef jsval jskey
-    cdef jsval jsv
-    cdef int i
-    cdef dict ret
-    cdef PyJSString js_str
-
-    hash = JSVAL_TO_OBJECT(v)
-
-    props = JS_Enumerate(cx.cx, hash)
-    if props == NULL:
-        raise JSError("Failed to enumerate hash properties.")
-
-    ret = {}
-
-    try:
-        for i from 0 <= i < props.length:
-            if not JS_IdToValue(cx.cx, (props.vector)[i], &jskey):
-                raise JSError("Failed to convert dict to JavaScript.")
-        
-            if js_is_string(cx, jskey):
-                key = js2py_string(cx, jskey)
-                js_str = py2js_jsstring(cx.cx, key)
-                
-                if not JS_GetUCProperty(cx.cx, hash, js_str.chars(), js_str.length(), &jsv):
-                    raise JSError("Faield to retrieve textual hash property.")
-            elif js_is_int(cx, jskey):
-                key = js2py_int(cx, jskey)
-                if not JS_GetElement(cx.cx, hash, key, &jsv):
-                    raise JSError("Failed to retrive numeric hash property.")
-            else:
-                raise AssertionError("Invalid JavaScript property.")
-
-            ret[key] = js2py(cx, jsv)
-    finally:
-        JS_DestroyIdArray(cx.cx, props)
-
-    return ret
-
-
-cdef jsval py2js_hash(Context cx, dict py_obj, JSObject* parent):
-    cdef JSObject* obj
-    cdef jsval elem
-    cdef PyJSString js_str
-    
-    obj = JS_NewObject(cx.cx, NULL, NULL, parent)
-    if obj == NULL:
-        raise JSError("Failed to create new JavaScript object for dict instance.")
-
-    for k, v in py_obj.iteritems():
-        js_str = py2js_jsstring(cx.cx, k)
-        elem = py2js(cx, v, obj)
-            
-        if not JS_SetUCProperty(cx.cx, obj, js_str.chars(), js_str.length(), &elem):
-            raise JSError("Failed to set JavaScript property for dict instance.")
-
-    return OBJECT_TO_JSVAL(obj)

old-sm/jshelpers.c

-JSString* py2js_jsstring_c(JSContext* cx, PyObject* str)
-{
-    PyObject* encoded = NULL;
-    char* bytes;
-    Py_ssize_t len;
-    
-    if(!PyUnicode_Check(str))
-    {
-        return NULL;
-    }
-        
-    encoded = PyUnicode_AsEncodedString(str, "utf-16", "strict");
-    if(encoded == NULL)
-    {
-        return NULL;
-    }
-        
-    if(PyString_AsStringAndSize(encoded, &bytes, &len) < 0)
-    {
-        return NULL;
-    }
-
-    if(len < 4)
-    {
-        return NULL;
-    }
-
-    // No idea why python adds FFFE to encoded UTF-16 data.
-    return JS_NewUCStringCopyN(cx, bytes+2, (len/2)-1);
-}
-
-PyObject* js2py_jsstring_c(JSString* str)
-{
-    jschar* bytes;
-    size_t len;
-        
-    if(str == NULL)
-    {
-        return NULL;
-    }
-    
-    len = JS_GetStringLength(str);
-    bytes = JS_GetStringChars(str);
-
-    return PyUnicode_Decode((const char*) bytes, (size_t) (len * 2), "utf-16", "strict");
-}
-
-void
-js_context_attach(JSContext* cx, PyObject* obj)
-{
-    Py_XINCREF(obj);
-    JS_SetContextPrivate(cx, (void*) obj);
-}
-
-JSBool
-js_context_has_data(JSContext* cx)
-{
-    if(JS_GetContextPrivate(cx) == NULL)
-    {
-        return JS_FALSE;
-    }
-    
-    return JS_TRUE;
-}
-
-PyObject* 
-js_context_fetch(JSContext* cx)
-{
-    PyObject* obj = (PyObject*) JS_GetContextPrivate(cx);
-    Py_XINCREF(obj);
-    return obj;
-}
-
-PyObject*
-js_context_destroy(JSContext* cx)
-{
-    PyObject* ret = (PyObject*) JS_GetContextPrivate(cx);
-    return ret;
-}
-
-void
-js_object_attach(JSContext* cx, JSObject* js_obj, PyObject* py_obj)
-{   
-    Py_XINCREF(py_obj);
-    JS_SetPrivate(cx, js_obj, (void*) py_obj);
-}
-
-JSBool
-js_object_has_data(JSContext* cx, JSObject* js_obj)
-{
-    JSClass* class = JS_GetClass(cx, js_obj);
-    
-    if(class == NULL)
-    {
-        return JS_FALSE;
-    }
-    
-    if(!(class->flags & JSCLASS_HAS_PRIVATE))
-    {
-        return JS_FALSE;
-    }
-    
-    if(JS_GetPrivate(cx, js_obj) == NULL)
-    {
-        return JS_FALSE;
-    }
-    
-    return JS_TRUE;
-}
-
-PyObject*
-js_object_fetch(JSContext* cx, JSObject* js_obj)
-{
-    PyObject* py_obj = (PyObject*) JS_GetPrivate(cx, js_obj);
-    Py_XINCREF(py_obj);
-    return py_obj;
-}
-
-PyObject*
-js_object_destroy(JSContext* cx, JSObject* js_obj)
-{
-    return (PyObject*) JS_GetPrivate(cx, js_obj);
-}
-
-void
-js_function_attach(JSContext* cx, JSObject* js_obj, PyObject* py_obj)
-{   
-    Py_XINCREF(py_obj);
-    jsval slot = PRIVATE_TO_JSVAL(py_obj);
-    JS_SetReservedSlot(cx, js_obj, 0, slot);
-}
-
-JSBool
-js_function_has_data(JSContext* cx, JSObject* js_obj)
-{
-    jsval slot;
-    if(JS_GetReservedSlot(cx, js_obj, 0, &slot) != JS_TRUE)
-    {
-        return JS_FALSE;
-    }
-    
-    void* data = JSVAL_TO_PRIVATE(slot);
-    
-    if(data == NULL)
-    {
-        return JS_FALSE;
-    }
-    
-    return JS_TRUE;
-}
-
-PyObject*
-js_function_fetch(JSContext* cx, JSObject* js_obj)
-{
-    jsval slot;
-    if(JS_GetReservedSlot(cx, js_obj, 0, &slot) != JS_TRUE)
-    {
-        return JS_FALSE;
-    }
-    
-    PyObject* py_obj = (PyObject*) JSVAL_TO_PRIVATE(slot);
-    Py_XINCREF(py_obj);
-    return py_obj;
-}
-
-PyObject*
-js_function_destroy(JSContext* cx, JSObject* js_obj)
-{
-    jsval slot;
-    if(JS_GetReservedSlot(cx, js_obj, 0, &slot) != JS_TRUE)
-    {
-        return JS_FALSE;
-    }
-    
-    PyObject* py_obj = (PyObject*) JSVAL_TO_PRIVATE(slot);
-    return py_obj;
-}
-
-static JSClass js_global_class =
-{
-    "RootObjectClass",
-    JSCLASS_GLOBAL_FLAGS,
-    JS_PropertyStub,
-    JS_PropertyStub,
-    JS_PropertyStub,
-    JS_PropertyStub,
-    JS_EnumerateStub,
-    JS_ResolveStub,
-    JS_ConvertStub,
-    JS_FinalizeStub,
-    JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-JSObject *
-js_make_global_object(JSContext *cx)
-{
-    return JS_NewObject(cx, &js_global_class, NULL, NULL);
-}

old-sm/jsint.pxi

-
-def js_is_int(Context cx, jsval jsv):
-    return JSVAL_IS_INT(jsv)
-
-def py_is_int(Context cx, object py_obj):
-    return isinstance(py_obj, (types.IntType, types.LongType))
-
-cdef object js2py_int(Context cx, jsval jsv):
-    return JSVAL_TO_INT(jsv)
-
-cdef jsval py2js_int(Context cx, jsint py_obj, JSObject* parent):
-    return INT_TO_JSVAL(py_obj)
-

old-sm/jsobject.pxi

-
-cdef class ObjectAdapter:
-    cdef Context cx
-    cdef ClassAdapter cl_adapter
-    cdef ObjectAdapter parent
-    cdef JSObject* js_obj
-    cdef object py_obj
-
-    def __cinit__(ObjectAdapter self, Context cx, ClassAdapter adapter, ObjectAdapter parent, object obj):
-        self.cx = cx
-        self.cl_adapter = adapter
-        self.parent = parent
-        self.js_obj = NULL
-        self.py_obj = obj
-
-    def __repr__(self):
-        return "<spidermonkey.ObjectAdapter: %r>" % self.py_obj
-
-def js_is_object(Context cx, jsval jsv):
-    if not JSVAL_IS_OBJECT(jsv):
-        return False
-    if not js_object_has_data(cx.cx, JSVAL_TO_OBJECT(jsv)):
-        return False
-    return True
-
-def py_is_object(Context cx, object py_obj):
-    return not isinstance(py_obj, types.TypeType)
-
-cdef object js2py_object(Context cx, jsval jsv):
-    cdef ClassAdapter ca
-    cdef ObjectAdapter oa
-    cdef FunctionAdapter fa
-    
-    tmp = js_object_fetch(cx.cx, JSVAL_TO_OBJECT(jsv))
-    if isinstance(tmp, ClassAdapter):
-        ca = tmp
-        return ca.py_obj
-    elif isinstance(tmp, ObjectAdapter):
-        oa = tmp
-        return oa.py_obj
-    elif isinstance(tmp, FunctionAdapter):
-        fa = tmp
-        return fa.py_obj
-    else:
-        raise JSError("Failed to unwrap Python object.")
-
-cdef jsval py2js_object(Context cx, object py_obj, JSObject* parent):
-    cdef ClassAdapter ca
-    cdef ObjectAdapter oa
-    cdef JSObject* js_obj
-    cdef jsval rval
-
-    ca = cx.install_class(py_obj.__class__)
-    js_obj = JS_NewObject(cx.cx, ca.js_class, NULL, NULL)
-    if js_obj == NULL:
-        raise JSError("Failed to create object.")
-    oa = ObjectAdapter(cx, ca, None, py_obj)
-    oa.js_obj = js_obj
-    js_object_attach(cx.cx, oa.js_obj, <PyObject*> oa)
-
-    return OBJECT_TO_JSVAL(js_obj)

old-sm/jsruntime.pxi

-
-cdef class Runtime:
-    cdef JSRuntime* rt
-
-    def __cinit__(self):
-        self.rt = JS_NewRuntime(1000000)
-        if self.rt == NULL:
-            raise JSError("Failed to create JavaScript Runtime.")
-
-    def __dealloc__(self):
-        JS_DestroyRuntime(self.rt)
-
-    def create_context(self, root=None):
-        cx = Context(self, root)
-        return cx

old-sm/jsstring.pxi

-
-
-
-def js_is_string(Context cx, jsval jsv):
-    return JSVAL_IS_STRING(jsv)
-
-def py_is_string(Context cx, object py_obj):
-    if isinstance(py_obj, types.StringTypes):
-        if not isinstance(py_obj, types.UnicodeType):
-            raise UnicodeError("Non unicode strings not allowed in spidermonkey.")
-        return True
-    return False
-
-cdef jsval py2js_string(Context cx, object py_obj, JSObject* parent):
-    cdef PyJSString js_str
-    js_str = py2js_jsstring(cx.cx, py_obj)
-    return STRING_TO_JSVAL(js_str.data)
-
-cdef object js2py_string(Context cx, jsval jsv):
-    return js2py_jsstring(JSVAL_TO_STRING(jsv))

old-sm/jsvalue.pxi

-
-cdef jsval py2js(Context cx, object py_obj, JSObject* parent) except 0:
-    if py_is_void(cx, py_obj):
-        return py2js_void(cx, py_obj, parent)
-    elif py_is_bool(cx, py_obj):
-        return py2js_bool(cx, py_obj, parent)
-    elif py_is_int(cx, py_obj):
-        return py2js_int(cx, py_obj, parent)
-    elif py_is_double(cx, py_obj):
-        return py2js_double(cx, py_obj, parent)
-    elif py_is_string(cx, py_obj):
-        return py2js_string(cx, py_obj, parent)
-    elif py_is_array(cx, py_obj):
-        return py2js_array(cx, py_obj, parent)
-    elif py_is_hash(cx, py_obj):
-        return py2js_hash(cx, py_obj, parent)
-    elif py_is_bound_method(cx, py_obj):
-        return py2js_bound_method(cx, py_obj, parent)
-    elif py_is_function(cx, py_obj):
-        return py2js_function(cx, py_obj, parent)
-    elif py_is_object(cx, py_obj):
-        return py2js_object(cx, py_obj, parent)
-    #elif py_is_class(cx, py_obj):
-    #    return py2js_class(cx, py_obj, parent)
-    else:
-        raise TypeError("Unable to convert Python value to JavaScript: %r" % py_obj)
-
-cdef object js2py(Context cx, jsval jsv):
-    if js_is_void(cx, jsv):
-        return js2py_void(cx, jsv)
-    elif js_is_bool(cx, jsv):
-        return js2py_bool(cx, jsv)
-    elif js_is_int(cx, jsv):
-        return js2py_int(cx, jsv)
-    elif js_is_double(cx, jsv):
-        return js2py_double(cx, jsv)
-    elif js_is_string(cx, jsv):
-        return js2py_string(cx, jsv)
-    elif js_is_array(cx, jsv):
-        return js2py_array(cx, jsv)
-    elif js_is_function(cx, jsv): 
-        return js2py_function(cx, jsv)
-    elif js_is_object(cx, jsv):
-        return js2py_object(cx, jsv)
-    elif js_is_hash(cx, jsv):
-        return js2py_hash(cx, jsv)
-    else:
-        raise TypeError("Unable to convert JavaScript value to Python: %r" % jsv)
-
-cdef class Value:
-    cdef jsval jsv
-
-cdef Value js_create_value(jsval jsv):
-    cdef Value v
-    v = Value()
-    v.jsv = jsv
-    return v

old-sm/jsvoid.pxi

-
-def js_is_void(Context cx, jsval jsv):
-    return JSVAL_IS_VOID(jsv) or jsv == 0
-
-def py_is_void(Context cx, object py_obj):
-    return isinstance(py_obj, (types.NoneType))
-
-cdef object js2py_void(Context cx, jsval jsv):
-    return None
-
-cdef jsval py2js_void(Context cx, object py_obj, JSObject* parent):
-    return JSVAL_VOID

old-sm/spidermonkey.c

-/* Generated by Pyrex 0.9.8.5 on Fri Feb 27 17:51:12 2009 */
-
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
-#ifndef PY_LONG_LONG
-  #define PY_LONG_LONG LONG_LONG
-#endif
-#if PY_VERSION_HEX < 0x02050000
-  typedef int Py_ssize_t;
-  #define PY_SSIZE_T_MAX INT_MAX
-  #define PY_SSIZE_T_MIN INT_MIN
-  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
-  #define PyInt_AsSsize_t(o)	PyInt_AsLong(o)
-#endif
-#if !defined(WIN32) && !defined(MS_WINDOWS)
-  #ifndef __stdcall
-    #define __stdcall
-  #endif
-  #ifndef __cdecl
-    #define __cdecl
-  #endif
-#endif
-#ifdef __cplusplus
-#define __PYX_EXTERN_C extern "C"
-#else
-#define __PYX_EXTERN_C extern
-#endif
-#include <math.h>
-#include "stdio.h"
-#include "string.h"
-#include "stdlib.h"
-#include "jsapi.h"
-#include "jshelpers.c"
-
-
-typedef struct {PyObject **p; int i; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
-
-static PyObject *__pyx_m;
-static PyObject *__pyx_b;
-static int __pyx_lineno;
-static char *__pyx_filename;
-static char **__pyx_f;
-
-static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
-
-static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
-
-static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
-
-static void __Pyx_WriteUnraisable(char *name); /*proto*/
-
-static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
-
-static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
-
-static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[],     Py_ssize_t nargs, PyObject **args2, PyObject **kwds2, char rqd_kwds[]); /*proto*/
-
-static int __Pyx_SetItemInt(PyObject *o, Py_ssize_t i, PyObject *v); /*proto*/
-
-static PyObject *__Pyx_GetItemInt(PyObject *o, Py_ssize_t i); /*proto*/
-
-static PyObject *__Pyx_UnpackItem(PyObject *); /*proto*/
-static int __Pyx_EndUnpack(PyObject *); /*proto*/
-
-static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
-
-static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
-
-static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
-
-static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/
-
-static void __Pyx_AddTraceback(char *funcname); /*proto*/
-
-/* Declarations from spidermonkey */
-
-
-/* Declarations from implementation of spidermonkey */
-
-typedef int __pyx_t_12spidermonkey_uint8;
-
-typedef int __pyx_t_12spidermonkey_uint16;
-
-typedef int __pyx_t_12spidermonkey_uint32;
-
-typedef int __pyx_t_12spidermonkey_uintN;
-
-typedef int __pyx_t_12spidermonkey_size_t;
-
-typedef char __pyx_t_12spidermonkey_jschar;
-
-typedef double __pyx_t_12spidermonkey_jsdouble;
-
-typedef int __pyx_t_12spidermonkey_jsid;
-
-typedef int __pyx_t_12spidermonkey_jsint;
-
-typedef int __pyx_t_12spidermonkey_jsuint;
-
-typedef int __pyx_t_12spidermonkey_jsval;
-
-typedef int __pyx_t_12spidermonkey_JSBool;
-
-struct __pyx_obj_12spidermonkey_PyJSString {
-  PyObject_HEAD
-  struct __pyx_vtabstruct_12spidermonkey_PyJSString *__pyx_vtab;
-  struct JSString *data;
-};
-
-struct __pyx_obj_12spidermonkey_GC {
-  PyObject_HEAD
-  struct __pyx_vtabstruct_12spidermonkey_GC *__pyx_vtab;
-  struct __pyx_obj_12spidermonkey_Context *cx;
-};
-
-struct __pyx_obj_12spidermonkey_Runtime {
-  PyObject_HEAD
-  struct JSRuntime *rt;
-};
-
-struct __pyx_obj_12spidermonkey_Context {
-  PyObject_HEAD
-  struct JSContext *cx;
-  struct __pyx_obj_12spidermonkey_Runtime *rt;
-  struct __pyx_obj_12spidermonkey_ObjectAdapter *root;
-  struct __pyx_obj_12spidermonkey_GC *gc;
-  PyObject *reg;
-  PyObject *classes;
-  PyObject *error;
-};
-
-struct __pyx_obj_12spidermonkey_ClassAdapter {
-  PyObject_HEAD
-  struct __pyx_obj_12spidermonkey_Context *cx;
-  struct __pyx_obj_12spidermonkey_ObjectAdapter *parent;
-  struct JSClass *js_class;
-  PyObject *py_class;
-};
-
-struct __pyx_obj_12spidermonkey_ObjectAdapter {
-  PyObject_HEAD
-  struct __pyx_obj_12spidermonkey_Context *cx;
-  struct __pyx_obj_12spidermonkey_ClassAdapter *cl_adapter;
-  struct __pyx_obj_12spidermonkey_ObjectAdapter *parent;
-  struct JSObject *js_obj;
-  PyObject *py_obj;
-};
-
-struct __pyx_obj_12spidermonkey_Function {
-  PyObject_HEAD
-  struct __pyx_obj_12spidermonkey_Context *cx;
-  __pyx_t_12spidermonkey_jsval func;
-};
-
-struct __pyx_obj_12spidermonkey_FunctionAdapter {
-  PyObject_HEAD
-  struct __pyx_obj_12spidermonkey_Context *cx;
-  struct JSObject *js_obj;
-  PyObject *py_obj;
-};
-
-struct __pyx_obj_12spidermonkey_Value {
-  PyObject_HEAD
-  __pyx_t_12spidermonkey_jsval jsv;
-};
-
-
-struct __pyx_vtabstruct_12spidermonkey_PyJSString {
-  __pyx_t_12spidermonkey_jschar *(*chars)(struct __pyx_obj_12spidermonkey_PyJSString *);
-  __pyx_t_12spidermonkey_size_t (*length)(struct __pyx_obj_12spidermonkey_PyJSString *);
-};
-static struct __pyx_vtabstruct_12spidermonkey_PyJSString *__pyx_vtabptr_12spidermonkey_PyJSString;
-
-
-
-
-struct __pyx_vtabstruct_12spidermonkey_GC {
-  void (*run)(struct __pyx_obj_12spidermonkey_GC *);
-  void (*run_maybe)(struct __pyx_obj_12spidermonkey_GC *);
-  void (*add_root)(struct __pyx_obj_12spidermonkey_GC *,void *);
-  void (*add_named_root)(struct __pyx_obj_12spidermonkey_GC *,void *,char *);
-  void (*rem_root)(struct __pyx_obj_12spidermonkey_GC *,void *);
-};
-static struct __pyx_vtabstruct_12spidermonkey_GC *__pyx_vtabptr_12spidermonkey_GC;
-
-
-
-
-
-
-static PyTypeObject *__pyx_ptype_12spidermonkey_PyJSString = 0;
-static PyTypeObject *__pyx_ptype_12spidermonkey_Context = 0;
-static PyTypeObject *__pyx_ptype_12spidermonkey_Function = 0;
-static PyTypeObject *__pyx_ptype_12spidermonkey_GC = 0;
-static PyTypeObject *__pyx_ptype_12spidermonkey_Runtime = 0;
-static PyTypeObject *__pyx_ptype_12spidermonkey_Value = 0;
-static PyTypeObject *__pyx_ptype_12spidermonkey_ClassAdapter = 0;
-static PyTypeObject *__pyx_ptype_12spidermonkey_ObjectAdapter = 0;
-static PyTypeObject *__pyx_ptype_12spidermonkey_FunctionAdapter = 0;
-static void *__pyx_f_12spidermonkey_xmalloc(__pyx_t_12spidermonkey_size_t); /*proto*/
-static struct __pyx_obj_12spidermonkey_PyJSString *__pyx_f_12spidermonkey_py2js_jsstring(struct JSContext *,PyObject *); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py_jsstring(struct JSString *); /*proto*/
-static __pyx_t_12spidermonkey_JSBool __pyx_f_12spidermonkey_report_python_error(struct JSContext *); /*proto*/
-static void __pyx_f_12spidermonkey___report_error_callback__(struct JSContext *,char *,struct JSErrorReport *); /*proto*/
-static __pyx_t_12spidermonkey_JSBool __pyx_f_12spidermonkey___constructor_callback__(struct JSContext *,struct JSObject *,__pyx_t_12spidermonkey_uintN,__pyx_t_12spidermonkey_jsval *,__pyx_t_12spidermonkey_jsval *); /*proto*/
-static __pyx_t_12spidermonkey_JSBool __pyx_f_12spidermonkey___resolve_global_callback__(struct JSContext *,struct JSObject *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static __pyx_t_12spidermonkey_JSBool __pyx_f_12spidermonkey___get_property_callback__(struct JSContext *,struct JSObject *,__pyx_t_12spidermonkey_jsval,__pyx_t_12spidermonkey_jsval *); /*proto*/
-static __pyx_t_12spidermonkey_JSBool __pyx_f_12spidermonkey___set_property_callback__(struct JSContext *,struct JSObject *,__pyx_t_12spidermonkey_jsval,__pyx_t_12spidermonkey_jsval *); /*proto*/
-static void __pyx_f_12spidermonkey___finalize_callback__(struct JSContext *,struct JSObject *); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py_object(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js_object(struct __pyx_obj_12spidermonkey_Context *,PyObject *,struct JSObject *); /*proto*/
-static __pyx_t_12spidermonkey_JSBool __pyx_f_12spidermonkey___bound_method_callback__(struct JSContext *,struct JSObject *,__pyx_t_12spidermonkey_uintN,__pyx_t_12spidermonkey_jsval *,__pyx_t_12spidermonkey_jsval *); /*proto*/
-static __pyx_t_12spidermonkey_JSBool __pyx_f_12spidermonkey___function_callback__(struct JSContext *,struct JSObject *,__pyx_t_12spidermonkey_uintN,__pyx_t_12spidermonkey_jsval *,__pyx_t_12spidermonkey_jsval *); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py_function(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js_bound_method(struct __pyx_obj_12spidermonkey_Context *,PyObject *,struct JSObject *); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js_function(struct __pyx_obj_12spidermonkey_Context *,PyObject *,struct JSObject *); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py_array(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js_array(struct __pyx_obj_12spidermonkey_Context *,PyListObject *,struct JSObject *); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py_bool(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js_bool(struct __pyx_obj_12spidermonkey_Context *,PyObject *,struct JSObject *); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py_double(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js_double(struct __pyx_obj_12spidermonkey_Context *,double,struct JSObject *); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py_hash(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js_hash(struct __pyx_obj_12spidermonkey_Context *,PyDictObject *,struct JSObject *); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py_int(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js_int(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsint,struct JSObject *); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js_string(struct __pyx_obj_12spidermonkey_Context *,PyObject *,struct JSObject *); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py_string(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py_void(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js_void(struct __pyx_obj_12spidermonkey_Context *,PyObject *,struct JSObject *); /*proto*/
-static __pyx_t_12spidermonkey_jsval __pyx_f_12spidermonkey_py2js(struct __pyx_obj_12spidermonkey_Context *,PyObject *,struct JSObject *); /*proto*/
-static PyObject *__pyx_f_12spidermonkey_js2py(struct __pyx_obj_12spidermonkey_Context *,__pyx_t_12spidermonkey_jsval); /*proto*/
-static struct __pyx_obj_12spidermonkey_Value *__pyx_f_12spidermonkey_js_create_value(__pyx_t_12spidermonkey_jsval); /*proto*/
-
-static char __pyx_k1[] = "Failed to encode Python string as UTF-16";
-static char __pyx_k2[] = "Unable to convert a NULL JSString.";
-static char __pyx_k3[] = "mesg";
-static char __pyx_k4[] = "traceback";
-static char __pyx_k5[] = "format_exc";
-static char __pyx_k6[] = "sys";
-static char __pyx_k7[] = "stderr";
-static char __pyx_k8[] = "write";
-static char __pyx_k9[] = "Attempting to report error for an unknown JSContext.\n";
-static char __pyx_k10[] = "Unknown";
-static char __pyx_k11[] = "set_error";
-static char __pyx_k12[] = "%s(%d): %s";
-static char __pyx_k13[] = "print_exc";
-static char __pyx_k14[] = "JSError";
-static char __pyx_k15[] = "Failed to add a GC root";
-static char __pyx_k16[] = "Failed to add a named GC root: %s";
-static char __pyx_k17[] = "Failed to remove GC root";
-static char __pyx_k18[] = "Failed to create JavaScript Runtime.";
-static char __pyx_k19[] = "Failed to create Context";
-static char __pyx_k20[] = "JSRootObject";
-static char __pyx_k21[] = "install_class";
-static char __pyx_k22[] = "__class__";
-static char __pyx_k23[] = "Failed to create root object.";
-static char __pyx_k24[] = "Failed to initialize standard classes.";
-static char __pyx_k25[] = "inspect";
-static char __pyx_k26[] = "isclass";
-static char __pyx_k27[] = "Unable to install %r as a class.";
-static char __pyx_k28[] = "types";
-static char __pyx_k29[] = "IntType";
-static char __pyx_k30[] = "LongType";
-static char __pyx_k31[] = "Flags is not an integer.";
-static char __pyx_k32[] = "Failed to bind Python object to the global object.";
-static char __pyx_k33[] = "execute";
-static char __pyx_k34[] = "unicode";
-static char __pyx_k35[] = ";";
-static char __pyx_k36[] = "Failed to unbind property: %s";
-static char __pyx_k37[] = "Python";
-static char __pyx_k38[] = "Unknown JSContext object.";
-static char __pyx_k39[] = "Object has no prototype.";
-static char __pyx_k40[] = "Unknown constructor callback.";
-static char __pyx_k41[] = "append";
-static char __pyx_k42[] = "__jsinit__";
-static char __pyx_k43[] = "UnicodeType";
-static char __pyx_k44[] = "bind";
-static char __pyx_k45[] = "_";
-static char __pyx_k46[] = "Invalid key: %r";
-static char __pyx_k47[] = "callable";
-static char __pyx_k48[] = "Unknown JSObject.";
-static char __pyx_k49[] = "__name__";
-static char __pyx_k50[] = "__jsname__";
-static char __pyx_k51[] = "js_classname";
-static char __pyx_k52[] = "Failed to bind Python adapter class.";
-static char __pyx_k53[] = "<spidermonkey.ClassAdapter: %r>";
-static char __pyx_k54[] = "<spidermonkey.ObjectAdapter: %r>";
-static char __pyx_k55[] = "TypeType";
-static char __pyx_k56[] = "py_obj";
-static char __pyx_k57[] = "Failed to unwrap Python object.";
-static char __pyx_k58[] = "Failed to create object.";
-static char __pyx_k59[] = "<spidermonkey.FunctionAdapter: %r>";
-static char __pyx_k60[] = "Function call back without attached functor.";
-static char __pyx_k61[] = "FunctionType";
-static char __pyx_k62[] = "LambdaType";
-static char __pyx_k63[] = "MethodType";
-static char __pyx_k64[] = "func_name";
-static char __pyx_k65[] = "im_fun";
-static char __pyx_k66[] = "Failed to find function name.";
-static char __pyx_k67[] = "ListType";
-static char __pyx_k68[] = "TupleType";
-static char __pyx_k69[] = "Failed to convert JavaScript array to Python.";
-static char __pyx_k70[] = "Failed to convert Python sequence type to JavaScript.";
-static char __pyx_k71[] = "BooleanType";
-static char __pyx_k72[] = "FloatType";
-static char __pyx_k73[] = "Failed to convert double.";
-static char __pyx_k74[] = "DictionaryType";
-static char __pyx_k75[] = "DictType";
-static char __pyx_k76[] = "Failed to enumerate hash properties.";
-static char __pyx_k77[] = "Failed to convert dict to JavaScript.";
-static char __pyx_k78[] = "js_is_string";
-static char __pyx_k79[] = "Faield to retrieve textual hash property.";
-static char __pyx_k80[] = "js_is_int";
-static char __pyx_k81[] = "Failed to retrive numeric hash property.";
-static char __pyx_k82[] = "Invalid JavaScript property.";
-static char __pyx_k83[] = "Failed to create new JavaScript object for dict instance.";
-static char __pyx_k84[] = "iteritems";
-static char __pyx_k85[] = "Failed to set JavaScript property for dict instance.";
-static char __pyx_k86[] = "StringTypes";
-static char __pyx_k87[] = "Non unicode strings not allowed in spidermonkey.";
-static char __pyx_k88[] = "NoneType";
-static char __pyx_k89[] = "py_is_void";
-static char __pyx_k90[] = "py_is_bool";
-static char __pyx_k91[] = "py_is_int";
-static char __pyx_k92[] = "py_is_double";
-static char __pyx_k93[] = "py_is_string";
-static char __pyx_k94[] = "py_is_array";
-static char __pyx_k95[] = "py_is_hash";
-static char __pyx_k96[] = "py_is_bound_method";
-static char __pyx_k97[] = "py_is_function";
-static char __pyx_k98[] = "py_is_object";
-static char __pyx_k99[] = "Unable to convert Python value to JavaScript: %r";
-static char __pyx_k100[] = "js_is_void";
-static char __pyx_k101[] = "js_is_bool";
-static char __pyx_k102[] = "js_is_double";
-static char __pyx_k103[] = "js_is_array";
-static char __pyx_k104[] = "js_is_function";
-static char __pyx_k105[] = "js_is_object";
-static char __pyx_k106[] = "js_is_hash";
-static char __pyx_k107[] = "Unable to convert JavaScript value to Python: %r";
-static char __pyx_k108[] = "__init__";
-static char __pyx_k109[] = "__str__";
-static char __pyx_k110[] = "__repr__";
-static char __pyx_k111[] = "object";
-
-static PyObject *__pyx_n_BooleanType;
-static PyObject *__pyx_n_DictType;
-static PyObject *__pyx_n_DictionaryType;
-static PyObject *__pyx_n_FloatType;
-static PyObject *__pyx_n_FunctionType;
-static PyObject *__pyx_n_IntType;
-static PyObject *__pyx_n_JSError;
-static PyObject *__pyx_n_JSRootObject;
-static PyObject *__pyx_n_LambdaType;
-static PyObject *__pyx_n_ListType;
-static PyObject *__pyx_n_LongType;
-static PyObject *__pyx_n_MethodType;
-static PyObject *__pyx_n_NoneType;
-static PyObject *__pyx_n_StringTypes;
-static PyObject *__pyx_n_TupleType;
-static PyObject *__pyx_n_TypeType;
-static PyObject *__pyx_n_UnicodeType;
-static PyObject *__pyx_n_Unknown;
-static PyObject *__pyx_n__;
-static PyObject *__pyx_n___class__;
-static PyObject *__pyx_n___init__;
-static PyObject *__pyx_n___jsinit__;
-static PyObject *__pyx_n___jsname__;
-static PyObject *__pyx_n___name__;
-static PyObject *__pyx_n___repr__;
-static PyObject *__pyx_n___str__;
-static PyObject *__pyx_n_append;
-static PyObject *__pyx_n_bind;
-static PyObject *__pyx_n_callable;
-static PyObject *__pyx_n_execute;
-static PyObject *__pyx_n_format_exc;
-static PyObject *__pyx_n_func_name;
-static PyObject *__pyx_n_im_fun;
-static PyObject *__pyx_n_inspect;
-static PyObject *__pyx_n_install_class;
-static PyObject *__pyx_n_isclass;
-static PyObject *__pyx_n_iteritems;
-static PyObject *__pyx_n_js_classname;
-static PyObject *__pyx_n_js_is_array;
-static PyObject *__pyx_n_js_is_bool;
-static PyObject *__pyx_n_js_is_double;
-static PyObject *__pyx_n_js_is_function;
-static PyObject *__pyx_n_js_is_hash;
-static PyObject *__pyx_n_js_is_int;
-static PyObject *__pyx_n_js_is_object;
-static PyObject *__pyx_n_js_is_string;
-static PyObject *__pyx_n_js_is_void;
-static PyObject *__pyx_n_mesg;
-static PyObject *__pyx_n_object;
-static PyObject *__pyx_n_print_exc;
-static PyObject *__pyx_n_py_is_array;
-static PyObject *__pyx_n_py_is_bool;
-static PyObject *__pyx_n_py_is_bound_method;
-static PyObject *__pyx_n_py_is_double;
-static PyObject *__pyx_n_py_is_function;
-static PyObject *__pyx_n_py_is_hash;
-static PyObject *__pyx_n_py_is_int;
-static PyObject *__pyx_n_py_is_object;
-static PyObject *__pyx_n_py_is_string;
-static PyObject *__pyx_n_py_is_void;
-static PyObject *__pyx_n_py_obj;
-static PyObject *__pyx_n_set_error;
-static PyObject *__pyx_n_stderr;
-static PyObject *__pyx_n_sys;
-static PyObject *__pyx_n_traceback;
-static PyObject *__pyx_n_types;
-static PyObject *__pyx_n_unicode;
-static PyObject *__pyx_n_write;
-
-static PyObject *__pyx_k1p;
-static PyObject *__pyx_k2p;
-static PyObject *__pyx_k9p;
-static PyObject *__pyx_k12p;
-static PyObject *__pyx_k15p;
-static PyObject *__pyx_k16p;
-static PyObject *__pyx_k17p;
-static PyObject *__pyx_k18p;
-static PyObject *__pyx_k19p;
-static PyObject *__pyx_k23p;
-static PyObject *__pyx_k24p;
-static PyObject *__pyx_k27p;
-static PyObject *__pyx_k31p;
-static PyObject *__pyx_k32p;
-static PyObject *__pyx_k35p;
-static PyObject *__pyx_k36p;
-static PyObject *__pyx_k38p;
-static PyObject *__pyx_k39p;
-static PyObject *__pyx_k40p;
-static PyObject *__pyx_k46p;
-static PyObject *__pyx_k48p;
-static PyObject *__pyx_k52p;
-static PyObject *__pyx_k53p;
-static PyObject *__pyx_k54p;
-static PyObject *__pyx_k57p;
-static PyObject *__pyx_k58p;
-static PyObject *__pyx_k59p;
-static PyObject *__pyx_k60p;
-static PyObject *__pyx_k66p;
-static PyObject *__pyx_k69p;
-static PyObject *__pyx_k70p;
-static PyObject *__pyx_k73p;
-static PyObject *__pyx_k76p;
-static PyObject *__pyx_k77p;
-static PyObject *__pyx_k79p;
-static PyObject *__pyx_k81p;
-static PyObject *__pyx_k82p;
-static PyObject *__pyx_k83p;
-static PyObject *__pyx_k85p;
-static PyObject *__pyx_k87p;
-static PyObject *__pyx_k99p;
-static PyObject *__pyx_k107p;
-
-static __Pyx_StringTabEntry __pyx_string_tab[] = {
-  {&__pyx_n_BooleanType, 1, __pyx_k71, sizeof(__pyx_k71)},
-  {&__pyx_n_DictType, 1, __pyx_k75, sizeof(__pyx_k75)},
-  {&__pyx_n_DictionaryType, 1, __pyx_k74, sizeof(__pyx_k74)},
-  {&__pyx_n_FloatType, 1, __pyx_k72, sizeof(__pyx_k72)},
-  {&__pyx_n_FunctionType, 1, __pyx_k61, sizeof(__pyx_k61)},
-  {&__pyx_n_IntType, 1, __pyx_k29, sizeof(__pyx_k29)},
-  {&__pyx_n_JSError, 1, __pyx_k14, sizeof(__pyx_k14)},
-  {&__pyx_n_JSRootObject, 1, __pyx_k20, sizeof(__pyx_k20)},
-  {&__pyx_n_LambdaType, 1, __pyx_k62, sizeof(__pyx_k62)},
-  {&__pyx_n_ListType, 1, __pyx_k67, sizeof(__pyx_k67)},
-  {&__pyx_n_LongType, 1, __pyx_k30, sizeof(__pyx_k30)},
-  {&__pyx_n_MethodType, 1, __pyx_k63, sizeof(__pyx_k63)},
-  {&__pyx_n_NoneType, 1, __pyx_k88, sizeof(__pyx_k88)},
-  {&__pyx_n_StringTypes, 1, __pyx_k86, sizeof(__pyx_k86)},
-  {&__pyx_n_TupleType, 1, __pyx_k68, sizeof(__pyx_k68)},
-  {&__pyx_n_TypeType, 1, __pyx_k55, sizeof(__pyx_k55)},
-  {&__pyx_n_UnicodeType, 1, __pyx_k43, sizeof(__pyx_k43)},
-  {&__pyx_n_Unknown, 1, __pyx_k10, sizeof(__pyx_k10)},
-  {&__pyx_n__, 1, __pyx_k45, sizeof(__pyx_k45)},
-  {&__pyx_n___class__, 1, __pyx_k22, sizeof(__pyx_k22)},
-  {&__pyx_n___init__, 1, __pyx_k108, sizeof(__pyx_k108)},
-  {&__pyx_n___jsinit__, 1, __pyx_k42, sizeof(__pyx_k42)},
-  {&__pyx_n___jsname__, 1, __pyx_k50, sizeof(__pyx_k50)},
-  {&__pyx_n___name__, 1, __pyx_k49, sizeof(__pyx_k49)},
-  {&__pyx_n___repr__, 1, __pyx_k110, sizeof(__pyx_k110)},
-  {&__pyx_n___str__, 1, __pyx_k109, sizeof(__pyx_k109)},
-  {&__pyx_n_append, 1, __pyx_k41, sizeof(__pyx_k41)},
-  {&__pyx_n_bind, 1, __pyx_k44, sizeof(__pyx_k44)},
-  {&__pyx_n_callable, 1, __pyx_k47, sizeof(__pyx_k47)},
-  {&__pyx_n_execute, 1, __pyx_k33, sizeof(__pyx_k33)},
-  {&__pyx_n_format_exc, 1, __pyx_k5, sizeof(__pyx_k5)},
-  {&__pyx_n_func_name, 1, __pyx_k64, sizeof(__pyx_k64)},
-  {&__pyx_n_im_fun, 1, __pyx_k65, sizeof(__pyx_k65)},
-  {&__pyx_n_inspect, 1, __pyx_k25, sizeof(__pyx_k25)},
-  {&__pyx_n_install_class, 1, __pyx_k21, sizeof(__pyx_k21)},
-  {&__pyx_n_isclass, 1, __pyx_k26, sizeof(__pyx_k26)},
-  {&__pyx_n_iteritems, 1, __pyx_k84, sizeof(__pyx_k84)},
-  {&__pyx_n_js_classname, 1, __pyx_k51, sizeof(__pyx_k51)},
-  {&__pyx_n_js_is_array, 1, __pyx_k103, sizeof(__pyx_k103)},
-  {&__pyx_n_js_is_bool, 1, __pyx_k101, sizeof(__pyx_k101)},
-  {&__pyx_n_js_is_double, 1, __pyx_k102, sizeof(__pyx_k102)},
-  {&__pyx_n_js_is_function, 1, __pyx_k104, sizeof(__pyx_k104)},
-  {&__pyx_n_js_is_hash, 1, __pyx_k106, sizeof(__pyx_k106)},
-  {&__pyx_n_js_is_int, 1, __pyx_k80, sizeof(__pyx_k80)},
-  {&__pyx_n_js_is_object, 1, __pyx_k105, sizeof(__pyx_k105)},
-  {&__pyx_n_js_is_string, 1, __pyx_k78, sizeof(__pyx_k78)},
-  {&__pyx_n_js_is_void, 1, __pyx_k100, sizeof(__pyx_k100)},
-  {&__pyx_n_mesg, 1, __pyx_k3, sizeof(__pyx_k3)},
-  {&__pyx_n_object, 1, __pyx_k111, sizeof(__pyx_k111)},
-  {&__pyx_n_print_exc, 1, __pyx_k13, sizeof(__pyx_k13)},
-  {&__pyx_n_py_is_array, 1, __pyx_k94, sizeof(__pyx_k94)},
-  {&__pyx_n_py_is_bool, 1, __pyx_k90, sizeof(__pyx_k90)},
-  {&__pyx_n_py_is_bound_method, 1, __pyx_k96, sizeof(__pyx_k96)},
-  {&__pyx_n_py_is_double, 1, __pyx_k92, sizeof(__pyx_k92)},
-  {&__pyx_n_py_is_function, 1, __pyx_k97, sizeof(__pyx_k97)},
-  {&__pyx_n_py_is_hash, 1, __pyx_k95, sizeof(__pyx_k95)},
-  {&__pyx_n_py_is_int, 1, __pyx_k91, sizeof(__pyx_k91)},
-  {&__pyx_n_py_is_object, 1, __pyx_k98, sizeof(__pyx_k98)},
-  {&__pyx_n_py_is_string, 1, __pyx_k93, sizeof(__pyx_k93)},
-  {&__pyx_n_py_is_void, 1, __pyx_k89, sizeof(__pyx_k89)},
-  {&__pyx_n_py_obj, 1, __pyx_k56, sizeof(__pyx_k56)},
-  {&__pyx_n_set_error, 1, __pyx_k11, sizeof(__pyx_k11)},
-  {&__pyx_n_stderr, 1, __pyx_k7, sizeof(__pyx_k7)},
-  {&__pyx_n_sys, 1, __pyx_k6, sizeof(__pyx_k6)},
-  {&__pyx_n_traceback, 1, __pyx_k4, sizeof(__pyx_k4)},
-  {&__pyx_n_types, 1, __pyx_k28, sizeof(__pyx_k28)},
-  {&__pyx_n_unicode, 1, __pyx_k34, sizeof(__pyx_k34)},
-  {&__pyx_n_write, 1, __pyx_k8, sizeof(__pyx_k8)},
-  {&__pyx_k1p, 0, __pyx_k1, sizeof(__pyx_k1)},
-  {&__pyx_k2p, 0, __pyx_k2, sizeof(__pyx_k2)},
-  {&__pyx_k9p, 0, __pyx_k9, sizeof(__pyx_k9)},
-  {&__pyx_k12p, 0, __pyx_k12, sizeof(__pyx_k12)},
-  {&__pyx_k15p, 0, __pyx_k15, sizeof(__pyx_k15)},
-  {&__pyx_k16p, 0, __pyx_k16, sizeof(__pyx_k16)},
-  {&__pyx_k17p, 0, __pyx_k17, sizeof(__pyx_k17)},
-  {&__pyx_k18p, 0, __pyx_k18, sizeof(__pyx_k18)},
-  {&__pyx_k19p, 0, __pyx_k19, sizeof(__pyx_k19)},
-  {&__pyx_k23p, 0, __pyx_k23, sizeof(__pyx_k23)},
-  {&__pyx_k24p, 0, __pyx_k24, sizeof(__pyx_k24)},
-  {&__pyx_k27p, 0, __pyx_k27, sizeof(__pyx_k27)},
-  {&__pyx_k31p, 0, __pyx_k31, sizeof(__pyx_k31)},
-  {&__pyx_k32p, 0, __pyx_k32, sizeof(__pyx_k32)},
-  {&__pyx_k35p, 0, __pyx_k35, sizeof(__pyx_k35)},
-  {&__pyx_k36p, 0, __pyx_k36, sizeof(__pyx_k36)},
-  {&__pyx_k38p, 0, __pyx_k38, sizeof(__pyx_k38)},
-  {&__pyx_k39p, 0, __pyx_k39, sizeof(__pyx_k39)},
-  {&__pyx_k40p, 0, __pyx_k40, sizeof(__pyx_k40)},
-  {&__pyx_k46p, 0, __pyx_k46, sizeof(__pyx_k46)},
-  {&__pyx_k48p, 0, __pyx_k48, sizeof(__pyx_k48)},
-  {&__pyx_k52p, 0, __pyx_k52, sizeof(__pyx_k52)},
-  {&__pyx_k53p, 0, __pyx_k53, sizeof(__pyx_k53)},
-  {&__pyx_k54p, 0, __pyx_k54, sizeof(__pyx_k54)},
-  {&__pyx_k57p, 0, __pyx_k57, sizeof(__pyx_k57)},
-  {&__pyx_k58p, 0, __pyx_k58, sizeof(__pyx_k58)},
-  {&__pyx_k59p, 0, __pyx_k59, sizeof(__pyx_k59)},
-  {&__pyx_k60p, 0, __pyx_k60, sizeof(__pyx_k60)},
-  {&__pyx_k66p, 0, __pyx_k66, sizeof(__pyx_k66)},
-  {&__pyx_k69p, 0, __pyx_k69, sizeof(__pyx_k69)},
-  {&__pyx_k70p, 0, __pyx_k70, sizeof(__pyx_k70)},
-  {&__pyx_k73p, 0, __pyx_k73, sizeof(__pyx_k73)},
-  {&__pyx_k76p, 0, __pyx_k76, sizeof(__pyx_k76)},
-  {&__pyx_k77p, 0, __pyx_k77, sizeof(__pyx_k77)},
-  {&__pyx_k79p, 0, __pyx_k79, sizeof(__pyx_k79)},
-  {&__pyx_k81p, 0, __pyx_k81, sizeof(__pyx_k81)},
-  {&__pyx_k82p, 0, __pyx_k82, sizeof(__pyx_k82)},
-  {&__pyx_k83p, 0, __pyx_k83, sizeof(__pyx_k83)},