comparison utils.c @ 37:d4efcbb06964

Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
author Atul Varma <varmaa@toolness.com>
date Thu, 02 Jul 2009 22:42:31 -0700
parents 5d3d3b25f23f
children 0b9a316ce4ef
comparison
equal deleted inserted replaced
36:04a6e9a67ae5 37:d4efcbb06964
47 return PYM_doubleToJsval(cx, number, rval); 47 return PYM_doubleToJsval(cx, number, rval);
48 } 48 }
49 49
50 if (PyFloat_Check(object)) 50 if (PyFloat_Check(object))
51 return PYM_doubleToJsval(cx, PyFloat_AS_DOUBLE(object), rval); 51 return PYM_doubleToJsval(cx, PyFloat_AS_DOUBLE(object), rval);
52
53 if (PyObject_TypeCheck(object, &PYM_JSObjectType)) {
54 PYM_JSObject *jsObject = (PYM_JSObject *) object;
55 JSRuntime *rt = JS_GetRuntime(cx);
56 if (rt != jsObject->runtime->rt) {
57 PyErr_SetString(PyExc_ValueError,
58 "JS object and JS context are from different "
59 "JS runtimes");
60 return -1;
61 }
62 *rval = OBJECT_TO_JSVAL(jsObject->obj);
63 return 0;
64 }
52 65
53 if (object == Py_True) { 66 if (object == Py_True) {
54 *rval = JSVAL_TRUE; 67 *rval = JSVAL_TRUE;
55 return 0; 68 return 0;
56 } 69 }
104 // of bytes, not the number of 16-bit characters. 117 // of bytes, not the number of 16-bit characters.
105 return PyUnicode_DecodeUTF16(chars, length * 2, "ignore", NULL); 118 return PyUnicode_DecodeUTF16(chars, length * 2, "ignore", NULL);
106 } 119 }
107 120
108 if (JSVAL_IS_OBJECT(value)) 121 if (JSVAL_IS_OBJECT(value))
109 return (PyObject *) PYM_newJSObject(context, JSVAL_TO_OBJECT(value)); 122 return (PyObject *) PYM_newJSObject(context, JSVAL_TO_OBJECT(value),
123 NULL);
110 124
111 // TODO: Support more types. 125 // TODO: Support more types.
112 PyErr_SetString(PyExc_NotImplementedError, 126 PyErr_SetString(PyExc_NotImplementedError,
113 "Data type conversion not implemented."); 127 "Data type conversion not implemented.");
114 return NULL; 128 return NULL;