Mercurial > pymonkey
annotate src/runtime.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:
47
diff
changeset
|
1 /* ***** BEGIN LICENSE BLOCK ***** |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
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:
47
diff
changeset
|
3 * |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
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:
47
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:
47
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:
47
diff
changeset
|
7 * http://www.mozilla.org/MPL/ |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
8 * |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
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:
47
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:
47
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:
47
diff
changeset
|
12 * License. |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
13 * |
170
dd32a92f6b4f
Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents:
151
diff
changeset
|
14 * The Original Code is Pydermonkey. |
48
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
15 * |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
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:
47
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:
47
diff
changeset
|
18 * the Initial Developer. All Rights Reserved. |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
19 * |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
20 * Contributor(s): |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
21 * Atul Varma <atul@mozilla.com> |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
22 * |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
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:
47
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:
47
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:
47
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:
47
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:
47
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:
47
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:
47
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:
47
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:
47
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:
47
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:
47
diff
changeset
|
34 * |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
35 * ***** END LICENSE BLOCK ***** */ |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
36 |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
37 #include "runtime.h" |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
38 #include "context.h" |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
39 #include "utils.h" |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
40 |
151
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
41 static unsigned int runtimeCount = 0; |
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
42 |
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
43 unsigned int PYM_getJSRuntimeCount() |
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
44 { |
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
45 return runtimeCount; |
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
46 } |
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
47 |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
48 static PyObject * |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
49 PYM_JSRuntimeNew(PyTypeObject *type, PyObject *args, |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
50 PyObject *kwds) |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
51 { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
52 PYM_JSRuntimeObject *self; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
53 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
54 self = (PYM_JSRuntimeObject *) type->tp_alloc(type, 0); |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
55 if (self != NULL) { |
129
7b7a23615873
Added weakref support for runtimes.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
56 self->weakrefs = NULL; |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
62
diff
changeset
|
57 self->thread = PyThread_get_thread_ident(); |
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:
19
diff
changeset
|
58 self->rt = NULL; |
62
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
59 self->cx = NULL; |
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
|
60 self->objects.ops = 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:
19
diff
changeset
|
61 |
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
|
62 if (!JS_DHashTableInit(&self->objects, |
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
|
63 JS_DHashGetStubOps(), |
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
|
64 NULL, |
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
|
65 sizeof(PYM_HashEntry), |
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
|
66 JS_DHASH_DEFAULT_CAPACITY(100))) { |
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
|
67 PyErr_SetString(PYM_error, "JS_DHashTableInit() failed"); |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
68 type->tp_dealloc((PyObject *) self); |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
69 self = NULL; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
70 } |
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:
19
diff
changeset
|
71 |
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:
19
diff
changeset
|
72 if (self != 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:
19
diff
changeset
|
73 self->rt = JS_NewRuntime(8L * 1024L * 1024L); |
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:
19
diff
changeset
|
74 if (!self->rt) { |
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:
19
diff
changeset
|
75 PyErr_SetString(PYM_error, "JS_NewRuntime() failed"); |
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:
19
diff
changeset
|
76 type->tp_dealloc((PyObject *) self); |
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:
19
diff
changeset
|
77 self = NULL; |
62
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
78 } else { |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
79 self->cx = JS_NewContext(self->rt, 8192); |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
80 if (!self->cx) { |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
81 PyErr_SetString(PYM_error, "JS_NewContext() failed"); |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
82 type->tp_dealloc((PyObject *) self); |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
83 self = NULL; |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
84 } |
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:
19
diff
changeset
|
85 } |
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:
19
diff
changeset
|
86 } |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
87 } |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
88 |
151
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
89 if (self) |
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
90 runtimeCount++; |
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
91 |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
92 return (PyObject *) self; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
93 } |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
94 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
95 static void |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
96 PYM_JSRuntimeDealloc(PYM_JSRuntimeObject *self) |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
97 { |
129
7b7a23615873
Added weakref support for runtimes.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
98 if (self->weakrefs) |
7b7a23615873
Added weakref support for runtimes.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
99 PyObject_ClearWeakRefs((PyObject *) self); |
7b7a23615873
Added weakref support for runtimes.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
100 |
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
|
101 if (self->objects.ops) { |
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
|
102 JS_DHashTableFinish(&self->objects); |
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
|
103 self->objects.ops = 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:
19
diff
changeset
|
104 } |
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:
19
diff
changeset
|
105 |
62
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
106 if (self->cx) { |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
107 // Note that this will also force GC of any remaining objects |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
108 // in the runtime. |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
109 JS_DestroyContext(self->cx); |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
110 self->cx = NULL; |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
111 } |
2b5696b91b01
Fixed a bug whereby some objects wouldn't be finalized when a runtime was destroyed.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
112 |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
113 if (self->rt) { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
114 JS_DestroyRuntime(self->rt); |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
115 self->rt = NULL; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
116 } |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
117 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
118 self->ob_type->tp_free((PyObject *) self); |
151
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
119 |
657afb7307eb
Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
120 runtimeCount--; |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
121 } |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
122 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
123 static PyObject * |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
124 PYM_newContext(PYM_JSRuntimeObject *self, PyObject *args) |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
125 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
62
diff
changeset
|
126 PYM_SANITY_CHECK(self); |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
127 JSContext *cx = JS_NewContext(self->rt, 8192); |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
128 if (cx == NULL) { |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
129 PyErr_SetString(PYM_error, "JS_NewContext() failed"); |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
130 return NULL; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
131 } |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
132 |
47
3f4982759e55
Converting JS exceptions into Python exceptions is now doable, albeit not yet implemented, thanks to the discovery of JSOPTION_DONT_REPORT_UNCAUGHT. Also, JS warnings are now converted into Python warnings.
Atul Varma <varmaa@toolness.com>
parents:
23
diff
changeset
|
133 JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_DONT_REPORT_UNCAUGHT | |
3f4982759e55
Converting JS exceptions into Python exceptions is now doable, albeit not yet implemented, thanks to the discovery of JSOPTION_DONT_REPORT_UNCAUGHT. Also, JS warnings are now converted into Python warnings.
Atul Varma <varmaa@toolness.com>
parents:
23
diff
changeset
|
134 JSOPTION_ATLINE | JSOPTION_STRICT); |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
135 JS_SetVersion(cx, JSVERSION_LATEST); |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
136 |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
137 PyObject *retval = (PyObject *) PYM_newJSContextObject(self, cx); |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
138 |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
139 if (retval == NULL) |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
140 JS_DestroyContext(cx); |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
141 |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
142 return retval; |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
143 } |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
144 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
145 static PyMethodDef PYM_JSRuntimeMethods[] = { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
146 {"new_context", (PyCFunction) PYM_newContext, METH_VARARGS, |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
147 "Create a new JavaScript context."}, |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
148 {NULL, NULL, 0, NULL} |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
149 }; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
150 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
151 PyTypeObject PYM_JSRuntimeType = { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
152 PyObject_HEAD_INIT(NULL) |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
153 0, /*ob_size*/ |
173
5cfb47c9e916
Minor line wrap and spacing fixes.
Atul Varma <varmaa@toolness.com>
parents:
170
diff
changeset
|
154 "pydermonkey.Runtime", /*tp_name*/ |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
155 sizeof(PYM_JSRuntimeObject), /*tp_basicsize*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
156 0, /*tp_itemsize*/ |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
129
diff
changeset
|
157 /*tp_dealloc*/ |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
158 (destructor) PYM_JSRuntimeDealloc, |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
159 0, /*tp_print*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
160 0, /*tp_getattr*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
161 0, /*tp_setattr*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
162 0, /*tp_compare*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
163 0, /*tp_repr*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
164 0, /*tp_as_number*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
165 0, /*tp_as_sequence*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
166 0, /*tp_as_mapping*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
167 0, /*tp_hash */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
168 0, /*tp_call*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
169 0, /*tp_str*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
170 0, /*tp_getattro*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
171 0, /*tp_setattro*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
172 0, /*tp_as_buffer*/ |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
129
diff
changeset
|
173 /*tp_flags*/ |
129
7b7a23615873
Added weakref support for runtimes.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
174 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
129
diff
changeset
|
175 /* tp_doc */ |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
176 "JavaScript Runtime.", |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
129
diff
changeset
|
177 0, /* tp_traverse */ |
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
129
diff
changeset
|
178 0, /* tp_clear */ |
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
129
diff
changeset
|
179 0, /* tp_richcompare */ |
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
129
diff
changeset
|
180 /* tp_weaklistoffset */ |
129
7b7a23615873
Added weakref support for runtimes.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
181 offsetof(PYM_JSRuntimeObject, weakrefs), |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
129
diff
changeset
|
182 0, /* tp_iter */ |
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
129
diff
changeset
|
183 0, /* tp_iternext */ |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
184 PYM_JSRuntimeMethods, /* tp_methods */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
185 0, /* tp_members */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
186 0, /* tp_getset */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
187 0, /* tp_base */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
188 0, /* tp_dict */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
189 0, /* tp_descr_get */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
190 0, /* tp_descr_set */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
191 0, /* tp_dictoffset */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
192 0, /* tp_init */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
193 0, /* tp_alloc */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
194 PYM_JSRuntimeNew, /* tp_new */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
195 }; |