Mercurial > pymonkey
annotate src/context.cpp @ 152:80463c8c7930
Added a 'name' property to function obects. Fixed a TODO.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sat, 29 Aug 2009 22:46:48 -0700 |
parents | 9ac6adc6304b |
children | b0c9d6884da3 |
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 * |
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
14 * The Original Code is Pymonkey. |
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 "context.h" |
13 | 38 #include "object.h" |
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:
33
diff
changeset
|
39 #include "function.h" |
136
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
40 #include "script.h" |
13 | 41 #include "utils.h" |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
42 |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
43 #include "jsdbgapi.h" |
146
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
44 #include "jsscript.h" |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
45 |
67 | 46 // This is the default JSOperationCallback for pymonkey-owned JS contexts, |
47 // when they've defined one in Python. | |
64
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
48 static JSBool |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
49 PYM_operationCallback(JSContext *cx) |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
50 { |
66
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
51 PYM_PyAutoEnsureGIL gil; |
64
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
52 PYM_JSContextObject *context = (PYM_JSContextObject *) |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
53 JS_GetContextPrivate(cx); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
54 |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
55 PyObject *callable = context->opCallback; |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
56 PyObject *args = PyTuple_Pack(1, (PyObject *) context); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
57 if (args == NULL) { |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
58 JS_ReportOutOfMemory(cx); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
59 return JS_FALSE; |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
60 } |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
61 PyObject *result = PyObject_Call(callable, args, NULL); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
62 Py_DECREF(args); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
63 if (result == NULL) { |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
64 PYM_pythonExceptionToJs(context); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
65 return JS_FALSE; |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
66 } |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
67 |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
68 Py_DECREF(result); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
69 return JS_TRUE; |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
70 } |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
71 |
48
bc4263c6ae82
Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents:
47
diff
changeset
|
72 // This is the default JSErrorReporter for pymonkey-owned JS contexts. |
46
a0f677cfc679
Added basic functionality for passing useful exceptions between Python and JS code.
Atul Varma <varmaa@toolness.com>
parents:
44
diff
changeset
|
73 static void |
a0f677cfc679
Added basic functionality for passing useful exceptions between Python and JS code.
Atul Varma <varmaa@toolness.com>
parents:
44
diff
changeset
|
74 PYM_reportError(JSContext *cx, const char *message, JSErrorReport *report) |
a0f677cfc679
Added basic functionality for passing useful exceptions between Python and JS code.
Atul Varma <varmaa@toolness.com>
parents:
44
diff
changeset
|
75 { |
66
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
76 PYM_PyAutoEnsureGIL gil; |
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
77 |
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:
46
diff
changeset
|
78 // Convert JS warnings into Python warnings. |
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:
46
diff
changeset
|
79 if (JSREPORT_IS_WARNING(report->flags)) { |
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:
46
diff
changeset
|
80 if (report->filename) |
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:
46
diff
changeset
|
81 PyErr_WarnExplicit(NULL, message, report->filename, report->lineno, |
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:
46
diff
changeset
|
82 NULL, NULL); |
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:
46
diff
changeset
|
83 else |
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:
46
diff
changeset
|
84 PyErr_Warn(NULL, message); |
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:
46
diff
changeset
|
85 } else |
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:
46
diff
changeset
|
86 // TODO: Not sure if this will ever get called, but we should know |
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:
46
diff
changeset
|
87 // if it is. |
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:
46
diff
changeset
|
88 PyErr_Warn(NULL, "A JS error was reported."); |
46
a0f677cfc679
Added basic functionality for passing useful exceptions between Python and JS code.
Atul Varma <varmaa@toolness.com>
parents:
44
diff
changeset
|
89 } |
a0f677cfc679
Added basic functionality for passing useful exceptions between Python and JS code.
Atul Varma <varmaa@toolness.com>
parents:
44
diff
changeset
|
90 |
125
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
91 static int |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
92 PYM_traverse(PYM_JSContextObject *self, visitproc visit, void *arg) |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
93 { |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
94 Py_VISIT(self->opCallback); |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
95 Py_VISIT(self->runtime); |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
96 return 0; |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
97 } |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
98 |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
99 static int |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
100 PYM_clear(PYM_JSContextObject *self) |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
101 { |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
102 Py_CLEAR(self->opCallback); |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
103 Py_CLEAR(self->runtime); |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
104 return 0; |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
105 } |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
106 |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
107 static void |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
108 PYM_JSContextDealloc(PYM_JSContextObject *self) |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
109 { |
126
8371983fee63
Added support for weakrefs to contexts.
Atul Varma <varmaa@toolness.com>
parents:
125
diff
changeset
|
110 if (self->weakrefs) |
8371983fee63
Added support for weakrefs to contexts.
Atul Varma <varmaa@toolness.com>
parents:
125
diff
changeset
|
111 PyObject_ClearWeakRefs((PyObject *) self); |
128
1e4d4d475e75
Fixed GC issues w/ context dealloc.
Atul Varma <varmaa@toolness.com>
parents:
127
diff
changeset
|
112 PyObject_GC_UnTrack(self); |
1e4d4d475e75
Fixed GC issues w/ context dealloc.
Atul Varma <varmaa@toolness.com>
parents:
127
diff
changeset
|
113 |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
114 if (self->cx) { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
115 JS_DestroyContext(self->cx); |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
116 self->cx = NULL; |
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 |
125
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
119 PYM_clear(self); |
128
1e4d4d475e75
Fixed GC issues w/ context dealloc.
Atul Varma <varmaa@toolness.com>
parents:
127
diff
changeset
|
120 PyObject_GC_Del(self); |
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_getRuntime(PYM_JSContextObject *self, PyObject *args) |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
125 { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
126 Py_INCREF(self->runtime); |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
127 return (PyObject *) self->runtime; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
128 } |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
129 |
13 | 130 static PyObject * |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
131 PYM_getStack(PYM_JSContextObject *self, PyObject *args) |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
132 { |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
133 PYM_SANITY_CHECK(self->runtime); |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
134 |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
135 JSStackFrame *iteratorp = NULL; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
136 JSStackFrame *frame; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
137 PyObject *top = NULL; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
138 // This is always a borrowed reference, i.e. we never incref/decref it. |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
139 PyObject *last = NULL; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
140 |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
141 while ((frame = JS_FrameIterator(self->cx, &iteratorp)) != NULL) { |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
142 bool success = true; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
143 JSScript *script = JS_GetFrameScript(self->cx, frame); |
146
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
144 unsigned int pc = 0; |
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
145 unsigned int lineno = 0; |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
146 PyObject *pyScript; |
146
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
147 if (script) { |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
148 pyScript = (PyObject *) PYM_newJSScript(self, script); |
146
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
149 if (pyScript == NULL) |
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
150 return NULL; |
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
151 jsbytecode *pcByte = JS_GetFramePC(self->cx, frame); |
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
152 pc = pcByte - script->code; |
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
153 lineno = JS_PCToLineNumber(self->cx, script, pcByte); |
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
154 } else { |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
155 pyScript = Py_None; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
156 Py_INCREF(pyScript); |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
157 } |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
158 |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
159 PyObject *frameDict = Py_BuildValue( |
149
9ac6adc6304b
'caller' key for base stack frame is now None.
Atul Varma <varmaa@toolness.com>
parents:
147
diff
changeset
|
160 "{sOsIsIsO}", |
146
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
161 "script", pyScript, |
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
162 "pc", pc, |
149
9ac6adc6304b
'caller' key for base stack frame is now None.
Atul Varma <varmaa@toolness.com>
parents:
147
diff
changeset
|
163 "lineno", lineno, |
9ac6adc6304b
'caller' key for base stack frame is now None.
Atul Varma <varmaa@toolness.com>
parents:
147
diff
changeset
|
164 "caller", Py_None |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
165 ); |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
166 |
146
b1cf9decc36f
Added 'lineno' and 'pc' attributes to stack frame information.
Atul Varma <varmaa@toolness.com>
parents:
145
diff
changeset
|
167 Py_DECREF(pyScript); |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
168 |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
169 if (frameDict) { |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
170 if (last) { |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
171 if (PyDict_SetItemString(last, "caller", frameDict) == 0) { |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
172 last = frameDict; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
173 Py_DECREF(frameDict); |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
174 frameDict = NULL; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
175 } else |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
176 success = false; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
177 } else { |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
178 top = frameDict; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
179 last = frameDict; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
180 } |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
181 } else |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
182 success = false; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
183 |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
184 if (!success) { |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
185 Py_XDECREF(top); |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
186 Py_XDECREF(frameDict); |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
187 return NULL; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
188 } |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
189 } |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
190 |
147
ebc0ff767290
Ensure that get_stack() returns None if the stack is empty.
Atul Varma <varmaa@toolness.com>
parents:
146
diff
changeset
|
191 if (top) |
ebc0ff767290
Ensure that get_stack() returns None if the stack is empty.
Atul Varma <varmaa@toolness.com>
parents:
146
diff
changeset
|
192 return top; |
ebc0ff767290
Ensure that get_stack() returns None if the stack is empty.
Atul Varma <varmaa@toolness.com>
parents:
146
diff
changeset
|
193 Py_RETURN_NONE; |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
194 } |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
195 |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
196 static PyObject * |
71
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
197 PYM_getObjectPrivate(PYM_JSContextObject *self, PyObject *args) |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
198 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
199 PYM_SANITY_CHECK(self->runtime); |
71
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
200 PYM_JSObject *object; |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
201 |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
202 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
203 return NULL; |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
204 |
89
e77bc7c799e8
JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
205 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); |
e77bc7c799e8
JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
206 |
84
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
207 JSObject *obj = object->obj; |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
208 |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
209 if (JS_ObjectIsFunction(self->cx, obj)) { |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
210 jsval functionHolder; |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
211 if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) { |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
212 JS_ClearPendingException(self->cx); |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
213 Py_RETURN_NONE; |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
214 } |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
215 if (!JSVAL_IS_OBJECT(functionHolder)) |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
216 Py_RETURN_NONE; |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
217 obj = JSVAL_TO_OBJECT(functionHolder); |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
218 } |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
219 |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
220 JSClass *klass = JS_GET_CLASS(self->cx, obj); |
71
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
221 if (klass != &PYM_JS_ObjectClass) |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
222 Py_RETURN_NONE; |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
223 |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
224 PyObject *pyObject; |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
225 |
84
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
226 if (!PYM_JS_getPrivatePyObject(self->cx, obj, &pyObject)) { |
73 | 227 PYM_jsExceptionToPython(self); |
71
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
228 return NULL; |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
229 } |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
230 |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
231 if (pyObject == NULL) |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
232 pyObject = Py_None; |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
233 |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
234 Py_INCREF(pyObject); |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
235 return pyObject; |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
236 } |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
237 |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
238 static PyObject * |
81
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
239 PYM_clearObjectPrivate(PYM_JSContextObject *self, PyObject *args) |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
240 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
241 PYM_SANITY_CHECK(self->runtime); |
81
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
242 PYM_JSObject *object; |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
243 |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
244 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
245 return NULL; |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
246 |
89
e77bc7c799e8
JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
247 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); |
e77bc7c799e8
JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
248 |
84
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
249 JSObject *obj = object->obj; |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
250 |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
251 if (JS_ObjectIsFunction(self->cx, obj)) { |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
252 jsval functionHolder; |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
253 if (!JS_GetReservedSlot(self->cx, obj, 0, &functionHolder)) { |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
254 JS_ClearPendingException(self->cx); |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
255 Py_RETURN_NONE; |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
256 } |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
257 if (!JSVAL_IS_OBJECT(functionHolder)) |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
258 Py_RETURN_NONE; |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
259 obj = JSVAL_TO_OBJECT(functionHolder); |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
260 } |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
261 |
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
262 JSClass *klass = JS_GET_CLASS(self->cx, obj); |
81
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
263 if (klass != &PYM_JS_ObjectClass) |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
264 Py_RETURN_NONE; |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
265 |
84
10205d88f6ff
JS-wrapped Python functions can now be passed to context.get_object_private() and context.clear_object_private(), which allows cycles to be manually broken from Python. Far from ideal, but easier than writing a cycle collector for now.
Atul Varma <varmaa@toolness.com>
parents:
83
diff
changeset
|
266 if (!PYM_JS_setPrivatePyObject(self->cx, obj, Py_None)) { |
81
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
267 PYM_jsExceptionToPython(self); |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
268 return NULL; |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
269 } |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
270 |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
271 Py_RETURN_NONE; |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
272 } |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
273 |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
274 static PyObject * |
13 | 275 PYM_newObject(PYM_JSContextObject *self, PyObject *args) |
276 { | |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
277 PYM_SANITY_CHECK(self->runtime); |
71
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
278 PyObject *privateObj = NULL; |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
279 |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
280 if (!PyArg_ParseTuple(args, "|O", &privateObj)) |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
281 return NULL; |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
282 |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
283 JSObject *obj = PYM_JS_newObject(self->cx, privateObj); |
18
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
17
diff
changeset
|
284 if (obj == NULL) { |
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:
67
diff
changeset
|
285 PyErr_SetString(PYM_error, "PYM_JS_newObject() failed"); |
13 | 286 return NULL; |
287 } | |
288 | |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
289 // If this fails, we don't need to worry about cleaning up |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
290 // obj because it'll get cleaned up at the next GC. |
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:
33
diff
changeset
|
291 return (PyObject *) PYM_newJSObject(self, obj, NULL); |
13 | 292 } |
293 | |
14
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
294 static PyObject * |
133
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
295 PYM_hasProperty(PYM_JSContextObject *self, PyObject *args) |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
296 { |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
297 PYM_SANITY_CHECK(self->runtime); |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
298 PYM_JSObject *object; |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
299 char *buffer = NULL; |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
300 int size; |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
301 |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
302 if (!PyArg_ParseTuple(args, "O!es#", &PYM_JSObjectType, &object, |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
303 "utf-16", &buffer, &size)) |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
304 return NULL; |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
305 |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
306 PYM_UTF16String str(buffer, size); |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
307 |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
308 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
309 |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
310 JSBool hasProperty; |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
311 JSBool result; |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
312 result = JS_HasUCProperty(self->cx, object->obj, str.jsbuffer, |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
313 str.jslen, &hasProperty); |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
314 |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
315 if (!result) { |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
316 PYM_jsExceptionToPython(self); |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
317 return NULL; |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
318 } |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
319 |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
320 if (hasProperty) |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
321 Py_RETURN_TRUE; |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
322 Py_RETURN_FALSE; |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
323 } |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
324 |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
325 static PyObject * |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
326 PYM_getProperty(PYM_JSContextObject *self, PyObject *args) |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
327 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
328 PYM_SANITY_CHECK(self->runtime); |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
329 PYM_JSObject *object; |
91
97d1faf02460
Got rid of Py_UNICODE_WIDE ifdefs.
Atul Varma <varmaa@toolness.com>
parents:
89
diff
changeset
|
330 char *buffer = NULL; |
97d1faf02460
Got rid of Py_UNICODE_WIDE ifdefs.
Atul Varma <varmaa@toolness.com>
parents:
89
diff
changeset
|
331 int size; |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
332 |
91
97d1faf02460
Got rid of Py_UNICODE_WIDE ifdefs.
Atul Varma <varmaa@toolness.com>
parents:
89
diff
changeset
|
333 if (!PyArg_ParseTuple(args, "O!es#", &PYM_JSObjectType, &object, |
97d1faf02460
Got rid of Py_UNICODE_WIDE ifdefs.
Atul Varma <varmaa@toolness.com>
parents:
89
diff
changeset
|
334 "utf-16", &buffer, &size)) |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
335 return NULL; |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
336 |
132
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
337 PYM_UTF16String str(buffer, size); |
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
338 |
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
339 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
340 |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
341 jsval val; |
66
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
342 JSBool result; |
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
343 Py_BEGIN_ALLOW_THREADS; |
132
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
344 result = JS_GetUCProperty(self->cx, object->obj, str.jsbuffer, |
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
345 str.jslen, &val); |
66
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
346 Py_END_ALLOW_THREADS; |
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
347 |
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
348 if (!result) { |
73 | 349 PYM_jsExceptionToPython(self); |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
350 return NULL; |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
351 } |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
352 |
21
fc04e5f1c675
Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents:
20
diff
changeset
|
353 return PYM_jsvalToPyObject(self, val); |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
354 } |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
355 |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
356 static PyObject * |
60
e557d84318a7
Added a gc() method to the context object which performs garbage collection.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
357 PYM_gc(PYM_JSContextObject *self, PyObject *args) |
e557d84318a7
Added a gc() method to the context object which performs garbage collection.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
358 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
359 PYM_SANITY_CHECK(self->runtime); |
60
e557d84318a7
Added a gc() method to the context object which performs garbage collection.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
360 JS_GC(self->cx); |
e557d84318a7
Added a gc() method to the context object which performs garbage collection.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
361 Py_RETURN_NONE; |
e557d84318a7
Added a gc() method to the context object which performs garbage collection.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
362 } |
e557d84318a7
Added a gc() method to the context object which performs garbage collection.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
363 |
e557d84318a7
Added a gc() method to the context object which performs garbage collection.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
364 static PyObject * |
14
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
365 PYM_initStandardClasses(PYM_JSContextObject *self, PyObject *args) |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
366 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
367 PYM_SANITY_CHECK(self->runtime); |
14
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
368 PYM_JSObject *object; |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
369 |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
370 if (!PyArg_ParseTuple(args, "O!", &PYM_JSObjectType, &object)) |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
371 return NULL; |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
372 |
89
e77bc7c799e8
JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
373 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); |
e77bc7c799e8
JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
374 |
14
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
375 if (!JS_InitStandardClasses(self->cx, object->obj)) { |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
376 PyErr_SetString(PYM_error, "JS_InitStandardClasses() failed"); |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
377 return NULL; |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
378 } |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
379 |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
380 Py_RETURN_NONE; |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
381 } |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
382 |
16
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
383 static PyObject * |
136
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
384 PYM_compileScript(PYM_JSContextObject *self, PyObject *args) |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
385 { |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
386 PYM_SANITY_CHECK(self->runtime); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
387 char *source = NULL; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
388 int sourceLen; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
389 const char *filename; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
390 int lineNo; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
391 |
140
ce8099238c01
As per a discussion with jorendorff, it looks like we can pass NULL to compile_script(), since we're not using object principals (and instead just using an object capability model for now).
Atul Varma <varmaa@toolness.com>
parents:
136
diff
changeset
|
392 if (!PyArg_ParseTuple(args, "es#si", "utf-16", &source, &sourceLen, |
ce8099238c01
As per a discussion with jorendorff, it looks like we can pass NULL to compile_script(), since we're not using object principals (and instead just using an object capability model for now).
Atul Varma <varmaa@toolness.com>
parents:
136
diff
changeset
|
393 &filename, &lineNo)) |
136
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
394 return NULL; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
395 |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
396 PYM_UTF16String str(source, sourceLen); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
397 |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
398 JSScript *script; |
140
ce8099238c01
As per a discussion with jorendorff, it looks like we can pass NULL to compile_script(), since we're not using object principals (and instead just using an object capability model for now).
Atul Varma <varmaa@toolness.com>
parents:
136
diff
changeset
|
399 script = JS_CompileUCScript(self->cx, NULL, str.jsbuffer, |
136
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
400 str.jslen, filename, lineNo); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
401 |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
402 if (script == NULL) { |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
403 PYM_jsExceptionToPython(self); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
404 return NULL; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
405 } |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
406 |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
407 // TODO: If this somehow fails, we may have a memory leak if a |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
408 // script object wasn't created for the JSScript. |
136
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
409 return (PyObject *) PYM_newJSScript(self, script); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
410 } |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
411 |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
412 static PyObject * |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
413 PYM_executeScript(PYM_JSContextObject *self, PyObject *args) |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
414 { |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
415 PYM_SANITY_CHECK(self->runtime); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
416 PYM_JSObject *object; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
417 PYM_JSScript *script; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
418 |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
419 if (!PyArg_ParseTuple(args, "O!O!", &PYM_JSObjectType, &object, |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
420 &PYM_JSScriptType, &script)) |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
421 return NULL; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
422 |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
423 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
424 PYM_ENSURE_RUNTIME_MATCH(self->runtime, script->base.runtime); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
425 |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
426 jsval rval; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
427 JSBool result; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
428 Py_BEGIN_ALLOW_THREADS; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
429 result = JS_ExecuteScript(self->cx, object->obj, script->script, &rval); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
430 Py_END_ALLOW_THREADS; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
431 |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
432 if (!result) { |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
433 PYM_jsExceptionToPython(self); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
434 return NULL; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
435 } |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
436 |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
437 PyObject *pyRval = PYM_jsvalToPyObject(self, rval); |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
438 return pyRval; |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
439 } |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
440 |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
441 static PyObject * |
16
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
442 PYM_evaluateScript(PYM_JSContextObject *self, PyObject *args) |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
443 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
444 PYM_SANITY_CHECK(self->runtime); |
16
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
445 PYM_JSObject *object; |
122
5eda03c8e756
context.evaluate_script() can now take unicode code strings.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
446 char *source = NULL; |
16
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
447 int sourceLen; |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
448 const char *filename; |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
449 int lineNo; |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
450 |
122
5eda03c8e756
context.evaluate_script() can now take unicode code strings.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
451 if (!PyArg_ParseTuple(args, "O!es#si", &PYM_JSObjectType, &object, |
5eda03c8e756
context.evaluate_script() can now take unicode code strings.
Atul Varma <varmaa@toolness.com>
parents:
117
diff
changeset
|
452 "utf-16", &source, &sourceLen, &filename, &lineNo)) |
16
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
453 return NULL; |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
454 |
132
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
455 PYM_UTF16String str(source, sourceLen); |
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
456 |
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
457 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); |
89
e77bc7c799e8
JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
458 |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
459 // Instead of calling JS_EvaluateUCScript(), we're going to first |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
460 // compile the script and then execute it. This is because the |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
461 // former function calls JS_DestroyScript() on the script it's |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
462 // created, which prevents e.g. the script object from being |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
463 // extracted during execution and outliving the script's execution. |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
464 |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
465 JSScript *script; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
466 script = JS_CompileUCScript(self->cx, NULL, str.jsbuffer, |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
467 str.jslen, filename, lineNo); |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
468 |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
469 if (script == NULL) { |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
470 PYM_jsExceptionToPython(self); |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
471 return NULL; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
472 } |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
473 |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
474 // TODO: If this somehow fails, we may have a memory leak if a |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
475 // script object wasn't created for the JSScript. |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
476 PYM_JSScript *pyScript = PYM_newJSScript(self, script); |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
477 |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
478 if (pyScript == NULL) { |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
479 PYM_jsExceptionToPython(self); |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
480 return NULL; |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
481 } |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
482 |
16
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
483 jsval rval; |
66
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
484 JSBool result; |
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
485 Py_BEGIN_ALLOW_THREADS; |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
486 result = JS_ExecuteScript(self->cx, object->obj, pyScript->script, &rval); |
66
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
487 Py_END_ALLOW_THREADS; |
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
488 |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
489 Py_DECREF((PyObject *) pyScript); |
66
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
490 if (!result) { |
46
a0f677cfc679
Added basic functionality for passing useful exceptions between Python and JS code.
Atul Varma <varmaa@toolness.com>
parents:
44
diff
changeset
|
491 PYM_jsExceptionToPython(self); |
16
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
492 return NULL; |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
493 } |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
494 |
21
fc04e5f1c675
Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents:
20
diff
changeset
|
495 PyObject *pyRval = PYM_jsvalToPyObject(self, rval); |
16
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
496 return pyRval; |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
497 } |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
498 |
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:
33
diff
changeset
|
499 static PyObject * |
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:
33
diff
changeset
|
500 PYM_defineProperty(PYM_JSContextObject *self, PyObject *args) |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
501 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
502 PYM_SANITY_CHECK(self->runtime); |
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:
33
diff
changeset
|
503 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:
33
diff
changeset
|
504 PyObject *value; |
104
00c1351b3e82
Added support for unicode property names in context.define_property().
Atul Varma <varmaa@toolness.com>
parents:
100
diff
changeset
|
505 char *name = NULL; |
00c1351b3e82
Added support for unicode property names in context.define_property().
Atul Varma <varmaa@toolness.com>
parents:
100
diff
changeset
|
506 int namelen; |
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:
33
diff
changeset
|
507 |
104
00c1351b3e82
Added support for unicode property names in context.define_property().
Atul Varma <varmaa@toolness.com>
parents:
100
diff
changeset
|
508 if (!PyArg_ParseTuple(args, "O!es#O", &PYM_JSObjectType, &object, |
00c1351b3e82
Added support for unicode property names in context.define_property().
Atul Varma <varmaa@toolness.com>
parents:
100
diff
changeset
|
509 "utf-16", &name, &namelen, &value)) |
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:
33
diff
changeset
|
510 return NULL; |
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:
33
diff
changeset
|
511 |
132
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
512 PYM_UTF16String str(name, namelen); |
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:
33
diff
changeset
|
513 jsval jsValue; |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
514 |
132
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
515 PYM_ENSURE_RUNTIME_MATCH(self->runtime, object->runtime); |
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:
33
diff
changeset
|
516 |
132
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
517 if (PYM_pyObjectToJsval(self, value, &jsValue) == -1) |
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
518 return NULL; |
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
519 |
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
520 if (!JS_DefineUCProperty(self->cx, object->obj, str.jsbuffer, |
537cf7deadc9
Added a new PYM_UTF16String C++ class to make calling UC JSAPI functions a little easier and less error-prone.
Atul Varma <varmaa@toolness.com>
parents:
131
diff
changeset
|
521 str.jslen, jsValue, NULL, NULL, |
104
00c1351b3e82
Added support for unicode property names in context.define_property().
Atul Varma <varmaa@toolness.com>
parents:
100
diff
changeset
|
522 JSPROP_ENUMERATE)) { |
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:
33
diff
changeset
|
523 // TODO: There's probably an exception pending on self->cx, |
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:
33
diff
changeset
|
524 // what should we do about it? |
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:
33
diff
changeset
|
525 PyErr_SetString(PYM_error, "JS_DefineProperty() failed"); |
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:
33
diff
changeset
|
526 return NULL; |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
527 } |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
528 |
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:
33
diff
changeset
|
529 Py_RETURN_NONE; |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
530 } |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
531 |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
532 static PyObject * |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
533 PYM_callFunction(PYM_JSContextObject *self, PyObject *args) |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
534 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
535 PYM_SANITY_CHECK(self->runtime); |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
536 PYM_JSObject *obj; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
537 PYM_JSFunction *fun; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
538 PyObject *funcArgs; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
539 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
540 if (!PyArg_ParseTuple(args, "O!O!O!", &PYM_JSObjectType, &obj, |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
541 &PYM_JSFunctionType, &fun, |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
542 &PyTuple_Type, &funcArgs)) |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
543 return NULL; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
544 |
89
e77bc7c799e8
JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
545 PYM_ENSURE_RUNTIME_MATCH(self->runtime, obj->runtime); |
e77bc7c799e8
JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
546 PYM_ENSURE_RUNTIME_MATCH(self->runtime, fun->base.runtime); |
e77bc7c799e8
JS runtime mismatches are now checked for and enforced so they won't cause segfaults.
Atul Varma <varmaa@toolness.com>
parents:
87
diff
changeset
|
547 |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
548 uintN argc = PyTuple_Size(funcArgs); |
100
b3cc704c035e
PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
Atul Varma <varmaa@toolness.com>
parents:
96
diff
changeset
|
549 |
b3cc704c035e
PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
Atul Varma <varmaa@toolness.com>
parents:
96
diff
changeset
|
550 jsval *argv = (jsval *) PyMem_Malloc(sizeof(jsval) * argc); |
b3cc704c035e
PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
Atul Varma <varmaa@toolness.com>
parents:
96
diff
changeset
|
551 if (argv == NULL) |
b3cc704c035e
PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
Atul Varma <varmaa@toolness.com>
parents:
96
diff
changeset
|
552 return PyErr_NoMemory(); |
b3cc704c035e
PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
Atul Varma <varmaa@toolness.com>
parents:
96
diff
changeset
|
553 |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
554 jsval *currArg = argv; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
555 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
556 for (unsigned int i = 0; i < argc; i++) { |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
557 PyObject *item = PyTuple_GET_ITEM(funcArgs, i); |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
558 if (item == NULL || |
100
b3cc704c035e
PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
Atul Varma <varmaa@toolness.com>
parents:
96
diff
changeset
|
559 PYM_pyObjectToJsval(self, item, currArg) == -1) { |
b3cc704c035e
PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
Atul Varma <varmaa@toolness.com>
parents:
96
diff
changeset
|
560 PyMem_Free(argv); |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
561 return NULL; |
100
b3cc704c035e
PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
Atul Varma <varmaa@toolness.com>
parents:
96
diff
changeset
|
562 } |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
563 currArg++; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
564 } |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
565 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
566 jsval rval; |
66
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
567 JSBool result; |
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
568 Py_BEGIN_ALLOW_THREADS; |
152
80463c8c7930
Added a 'name' property to function obects. Fixed a TODO.
Atul Varma <varmaa@toolness.com>
parents:
149
diff
changeset
|
569 result = JS_CallFunctionValue(self->cx, obj->obj, |
80463c8c7930
Added a 'name' property to function obects. Fixed a TODO.
Atul Varma <varmaa@toolness.com>
parents:
149
diff
changeset
|
570 OBJECT_TO_JSVAL(fun->base.obj), |
80463c8c7930
Added a 'name' property to function obects. Fixed a TODO.
Atul Varma <varmaa@toolness.com>
parents:
149
diff
changeset
|
571 argc, argv, &rval); |
66
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
572 Py_END_ALLOW_THREADS; |
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
573 |
100
b3cc704c035e
PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
Atul Varma <varmaa@toolness.com>
parents:
96
diff
changeset
|
574 PyMem_Free(argv); |
b3cc704c035e
PYM_callFunction() now uses PyMem_Malloc() to dynamically allocate space for arguments on the heap, since MSVC doesn't seem to support dynamically-sized arrays on the stack.
Atul Varma <varmaa@toolness.com>
parents:
96
diff
changeset
|
575 |
66
b49180c39d0a
Pymonkey now handles the GIL properly so that Python code can run while JS code does.
Atul Varma <varmaa@toolness.com>
parents:
64
diff
changeset
|
576 if (!result) { |
46
a0f677cfc679
Added basic functionality for passing useful exceptions between Python and JS code.
Atul Varma <varmaa@toolness.com>
parents:
44
diff
changeset
|
577 PYM_jsExceptionToPython(self); |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
578 return NULL; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
579 } |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
580 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
581 return PYM_jsvalToPyObject(self, rval); |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
582 } |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
583 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
584 static PyObject * |
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:
33
diff
changeset
|
585 PYM_newFunction(PYM_JSContextObject *self, PyObject *args) |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
586 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
587 PYM_SANITY_CHECK(self->runtime); |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
588 PyObject *callable; |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
589 const char *name; |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
590 |
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:
33
diff
changeset
|
591 if (!PyArg_ParseTuple(args, "Os", &callable, &name)) |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
592 return NULL; |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
593 |
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:
38
diff
changeset
|
594 return (PyObject *) PYM_newJSFunctionFromCallable(self, callable, name); |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
595 } |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
596 |
64
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
597 static PyObject * |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
598 PYM_setOperationCallback(PYM_JSContextObject *self, PyObject *args) |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
599 { |
87
345d4c0e3dd3
Thread safety exceptions are now properly raised by all relevant pymonkey functions.
Atul Varma <varmaa@toolness.com>
parents:
84
diff
changeset
|
600 PYM_SANITY_CHECK(self->runtime); |
64
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
601 PyObject *callable; |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
602 |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
603 if (!PyArg_ParseTuple(args, "O", &callable)) |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
604 return NULL; |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
605 |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
606 if (!PyCallable_Check(callable)) { |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
607 PyErr_SetString(PyExc_TypeError, "Callable must be callable"); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
608 return NULL; |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
609 } |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
610 |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
611 JS_SetOperationCallback(self->cx, PYM_operationCallback); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
612 |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
613 Py_INCREF(callable); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
614 if (self->opCallback) |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
615 Py_DECREF(self->opCallback); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
616 self->opCallback = callable; |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
617 |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
618 Py_RETURN_NONE; |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
619 } |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
620 |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
621 static PyObject * |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
622 PYM_triggerOperationCallback(PYM_JSContextObject *self, PyObject *args) |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
623 { |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
624 JS_TriggerOperationCallback(self->cx); |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
625 Py_RETURN_NONE; |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
626 } |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
627 |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
628 static PyMethodDef PYM_JSContextMethods[] = { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
629 {"get_runtime", (PyCFunction) PYM_getRuntime, METH_VARARGS, |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
630 "Get the JavaScript runtime associated with this context."}, |
145
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
631 {"get_stack", (PyCFunction) PYM_getStack, METH_VARARGS, |
5d53f6293a81
Added a basic context.get_stack() function.
Atul Varma <varmaa@toolness.com>
parents:
140
diff
changeset
|
632 "Get the current stack for the context."}, |
13 | 633 {"new_object", (PyCFunction) PYM_newObject, METH_VARARGS, |
634 "Create a new JavaScript object."}, | |
14
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
635 {"init_standard_classes", |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
636 (PyCFunction) PYM_initStandardClasses, METH_VARARGS, |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
637 "Add standard classes and functions to the given object."}, |
136
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
638 {"compile_script", |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
639 (PyCFunction) PYM_compileScript, METH_VARARGS, |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
640 "Compile the given JavaScript code using the given filename" |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
641 "and line number information."}, |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
642 {"execute_script", |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
643 (PyCFunction) PYM_executeScript, METH_VARARGS, |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
644 "Execute the given JavaScript script object in the context of " |
b4e216d06e83
Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents:
133
diff
changeset
|
645 "the given global object."}, |
16
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
646 {"evaluate_script", |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
647 (PyCFunction) PYM_evaluateScript, METH_VARARGS, |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
648 "Evaluate the given JavaScript code in the context of the given " |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
649 "global object, using the given filename" |
532b7ddca616
Created a new context.evaluate_script() function, replacing pymonkey.evaluate(). Separated out one of the big unit tests into several.
Atul Varma <varmaa@toolness.com>
parents:
15
diff
changeset
|
650 "and line number information."}, |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
651 {"call_function", |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
652 (PyCFunction) PYM_callFunction, METH_VARARGS, |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
653 "Calls a JS function."}, |
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:
33
diff
changeset
|
654 {"new_function", |
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:
33
diff
changeset
|
655 (PyCFunction) PYM_newFunction, METH_VARARGS, |
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:
33
diff
changeset
|
656 "Creates a new function callable from JS."}, |
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:
33
diff
changeset
|
657 {"define_property", |
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:
33
diff
changeset
|
658 (PyCFunction) PYM_defineProperty, METH_VARARGS, |
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:
33
diff
changeset
|
659 "Defines a property on an object."}, |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
660 {"get_property", (PyCFunction) PYM_getProperty, METH_VARARGS, |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
661 "Gets the given property for the given JavaScript object."}, |
133
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
662 {"has_property", (PyCFunction) PYM_hasProperty, METH_VARARGS, |
a9c0db56e06b
Added a context.has_property() function.
Atul Varma <varmaa@toolness.com>
parents:
132
diff
changeset
|
663 "Returns whether the given JavaScript object has the given property."}, |
60
e557d84318a7
Added a gc() method to the context object which performs garbage collection.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
664 {"gc", (PyCFunction) PYM_gc, METH_VARARGS, |
e557d84318a7
Added a gc() method to the context object which performs garbage collection.
Atul Varma <varmaa@toolness.com>
parents:
48
diff
changeset
|
665 "Performs garbage collection on the context's runtime."}, |
64
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
666 {"set_operation_callback", (PyCFunction) PYM_setOperationCallback, |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
667 METH_VARARGS, |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
668 "Sets the operation callback for the context."}, |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
669 {"trigger_operation_callback", (PyCFunction) PYM_triggerOperationCallback, |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
670 METH_VARARGS, |
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
671 "Triggers the operation callback for the context."}, |
71
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
672 {"get_object_private", (PyCFunction) PYM_getObjectPrivate, METH_VARARGS, |
9b3f4e53e365
Added context.get_object_private() and an optional private object parameter to context.new_object().
Atul Varma <varmaa@toolness.com>
parents:
70
diff
changeset
|
673 "Returns the private Python object stored in the JavaScript object."}, |
81
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
674 {"clear_object_private", (PyCFunction) PYM_clearObjectPrivate, METH_VARARGS, |
99138265d4b9
Added a context.clear_object_private() function.
Atul Varma <varmaa@toolness.com>
parents:
73
diff
changeset
|
675 "Clears any private Python object stored in the JavaScript object."}, |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
676 {NULL, NULL, 0, NULL} |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
677 }; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
678 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
679 PyTypeObject PYM_JSContextType = { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
680 PyObject_HEAD_INIT(NULL) |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
681 0, /*ob_size*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
682 "pymonkey.Context", /*tp_name*/ |
12 | 683 sizeof(PYM_JSContextObject), /*tp_basicsize*/ |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
684 0, /*tp_itemsize*/ |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
685 /*tp_dealloc*/ |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
686 (destructor) PYM_JSContextDealloc, |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
687 0, /*tp_print*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
688 0, /*tp_getattr*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
689 0, /*tp_setattr*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
690 0, /*tp_compare*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
691 0, /*tp_repr*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
692 0, /*tp_as_number*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
693 0, /*tp_as_sequence*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
694 0, /*tp_as_mapping*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
695 0, /*tp_hash */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
696 0, /*tp_call*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
697 0, /*tp_str*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
698 0, /*tp_getattro*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
699 0, /*tp_setattro*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
700 0, /*tp_as_buffer*/ |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
701 /*tp_flags*/ |
126
8371983fee63
Added support for weakrefs to contexts.
Atul Varma <varmaa@toolness.com>
parents:
125
diff
changeset
|
702 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_WEAKREFS, |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
703 /* tp_doc */ |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
704 "JavaScript Context.", |
125
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
705 (traverseproc) PYM_traverse, /* tp_traverse */ |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
706 (inquiry) PYM_clear, /* tp_clear */ |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
707 0, /* tp_richcompare */ |
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
708 /* tp_weaklistoffset */ |
126
8371983fee63
Added support for weakrefs to contexts.
Atul Varma <varmaa@toolness.com>
parents:
125
diff
changeset
|
709 offsetof(PYM_JSContextObject, weakrefs), |
131
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
710 0, /* tp_iter */ |
f956a6dea16c
Minor housekeeping: replaced tabs w/ spaces, got rid of outdated TODOs, etc.
Atul Varma <varmaa@toolness.com>
parents:
128
diff
changeset
|
711 0, /* tp_iternext */ |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
712 PYM_JSContextMethods, /* tp_methods */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
713 0, /* tp_members */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
714 0, /* tp_getset */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
715 0, /* tp_base */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
716 0, /* tp_dict */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
717 0, /* tp_descr_get */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
718 0, /* tp_descr_set */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
719 0, /* tp_dictoffset */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
720 0, /* tp_init */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
721 0, /* tp_alloc */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
722 0, /* tp_new */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
723 }; |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
724 |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
725 extern PYM_JSContextObject * |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
726 PYM_newJSContextObject(PYM_JSRuntimeObject *runtime, JSContext *cx) |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
727 { |
125
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
728 PYM_JSContextObject *context = PyObject_GC_New(PYM_JSContextObject, |
05e18059b5c4
Added cyclic garbage collection support to context objects.
Atul Varma <varmaa@toolness.com>
parents:
122
diff
changeset
|
729 &PYM_JSContextType); |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
730 if (context == NULL) |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
731 return NULL; |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
732 |
126
8371983fee63
Added support for weakrefs to contexts.
Atul Varma <varmaa@toolness.com>
parents:
125
diff
changeset
|
733 context->weakrefs = NULL; |
64
fb7e11dec538
Added context.set_operation_callback() and trigger_operation_callback() methods.
Atul Varma <varmaa@toolness.com>
parents:
60
diff
changeset
|
734 context->opCallback = NULL; |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
735 context->runtime = runtime; |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
736 Py_INCREF(runtime); |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
737 |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
738 context->cx = cx; |
43
5727675b1bcb
JS-wrapped python functions now take a context object as their first parameter.
Atul Varma <varmaa@toolness.com>
parents:
42
diff
changeset
|
739 JS_SetContextPrivate(cx, context); |
46
a0f677cfc679
Added basic functionality for passing useful exceptions between Python and JS code.
Atul Varma <varmaa@toolness.com>
parents:
44
diff
changeset
|
740 JS_SetErrorReporter(cx, PYM_reportError); |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
741 |
38
6cd870a2b81e
If the JS engine supports GC zeal setting, we enable it automatically to help find any memory management bugs.
Atul Varma <varmaa@toolness.com>
parents:
37
diff
changeset
|
742 #ifdef JS_GC_ZEAL |
6cd870a2b81e
If the JS engine supports GC zeal setting, we enable it automatically to help find any memory management bugs.
Atul Varma <varmaa@toolness.com>
parents:
37
diff
changeset
|
743 // TODO: Consider exposing JS_SetGCZeal() to Python instead of |
6cd870a2b81e
If the JS engine supports GC zeal setting, we enable it automatically to help find any memory management bugs.
Atul Varma <varmaa@toolness.com>
parents:
37
diff
changeset
|
744 // hard-coding it here. |
6cd870a2b81e
If the JS engine supports GC zeal setting, we enable it automatically to help find any memory management bugs.
Atul Varma <varmaa@toolness.com>
parents:
37
diff
changeset
|
745 JS_SetGCZeal(cx, 2); |
6cd870a2b81e
If the JS engine supports GC zeal setting, we enable it automatically to help find any memory management bugs.
Atul Varma <varmaa@toolness.com>
parents:
37
diff
changeset
|
746 #endif |
6cd870a2b81e
If the JS engine supports GC zeal setting, we enable it automatically to help find any memory management bugs.
Atul Varma <varmaa@toolness.com>
parents:
37
diff
changeset
|
747 |
127
4179d1e1a75c
Added a test for context cyclic gc support and fixed a bug revealed by it.
Atul Varma <varmaa@toolness.com>
parents:
126
diff
changeset
|
748 PyObject_GC_Track((PyObject *) context); |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
749 return context; |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
750 } |