Mercurial > pymonkey
changeset 77:755af0a94c94
Added a pymonkey.Object.get_runtime() method.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 07 Aug 2009 11:20:12 -0700 |
parents | 4cb89d48b068 |
children | c48b393f6461 |
files | object.c test_pymonkey.py |
diffstat | 2 files changed, 20 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/object.c Fri Aug 07 11:02:56 2009 -0700 +++ b/object.c Fri Aug 07 11:20:12 2009 -0700 @@ -130,6 +130,19 @@ self->ob_type->tp_free((PyObject *) self); } +static PyObject * +PYM_getRuntime(PYM_JSObject *self, PyObject *args) +{ + Py_INCREF(self->runtime); + return (PyObject *) self->runtime; +} + +static PyMethodDef PYM_JSObjectMethods[] = { + {"get_runtime", (PyCFunction) PYM_getRuntime, METH_VARARGS, + "Get the JavaScript runtime associated with this object."}, + {NULL, NULL, 0, NULL} +}; + PyTypeObject PYM_JSObjectType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ @@ -162,7 +175,7 @@ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + PYM_JSObjectMethods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */
--- a/test_pymonkey.py Fri Aug 07 11:02:56 2009 -0700 +++ b/test_pymonkey.py Fri Aug 07 11:20:12 2009 -0700 @@ -324,7 +324,12 @@ def testFunctionTypeCannotBeInstantiated(self): self.assertRaises(TypeError, pymonkey.Function) - def testGetRuntimeWorks(self): + def testObjectGetRuntimeWorks(self): + rt = pymonkey.Runtime() + obj = rt.new_context().new_object() + self.assertEqual(obj.get_runtime(), rt) + + def testContextGetRuntimeWorks(self): rt = pymonkey.Runtime() cx = rt.new_context() self.assertEqual(cx.get_runtime(), rt)