comparison object.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 951ad1b15587
children 8a7abd0bb48d
comparison
equal deleted inserted replaced
36:04a6e9a67ae5 37:d4efcbb06964
25 25
26 if (self->runtime) { 26 if (self->runtime) {
27 Py_DECREF(self->runtime); 27 Py_DECREF(self->runtime);
28 self->runtime = NULL; 28 self->runtime = NULL;
29 } 29 }
30
31 self->ob_type->tp_free((PyObject *) self);
30 } 32 }
31 33
32 PyTypeObject PYM_JSObjectType = { 34 PyTypeObject PYM_JSObjectType = {
33 PyObject_HEAD_INIT(NULL) 35 PyObject_HEAD_INIT(NULL)
34 0, /*ob_size*/ 36 0, /*ob_size*/
49 0, /*tp_call*/ 51 0, /*tp_call*/
50 0, /*tp_str*/ 52 0, /*tp_str*/
51 0, /*tp_getattro*/ 53 0, /*tp_getattro*/
52 0, /*tp_setattro*/ 54 0, /*tp_setattro*/
53 0, /*tp_as_buffer*/ 55 0, /*tp_as_buffer*/
54 Py_TPFLAGS_DEFAULT, /*tp_flags*/ 56 /*tp_flags*/
57 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
55 /* tp_doc */ 58 /* tp_doc */
56 "JavaScript Object.", 59 "JavaScript Object.",
57 0, /* tp_traverse */ 60 0, /* tp_traverse */
58 0, /* tp_clear */ 61 0, /* tp_clear */
59 0, /* tp_richcompare */ 62 0, /* tp_richcompare */
72 0, /* tp_alloc */ 75 0, /* tp_alloc */
73 0, /* tp_new */ 76 0, /* tp_new */
74 }; 77 };
75 78
76 PYM_JSObject *PYM_newJSObject(PYM_JSContextObject *context, 79 PYM_JSObject *PYM_newJSObject(PYM_JSContextObject *context,
77 JSObject *obj) { 80 JSObject *obj,
81 PYM_JSObject *subclass) {
78 jsid uniqueId; 82 jsid uniqueId;
79 if (!JS_GetObjectId(context->cx, obj, &uniqueId)) { 83 if (!JS_GetObjectId(context->cx, obj, &uniqueId)) {
80 PyErr_SetString(PYM_error, "JS_GetObjectId() failed"); 84 PyErr_SetString(PYM_error, "JS_GetObjectId() failed");
81 return NULL; 85 return NULL;
82 } 86 }
91 if (JS_DHASH_ENTRY_IS_BUSY((JSDHashEntryHdr *) cached)) { 95 if (JS_DHASH_ENTRY_IS_BUSY((JSDHashEntryHdr *) cached)) {
92 Py_INCREF((PyObject *) cached->value); 96 Py_INCREF((PyObject *) cached->value);
93 return (PYM_JSObject *) cached->value; 97 return (PYM_JSObject *) cached->value;
94 } 98 }
95 99
96 PYM_JSObject *object = PyObject_New(PYM_JSObject, 100 PYM_JSObject *object;
97 &PYM_JSObjectType); 101
102 if (subclass)
103 object = subclass;
104 else
105 object = PyObject_New(PYM_JSObject,
106 &PYM_JSObjectType);
107
98 if (object == NULL) 108 if (object == NULL)
99 return NULL; 109 return NULL;
100 110
101 object->runtime = NULL; 111 object->runtime = NULL;
102 object->obj = NULL; 112 object->obj = NULL;