Mercurial > pymonkey
annotate src/object.cpp @ 173:5cfb47c9e916 default tip
Minor line wrap and spacing fixes.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 01 Sep 2009 03:22:33 -0700 |
parents | dd32a92f6b4f |
children |
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 * |
170
dd32a92f6b4f
Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
14 * The Original Code is Pydermonkey. |
48
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 | 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 | 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) { |
170
dd32a92f6b4f
Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
72 JS_ReportError(cx, "Object is not an instance of PydermonkeyObject"); |
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
|
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 | 95 JSClass PYM_JS_ObjectClass = { |
170
dd32a92f6b4f
Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
96 "PydermonkeyObject", JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_PRIVATE, |
13 | 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 | 99 JSCLASS_NO_OPTIONAL_MEMBERS |
100 }; | |
101 | |
102 static void | |
103 PYM_JSObjectDealloc(PYM_JSObject *self) | |
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 | 122 } |
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 | 137 PyTypeObject PYM_JSObjectType = { |
138 PyObject_HEAD_INIT(NULL) | |
139 0, /*ob_size*/ | |
173
5cfb47c9e916
Minor line wrap and spacing fixes.
Atul Varma <varmaa@toolness.com>
parents:
170
diff
changeset
|
140 "pydermonkey.Object", /*tp_name*/ |
13 | 141 sizeof(PYM_JSObject), /*tp_basicsize*/ |
142 0, /*tp_itemsize*/ | |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
143 /*tp_dealloc*/ |
13 | 144 (destructor) PYM_JSObjectDealloc, |
145 0, /*tp_print*/ | |
146 0, /*tp_getattr*/ | |
147 0, /*tp_setattr*/ | |
148 0, /*tp_compare*/ | |
149 0, /*tp_repr*/ | |
150 0, /*tp_as_number*/ | |
151 0, /*tp_as_sequence*/ | |
152 0, /*tp_as_mapping*/ | |
153 0, /*tp_hash */ | |
154 0, /*tp_call*/ | |
155 0, /*tp_str*/ | |
156 0, /*tp_getattro*/ | |
157 0, /*tp_setattro*/ | |
158 0, /*tp_as_buffer*/ | |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
159 /*tp_flags*/ |
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
|
160 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
161 /* tp_doc */ |
13 | 162 "JavaScript Object.", |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
163 0, /* tp_traverse */ |
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
164 0, /* tp_clear */ |
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
117
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 */ |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
167 0, /* tp_iter */ |
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
117
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 | 170 0, /* tp_members */ |
171 0, /* tp_getset */ | |
172 0, /* tp_base */ | |
173 0, /* tp_dict */ | |
174 0, /* tp_descr_get */ | |
175 0, /* tp_descr_set */ | |
176 0, /* tp_dictoffset */ | |
177 0, /* tp_init */ | |
178 0, /* tp_alloc */ | |
179 0, /* tp_new */ | |
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 |
135
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
182 PYM_JSObject *PYM_findJSObject(PYM_JSContextObject *context, JSObject *obj) |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
183 { |
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
|
184 PYM_HashEntry *cached = (PYM_HashEntry *) JS_DHashTableOperate( |
135
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
185 &context->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
|
186 (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
|
187 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
|
188 ); |
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 |
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 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
|
191 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
|
192 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
|
193 } |
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 |
135
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
195 return NULL; |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
196 } |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
197 |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
198 PYM_JSObject *PYM_newJSObject(PYM_JSContextObject *context, |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
199 JSObject *obj, |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
200 PYM_JSObject *subclass) |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
201 { |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
202 PYM_JSObject *cachedObject = PYM_findJSObject(context, obj); |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
203 if (cachedObject) |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
204 return cachedObject; |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
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)) { |
152
80463c8c7930
Added a 'name' property to function obects. Fixed a TODO.
Atul Varma <varmaa@toolness.com>
parents:
136
diff
changeset
|
212 PYM_JSFunction *func = PYM_newJSFunction( |
80463c8c7930
Added a 'name' property to function obects. Fixed a TODO.
Atul Varma <varmaa@toolness.com>
parents:
136
diff
changeset
|
213 context, |
80463c8c7930
Added a 'name' property to function obects. Fixed a TODO.
Atul Varma <varmaa@toolness.com>
parents:
136
diff
changeset
|
214 JS_ValueToFunction(context->cx, OBJECT_TO_JSVAL(obj)) |
80463c8c7930
Added a 'name' property to function obects. Fixed a TODO.
Atul Varma <varmaa@toolness.com>
parents:
136
diff
changeset
|
215 ); |
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
|
216 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
|
217 } 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
|
218 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
|
219 &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
|
220 } |
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
|
221 |
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 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
|
223 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
|
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 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
|
226 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
|
227 |
135
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
228 PYM_HashEntry *cached = (PYM_HashEntry *) JS_DHashTableOperate( |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
229 &context->runtime->objects, |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
230 (void *) obj, |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
231 JS_DHASH_ADD |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
232 ); |
9157e7c9cb81
Refactored a new function, PYM_findJSObject(), out of PYM_newJSObject().
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
233 |
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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 } |
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
|
239 |
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
|
240 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
|
241 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
|
242 |
21
fc04e5f1c675
Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
243 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
|
244 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
|
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 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
|
247 |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
248 JS_AddNamedRootRT(object->runtime->rt, &object->obj, |
170
dd32a92f6b4f
Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents:
152
diff
changeset
|
249 "Pydermonkey-Generated 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
|
250 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
|
251 } |