Mercurial > pymonkey
changeset 40:8a7abd0bb48d
Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 03 Jul 2009 20:04:01 -0700 |
parents | 9103afca7386 |
children | 71ab5e977dd3 |
files | context.c function.c function.h object.c test_pymonkey.py |
diffstat | 5 files changed, 28 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/context.c Fri Jul 03 19:40:42 2009 -0700 +++ b/context.c Fri Jul 03 20:04:01 2009 -0700 @@ -159,7 +159,7 @@ if (!PyArg_ParseTuple(args, "Os", &callable, &name)) return NULL; - return (PyObject *) PYM_newJSFunction(self, callable, name); + return (PyObject *) PYM_newJSFunctionFromCallable(self, callable, name); } static PyMethodDef PYM_JSContextMethods[] = {
--- a/function.c Fri Jul 03 19:40:42 2009 -0700 +++ b/function.c Fri Jul 03 20:04:01 2009 -0700 @@ -99,9 +99,9 @@ }; PYM_JSFunction * -PYM_newJSFunction(PYM_JSContextObject *context, - PyObject *callable, - const char *name) +PYM_newJSFunctionFromCallable(PYM_JSContextObject *context, + PyObject *callable, + const char *name) { if (!PyCallable_Check(callable)) { PyErr_SetString(PyExc_TypeError, "Callable must be callable");
--- a/function.h Fri Jul 03 19:40:42 2009 -0700 +++ b/function.h Fri Jul 03 20:04:01 2009 -0700 @@ -15,8 +15,8 @@ extern PyTypeObject PYM_JSFunctionType; extern PYM_JSFunction * -PYM_newJSFunction(PYM_JSContextObject *context, - PyObject *callable, - const char *name); +PYM_newJSFunctionFromCallable(PYM_JSContextObject *context, + PyObject *callable, + const char *name); #endif
--- a/object.c Fri Jul 03 19:40:42 2009 -0700 +++ b/object.c Fri Jul 03 20:04:01 2009 -0700 @@ -1,4 +1,5 @@ #include "object.h" +#include "function.h" #include "runtime.h" #include "utils.h" @@ -101,9 +102,17 @@ if (subclass) object = subclass; - else - object = PyObject_New(PYM_JSObject, - &PYM_JSObjectType); + else { + if (JS_ObjectIsFunction(context->cx, obj)) { + PYM_JSFunction *func = PyObject_New(PYM_JSFunction, + &PYM_JSFunctionType); + if (func != NULL) + func->callable = NULL; + object = (PYM_JSObject *) func; + } else + object = PyObject_New(PYM_JSObject, + &PYM_JSObjectType); + } if (object == NULL) return NULL;
--- a/test_pymonkey.py Fri Jul 03 19:40:42 2009 -0700 +++ b/test_pymonkey.py Fri Jul 03 20:04:01 2009 -0700 @@ -161,6 +161,15 @@ self.assertTrue(isinstance(obj, pymonkey.Object)) self.assertEqual(cx.get_property(obj, u"boop"), 1) + def testEvaluateReturnsFunction(self): + rt = pymonkey.Runtime() + cx = rt.new_context() + obj = cx.new_object() + cx.init_standard_classes(obj) + obj = cx.evaluate_script(obj, '(function boop() { return 1; })', + '<string>', 1) + self.assertTrue(isinstance(obj, pymonkey.Function)) + def testEvaluateReturnsTrue(self): self.assertTrue(self._evaljs('true') is True)