annotate object.c @ 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 b0360c0ed546
children 9e8e56b4de6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
1 /* ***** BEGIN LICENSE BLOCK *****
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
3 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
4 * The contents of this file are subject to the Mozilla Public License Version
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
5 * 1.1 (the "License"); you may not use this file except in compliance with
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
6 * the License. You may obtain a copy of the License at
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
7 * http://www.mozilla.org/MPL/
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
8 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
9 * Software distributed under the License is distributed on an "AS IS" basis,
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
11 * for the specific language governing rights and limitations under the
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
12 * License.
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
13 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
14 * The Original Code is Pymonkey.
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
15 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
16 * The Initial Developer of the Original Code is Mozilla.
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
17 * Portions created by the Initial Developer are Copyright (C) 2007
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
18 * the Initial Developer. All Rights Reserved.
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
19 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
20 * Contributor(s):
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
21 * Atul Varma <atul@mozilla.com>
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
22 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
23 * Alternatively, the contents of this file may be used under the terms of
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
26 * in which case the provisions of the GPL or the LGPL are applicable instead
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
27 * of those above. If you wish to allow use of your version of this file only
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
28 * under the terms of either the GPL or the LGPL, and not to allow others to
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
29 * use your version of this file under the terms of the MPL, indicate your
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
30 * decision by deleting the provisions above and replace them with the notice
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
31 * and other provisions required by the GPL or the LGPL. If you do not delete
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
32 * the provisions above, a recipient may use your version of this file under
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
33 * the terms of any one of the MPL, the GPL or the LGPL.
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
34 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
35 * ***** END LICENSE BLOCK ***** */
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 40
diff changeset
36
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
37 #include "object.h"
40
8a7abd0bb48d Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
38 #include "function.h"
21
fc04e5f1c675 Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
39 #include "runtime.h"
22
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
40 #include "utils.h"
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
41
70
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
42 JSObject *
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
43 PYM_JS_newObject(JSContext *cx, PyObject *pyObject)
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
44 {
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
45 JSObject *obj = JS_NewObject(cx, &PYM_JS_ObjectClass, NULL, NULL);
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
46 if (obj) {
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
47 if (!JS_SetReservedSlot(cx, obj, 0, PRIVATE_TO_JSVAL(pyObject)))
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
48 return NULL;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
49 Py_XINCREF(pyObject);
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
50 }
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
51 return obj;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
52 }
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
53
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
54 JSBool
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
55 PYM_JS_setPrivatePyObject(JSContext *cx, JSObject *obj, PyObject *pyObject)
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
56 {
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
57 JSClass *klass = JS_GET_CLASS(cx, obj);
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
58 if (klass != &PYM_JS_ObjectClass) {
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
59 JS_ReportError(cx, "Object is not an instance of PymonkeyObject");
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
60 return JS_FALSE;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
61 }
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
62
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
63 PyObject *old;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
64 if (!PYM_JS_getPrivatePyObject(cx, obj, &old))
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
65 return JS_FALSE;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
66 if (!JS_SetReservedSlot(cx, obj, 0, PRIVATE_TO_JSVAL(pyObject)))
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
67 return JS_FALSE;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
68 Py_INCREF(pyObject);
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
69 Py_XDECREF(old);
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
70 return JS_TRUE;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
71 }
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
72
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
73 JSBool
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
74 PYM_JS_getPrivatePyObject(JSContext *cx, JSObject *obj, PyObject **pyObject)
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
75 {
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
76 JSClass *klass = JS_GET_CLASS(cx, obj);
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
77 if (klass != &PYM_JS_ObjectClass) {
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
78 JS_ReportError(cx, "Object is not an instance of PymonkeyObject");
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
79 return JS_FALSE;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
80 }
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
81
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
82 jsval val;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
83 if (!JS_GetReservedSlot(cx, obj, 0, &val))
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
84 return JS_FALSE;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
85 *pyObject = (PyObject *) JSVAL_TO_PRIVATE(val);
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
86 return JS_TRUE;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
87 }
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
88
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
89 static void
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
90 PYM_JS_finalizeObject(JSContext *cx, JSObject *obj)
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
91 {
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
92 PYM_PyAutoEnsureGIL gil;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
93 PyObject *pyObject;
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
94 // TODO: What if this fails?
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
95 if (PYM_JS_getPrivatePyObject(cx, obj, &pyObject))
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
96 Py_XDECREF(pyObject);
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
97 }
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
98
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
99 // This one-size-fits-all JSClass is used for any JS objects created
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
100 // in Python. It can hold a reference to a Python object for as long as
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
101 // its parent JS object is accessible from JS-land. As soon as it's
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
102 // garbage collected by the JS interpreter, it releases its reference on
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
103 // the Python object.
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
104 JSClass PYM_JS_ObjectClass = {
70
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
105 "PymonkeyObject", JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_RESERVED_SLOTS(1),
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
106 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
70
b0360c0ed546 Factored the JS FunctionHolder class into the JS PymonkeyObject class, so that any PymonkeyObject can contain a private Python object if it needs to.
Atul Varma <varmaa@toolness.com>
parents: 63
diff changeset
107 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, PYM_JS_finalizeObject,
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
108 JSCLASS_NO_OPTIONAL_MEMBERS
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
109 };
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
110
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
111 static void
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
112 PYM_JSObjectDealloc(PYM_JSObject *self)
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
113 {
15
baa4cb961330 JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents: 13
diff changeset
114 if (self->obj) {
23
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
115 JS_DHashTableOperate(&self->runtime->objects,
63
f3ecf06a2851 js objects no longer have a unique id in addition to their JSObject *, since mrbkap verified that SpiderMonkey's mark-and-sweep garbage collector isn't a copying one.
Atul Varma <varmaa@toolness.com>
parents: 61
diff changeset
116 (void *) self->obj,
23
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
117 JS_DHASH_REMOVE);
22
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
118
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
119 // JS_RemoveRoot() always returns JS_TRUE, so don't
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
120 // bother checking its return value.
15
baa4cb961330 JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents: 13
diff changeset
121 JS_RemoveRootRT(self->runtime->rt, &self->obj);
baa4cb961330 JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents: 13
diff changeset
122 self->obj = NULL;
baa4cb961330 JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents: 13
diff changeset
123 }
baa4cb961330 JS objects in python-land are now rooted while in python-land so that they're not gc'd while in python-land.
Atul Varma <varmaa@toolness.com>
parents: 13
diff changeset
124
22
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
125 if (self->runtime) {
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
126 Py_DECREF(self->runtime);
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
127 self->runtime = NULL;
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
128 }
37
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
129
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
130 self->ob_type->tp_free((PyObject *) self);
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
131 }
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
132
77
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
133 static PyObject *
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
134 PYM_getRuntime(PYM_JSObject *self, PyObject *args)
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
135 {
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
136 Py_INCREF(self->runtime);
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
137 return (PyObject *) self->runtime;
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
138 }
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
139
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
140 static PyMethodDef PYM_JSObjectMethods[] = {
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
141 {"get_runtime", (PyCFunction) PYM_getRuntime, METH_VARARGS,
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
142 "Get the JavaScript runtime associated with this object."},
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
143 {NULL, NULL, 0, NULL}
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
144 };
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
145
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
146 PyTypeObject PYM_JSObjectType = {
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
147 PyObject_HEAD_INIT(NULL)
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
148 0, /*ob_size*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
149 "pymonkey.Object", /*tp_name*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
150 sizeof(PYM_JSObject), /*tp_basicsize*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
151 0, /*tp_itemsize*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
152 /*tp_dealloc*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
153 (destructor) PYM_JSObjectDealloc,
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
154 0, /*tp_print*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
155 0, /*tp_getattr*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
156 0, /*tp_setattr*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
157 0, /*tp_compare*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
158 0, /*tp_repr*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
159 0, /*tp_as_number*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
160 0, /*tp_as_sequence*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
161 0, /*tp_as_mapping*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
162 0, /*tp_hash */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
163 0, /*tp_call*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
164 0, /*tp_str*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
165 0, /*tp_getattro*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
166 0, /*tp_setattro*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
167 0, /*tp_as_buffer*/
37
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
168 /*tp_flags*/
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
169 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
170 /* tp_doc */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
171 "JavaScript Object.",
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
172 0, /* tp_traverse */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
173 0, /* tp_clear */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
174 0, /* tp_richcompare */
23
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
175 0, /* tp_weaklistoffset */
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
176 0, /* tp_iter */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
177 0, /* tp_iternext */
77
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
178 PYM_JSObjectMethods, /* tp_methods */
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
179 0, /* tp_members */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
180 0, /* tp_getset */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
181 0, /* tp_base */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
182 0, /* tp_dict */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
183 0, /* tp_descr_get */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
184 0, /* tp_descr_set */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
185 0, /* tp_dictoffset */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
186 0, /* tp_init */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
187 0, /* tp_alloc */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
188 0, /* tp_new */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
189 };
18
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
190
21
fc04e5f1c675 Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
191 PYM_JSObject *PYM_newJSObject(PYM_JSContextObject *context,
37
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
192 JSObject *obj,
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
193 PYM_JSObject *subclass) {
22
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
194 PYM_JSRuntimeObject *runtime = context->runtime;
23
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
195 PYM_HashEntry *cached = (PYM_HashEntry *) JS_DHashTableOperate(
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
196 &runtime->objects,
63
f3ecf06a2851 js objects no longer have a unique id in addition to their JSObject *, since mrbkap verified that SpiderMonkey's mark-and-sweep garbage collector isn't a copying one.
Atul Varma <varmaa@toolness.com>
parents: 61
diff changeset
197 (void *) obj,
23
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
198 JS_DHASH_LOOKUP
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
199 );
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
200
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
201 if (JS_DHASH_ENTRY_IS_BUSY((JSDHashEntryHdr *) cached)) {
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
202 Py_INCREF((PyObject *) cached->value);
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
203 return (PYM_JSObject *) cached->value;
22
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
204 }
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
205
37
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
206 PYM_JSObject *object;
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
207
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
208 if (subclass)
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
209 object = subclass;
40
8a7abd0bb48d Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
210 else {
8a7abd0bb48d Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
211 if (JS_ObjectIsFunction(context->cx, obj)) {
8a7abd0bb48d Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
212 PYM_JSFunction *func = PyObject_New(PYM_JSFunction,
8a7abd0bb48d Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
213 &PYM_JSFunctionType);
8a7abd0bb48d Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
214 object = (PYM_JSObject *) func;
8a7abd0bb48d Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
215 } else
8a7abd0bb48d Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
216 object = PyObject_New(PYM_JSObject,
8a7abd0bb48d Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
217 &PYM_JSObjectType);
8a7abd0bb48d Renamed PYM_newJSFunction() to PYM_newJSFunctionFromCallable(). PYM_newJSObject() now returns objects of type PYM_JSFunctionType as needed.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
218 }
37
d4efcbb06964 Added a new PYM_JSFunction type, PYM_JSContext.define_property(), and PYM_JSContext.new_function(). Also fixed a memory leak.
Atul Varma <varmaa@toolness.com>
parents: 23
diff changeset
219
23
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
220 if (object == NULL)
18
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
221 return NULL;
22
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
222
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
223 object->runtime = NULL;
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
224 object->obj = NULL;
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
225
23
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
226 cached = (PYM_HashEntry *) JS_DHashTableOperate(&runtime->objects,
63
f3ecf06a2851 js objects no longer have a unique id in addition to their JSObject *, since mrbkap verified that SpiderMonkey's mark-and-sweep garbage collector isn't a copying one.
Atul Varma <varmaa@toolness.com>
parents: 61
diff changeset
227 (void *) obj,
23
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
228 JS_DHASH_ADD);
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
229 if (cached == NULL) {
22
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
230 Py_DECREF(object);
23
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
231 PyErr_SetString(PYM_error, "JS_DHashTableOperate() failed");
22
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
232 return NULL;
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
233 }
988a8998c75f JS objects reflected into Python are now identity-preserving, though the implementation for this is pretty bad right now.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
234
63
f3ecf06a2851 js objects no longer have a unique id in addition to their JSObject *, since mrbkap verified that SpiderMonkey's mark-and-sweep garbage collector isn't a copying one.
Atul Varma <varmaa@toolness.com>
parents: 61
diff changeset
235 cached->base.key = (void *) obj;
23
951ad1b15587 The hashtable of reflected JS objects now uses a JS_DHashTable instead of a PyDict. Also removed weakref-ability of the JSObject class since it didn't make any sense to use Python's weakref support for JSObjects.
Atul Varma <varmaa@toolness.com>
parents: 22
diff changeset
236 cached->value = object;
18
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
237
21
fc04e5f1c675 Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
238 object->runtime = context->runtime;
18
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
239 Py_INCREF(object->runtime);
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
240
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
241 object->obj = obj;
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
242
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
243 JS_AddNamedRootRT(object->runtime->rt, &object->obj,
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
244 "Pymonkey-Generated Object");
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
245
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
246 return object;
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
247 }