# HG changeset patch # User Atul Varma # Date 1249669212 25200 # Node ID 755af0a94c94e8a3d5fc391b6ff7b47c32942fbd # Parent 4cb89d48b06874ea18d1dbf8ef656dfad428e7b0 Added a pymonkey.Object.get_runtime() method. diff -r 4cb89d48b068 -r 755af0a94c94 object.c --- 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 */ diff -r 4cb89d48b068 -r 755af0a94c94 test_pymonkey.py --- 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)