annotate object.c @ 82:9e8e56b4de6f

Changed PymonkeyObject JSClass to store its private Python object in its private slot rather than a reserved slot.
author Atul Varma <varmaa@toolness.com>
date Sun, 09 Aug 2009 14:42:54 -0700
parents 755af0a94c94
children
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) {
82
9e8e56b4de6f Changed PymonkeyObject JSClass to store its private Python object in its private slot rather than a reserved slot.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
47 if (!JS_SetPrivate(cx, obj, pyObject))
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
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 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
58 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
59 return JS_FALSE;
82
9e8e56b4de6f Changed PymonkeyObject JSClass to store its private Python object in its private slot rather than a reserved slot.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
60 if (!JS_SetPrivate(cx, obj, pyObject))
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
61 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
62 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
63 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
64 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
65 }
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
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 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
68 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
69 {
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 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
71 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
72 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
73 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
74 }
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
82
9e8e56b4de6f Changed PymonkeyObject JSClass to store its private Python object in its private slot rather than a reserved slot.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
76 *pyObject = (PyObject *) JS_GetPrivate(cx, obj);
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
77 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
78 }
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
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 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
81 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
82 {
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 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
84 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
85 // 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
86 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
87 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
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
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 // 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
91 // 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
92 // 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
93 // 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
94 // the Python object.
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
95 JSClass PYM_JS_ObjectClass = {
82
9e8e56b4de6f Changed PymonkeyObject JSClass to store its private Python object in its private slot rather than a reserved slot.
Atul Varma <varmaa@toolness.com>
parents: 77
diff changeset
96 "PymonkeyObject", JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_PRIVATE,
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
97 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
98 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, PYM_JS_finalizeObject,
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
99 JSCLASS_NO_OPTIONAL_MEMBERS
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
100 };
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
101
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
102 static void
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
103 PYM_JSObjectDealloc(PYM_JSObject *self)
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
104 {
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
105 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
106 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
107 (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
108 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
109
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
110 // 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
111 // 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
112 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
113 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
114 }
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
115
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
116 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
117 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
118 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
119 }
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
120
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
121 self->ob_type->tp_free((PyObject *) self);
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
122 }
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
123
77
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
124 static PyObject *
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
125 PYM_getRuntime(PYM_JSObject *self, PyObject *args)
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
126 {
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
127 Py_INCREF(self->runtime);
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
128 return (PyObject *) self->runtime;
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
129 }
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
130
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
131 static PyMethodDef PYM_JSObjectMethods[] = {
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
132 {"get_runtime", (PyCFunction) PYM_getRuntime, METH_VARARGS,
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
133 "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
134 {NULL, NULL, 0, NULL}
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
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
137 PyTypeObject PYM_JSObjectType = {
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
138 PyObject_HEAD_INIT(NULL)
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
139 0, /*ob_size*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
140 "pymonkey.Object", /*tp_name*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
141 sizeof(PYM_JSObject), /*tp_basicsize*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
142 0, /*tp_itemsize*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
143 /*tp_dealloc*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
144 (destructor) PYM_JSObjectDealloc,
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
145 0, /*tp_print*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
146 0, /*tp_getattr*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
147 0, /*tp_setattr*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
148 0, /*tp_compare*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
149 0, /*tp_repr*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
150 0, /*tp_as_number*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
151 0, /*tp_as_sequence*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
152 0, /*tp_as_mapping*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
153 0, /*tp_hash */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
154 0, /*tp_call*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
155 0, /*tp_str*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
156 0, /*tp_getattro*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
157 0, /*tp_setattro*/
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
158 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
159 /*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
160 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
161 /* tp_doc */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
162 "JavaScript Object.",
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
163 0, /* tp_traverse */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
164 0, /* tp_clear */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
165 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
166 0, /* tp_weaklistoffset */
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
167 0, /* tp_iter */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
168 0, /* tp_iternext */
77
755af0a94c94 Added a pymonkey.Object.get_runtime() method.
Atul Varma <varmaa@toolness.com>
parents: 70
diff changeset
169 PYM_JSObjectMethods, /* tp_methods */
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
170 0, /* tp_members */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
171 0, /* tp_getset */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
172 0, /* tp_base */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
173 0, /* tp_dict */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
174 0, /* tp_descr_get */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
175 0, /* tp_descr_set */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
176 0, /* tp_dictoffset */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
177 0, /* tp_init */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
178 0, /* tp_alloc */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
179 0, /* tp_new */
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
180 };
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
181
21
fc04e5f1c675 Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
182 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
183 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
184 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
185 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
186 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
187 &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
188 (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
189 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
190 );
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
191
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
192 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
193 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
194 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
195 }
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
196
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
197 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
198
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
199 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
200 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
201 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
202 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
203 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
204 &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
205 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
206 } 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
207 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
208 &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
209 }
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
210
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
211 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
212 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
213
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
214 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
215 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
216
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
217 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
218 (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
219 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
220 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
221 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
222 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
223 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
224 }
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
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
226 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
227 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
228
21
fc04e5f1c675 Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
229 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
230 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
231
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
232 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
233
f3223debd70b Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents: 15
diff changeset
234 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
235 "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
236
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 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
238 }