Mercurial > pymonkey
annotate context.c @ 44:0b9a316ce4ef
Changed function signature of PYM_pyObjectToJsval() to be consistent w/ the rest of the API.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 05 Jul 2009 23:55:42 -0700 |
parents | 5727675b1bcb |
children | a0f677cfc679 |
rev | line source |
---|---|
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
1 #include "context.h" |
13 | 2 #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
|
3 #include "function.h" |
13 | 4 #include "utils.h" |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
5 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
6 static void |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
7 PYM_JSContextDealloc(PYM_JSContextObject *self) |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
8 { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
9 if (self->cx) { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
10 JS_DestroyContext(self->cx); |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
11 self->cx = NULL; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
12 } |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
13 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
14 Py_DECREF(self->runtime); |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
15 self->runtime = NULL; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
16 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
17 self->ob_type->tp_free((PyObject *) self); |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
18 } |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
19 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
20 static PyObject * |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
21 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
|
22 { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
23 Py_INCREF(self->runtime); |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
24 return (PyObject *) self->runtime; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
25 } |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
26 |
13 | 27 static PyObject * |
28 PYM_newObject(PYM_JSContextObject *self, PyObject *args) | |
29 { | |
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
|
30 JSObject *obj = JS_NewObject(self->cx, &PYM_JS_ObjectClass, NULL, NULL); |
f3223debd70b
Refactoring; moved PYM_JSObject creation code into a new public function in object.c.
Atul Varma <varmaa@toolness.com>
parents:
17
diff
changeset
|
31 if (obj == NULL) { |
13 | 32 PyErr_SetString(PYM_error, "JS_NewObject() failed"); |
33 return NULL; | |
34 } | |
35 | |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
36 // 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
|
37 // 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
|
38 return (PyObject *) PYM_newJSObject(self, obj, NULL); |
13 | 39 } |
40 | |
14
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
41 static PyObject * |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
42 PYM_getProperty(PYM_JSContextObject *self, PyObject *args) |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
43 { |
29
608d086d12e3
Added a new PYM_pyObjectToJsval() function that only supports unicode for the moment. Also, whereever we're assuming that Py_UNICODE is UCS-2, we're surrounding such code with #ifndef Py_UNICODE_WIDE.
Atul Varma <varmaa@toolness.com>
parents:
27
diff
changeset
|
44 #ifndef Py_UNICODE_WIDE |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
45 PYM_JSObject *object; |
27
21045074139f
Based on my new understanding of JSString */jschar * thanks to folks on #jsapi, I've removed the requirement that SpiderMonkey be in UTF-8 mode to translate strings between Python and SpiderMonkey.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
46 Py_UNICODE *string; |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
47 |
27
21045074139f
Based on my new understanding of JSString */jschar * thanks to folks on #jsapi, I've removed the requirement that SpiderMonkey be in UTF-8 mode to translate strings between Python and SpiderMonkey.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
48 if (!PyArg_ParseTuple(args, "O!u", &PYM_JSObjectType, &object, |
21045074139f
Based on my new understanding of JSString */jschar * thanks to folks on #jsapi, I've removed the requirement that SpiderMonkey be in UTF-8 mode to translate strings between Python and SpiderMonkey.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
49 &string)) |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
50 return NULL; |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
51 |
27
21045074139f
Based on my new understanding of JSString */jschar * thanks to folks on #jsapi, I've removed the requirement that SpiderMonkey be in UTF-8 mode to translate strings between Python and SpiderMonkey.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
52 JSString *jsString = JS_NewUCStringCopyZ(self->cx, |
21045074139f
Based on my new understanding of JSString */jschar * thanks to folks on #jsapi, I've removed the requirement that SpiderMonkey be in UTF-8 mode to translate strings between Python and SpiderMonkey.
Atul Varma <varmaa@toolness.com>
parents:
24
diff
changeset
|
53 (const jschar *) string); |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
54 if (jsString == NULL) { |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
55 PyErr_SetString(PYM_error, "JS_NewStringCopyZ() failed"); |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
56 return NULL; |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
57 } |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
58 |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
59 jsval val; |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
60 if (!JS_GetUCProperty(self->cx, object->obj, |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
61 JS_GetStringChars(jsString), |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
62 JS_GetStringLength(jsString), &val)) { |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
63 // TODO: Get the actual JS exception. Any exception that exists |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
64 // here will probably still be pending on the JS context. |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
65 PyErr_SetString(PYM_error, "Getting property failed."); |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
66 return NULL; |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
67 } |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
68 |
21
fc04e5f1c675
Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents:
20
diff
changeset
|
69 return PYM_jsvalToPyObject(self, val); |
29
608d086d12e3
Added a new PYM_pyObjectToJsval() function that only supports unicode for the moment. Also, whereever we're assuming that Py_UNICODE is UCS-2, we're surrounding such code with #ifndef Py_UNICODE_WIDE.
Atul Varma <varmaa@toolness.com>
parents:
27
diff
changeset
|
70 #else |
608d086d12e3
Added a new PYM_pyObjectToJsval() function that only supports unicode for the moment. Also, whereever we're assuming that Py_UNICODE is UCS-2, we're surrounding such code with #ifndef Py_UNICODE_WIDE.
Atul Varma <varmaa@toolness.com>
parents:
27
diff
changeset
|
71 PyErr_SetString(PyExc_NotImplementedError, |
608d086d12e3
Added a new PYM_pyObjectToJsval() function that only supports unicode for the moment. Also, whereever we're assuming that Py_UNICODE is UCS-2, we're surrounding such code with #ifndef Py_UNICODE_WIDE.
Atul Varma <varmaa@toolness.com>
parents:
27
diff
changeset
|
72 "This function is not yet implemented for wide " |
608d086d12e3
Added a new PYM_pyObjectToJsval() function that only supports unicode for the moment. Also, whereever we're assuming that Py_UNICODE is UCS-2, we're surrounding such code with #ifndef Py_UNICODE_WIDE.
Atul Varma <varmaa@toolness.com>
parents:
27
diff
changeset
|
73 "unicode builds of Python."); |
608d086d12e3
Added a new PYM_pyObjectToJsval() function that only supports unicode for the moment. Also, whereever we're assuming that Py_UNICODE is UCS-2, we're surrounding such code with #ifndef Py_UNICODE_WIDE.
Atul Varma <varmaa@toolness.com>
parents:
27
diff
changeset
|
74 return NULL; |
608d086d12e3
Added a new PYM_pyObjectToJsval() function that only supports unicode for the moment. Also, whereever we're assuming that Py_UNICODE is UCS-2, we're surrounding such code with #ifndef Py_UNICODE_WIDE.
Atul Varma <varmaa@toolness.com>
parents:
27
diff
changeset
|
75 #endif |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
76 } |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
77 |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
78 static PyObject * |
14
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
79 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
|
80 { |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
81 PYM_JSObject *object; |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
82 |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
83 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
|
84 return NULL; |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
85 |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
86 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
|
87 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
|
88 return NULL; |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
89 } |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
90 |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
91 Py_RETURN_NONE; |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
92 } |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
93 |
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
|
94 static PyObject * |
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
|
95 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
|
96 { |
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
|
97 PYM_JSObject *object; |
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
|
98 const char *source; |
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
|
99 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
|
100 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
|
101 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
|
102 |
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
|
103 if (!PyArg_ParseTuple(args, "O!s#si", &PYM_JSObjectType, &object, |
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
|
104 &source, &sourceLen, &filename, &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
|
105 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
|
106 |
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
|
107 JS_BeginRequest(self->cx); |
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
|
108 |
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
|
109 jsval rval; |
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
|
110 if (!JS_EvaluateScript(self->cx, object->obj, source, 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
|
111 filename, lineNo, &rval)) { |
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
|
112 // TODO: Actually get the error that was raised. |
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
|
113 PyErr_SetString(PYM_error, "Script failed"); |
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
|
114 JS_EndRequest(self->cx); |
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
|
115 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
|
116 } |
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
|
117 |
21
fc04e5f1c675
Changed object constructor to take a context instead of a runtime.
Atul Varma <varmaa@toolness.com>
parents:
20
diff
changeset
|
118 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
|
119 |
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
|
120 JS_EndRequest(self->cx); |
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
|
121 |
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
|
122 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
|
123 } |
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
|
124 |
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
|
125 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
|
126 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
|
127 { |
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
|
128 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
|
129 PyObject *value; |
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
|
130 const char *name; |
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
|
131 |
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
|
132 if (!PyArg_ParseTuple(args, "O!sO", &PYM_JSObjectType, &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
|
133 &name, &value)) |
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
|
134 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
|
135 |
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
|
136 jsval jsValue; |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
137 |
44
0b9a316ce4ef
Changed function signature of PYM_pyObjectToJsval() to be consistent w/ the rest of the API.
Atul Varma <varmaa@toolness.com>
parents:
43
diff
changeset
|
138 if (PYM_pyObjectToJsval(self, value, &jsValue) == -1) |
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
|
139 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
|
140 |
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
|
141 // TODO: Support unicode naming. |
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
|
142 if (!JS_DefineProperty(self->cx, object->obj, name, jsValue, |
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
|
143 NULL, NULL, JSPROP_ENUMERATE)) { |
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
|
144 // 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
|
145 // 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
|
146 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
|
147 return NULL; |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
148 } |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
149 |
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
|
150 Py_RETURN_NONE; |
24
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
151 } |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
152 |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
153 static PyObject * |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
154 PYM_callFunction(PYM_JSContextObject *self, PyObject *args) |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
155 { |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
156 PYM_JSObject *obj; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
157 PYM_JSFunction *fun; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
158 PyObject *funcArgs; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
159 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
160 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
|
161 &PYM_JSFunctionType, &fun, |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
162 &PyTuple_Type, &funcArgs)) |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
163 return NULL; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
164 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
165 uintN argc = PyTuple_Size(funcArgs); |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
166 jsval argv[argc]; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
167 jsval *currArg = argv; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
168 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
169 for (unsigned int i = 0; i < argc; i++) { |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
170 PyObject *item = PyTuple_GET_ITEM(funcArgs, i); |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
171 if (item == NULL || |
44
0b9a316ce4ef
Changed function signature of PYM_pyObjectToJsval() to be consistent w/ the rest of the API.
Atul Varma <varmaa@toolness.com>
parents:
43
diff
changeset
|
172 PYM_pyObjectToJsval(self, item, currArg) == -1) |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
173 return NULL; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
174 currArg++; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
175 } |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
176 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
177 jsval rval; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
178 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
179 // TODO: This assumes that a JSFunction * is actually a subclass of |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
180 // a JSObject *, which may or may not be regarded as an implementation |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
181 // detail. |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
182 if (!JS_CallFunction(self->cx, obj->obj, (JSFunction *) fun->base.obj, |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
183 argc, argv, &rval)) { |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
184 // TODO: There's a pending exception on the JS context, should we |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
185 // do something about it? |
42 | 186 |
187 // TODO: Convert the JS exception to a Python one. | |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
188 PyErr_SetString(PYM_error, "Function failed"); |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
189 return NULL; |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
190 } |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
191 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
192 return PYM_jsvalToPyObject(self, rval); |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
193 } |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
194 |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
195 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
|
196 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
|
197 { |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
198 PyObject *callable; |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
199 const char *name; |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
200 |
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
|
201 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
|
202 return NULL; |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
203 |
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
|
204 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
|
205 } |
74b7ad049542
Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents:
21
diff
changeset
|
206 |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
207 static PyMethodDef PYM_JSContextMethods[] = { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
208 {"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
|
209 "Get the JavaScript runtime associated with this context."}, |
13 | 210 {"new_object", (PyCFunction) PYM_newObject, METH_VARARGS, |
211 "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
|
212 {"init_standard_classes", |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
213 (PyCFunction) PYM_initStandardClasses, METH_VARARGS, |
9edcdb4ab12d
added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents:
13
diff
changeset
|
214 "Add standard classes and functions to the given 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
|
215 {"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
|
216 (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
|
217 "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
|
218 "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
|
219 "and line number information."}, |
41
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
220 {"call_function", |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
221 (PyCFunction) PYM_callFunction, METH_VARARGS, |
71ab5e977dd3
Added a context.call_function() method.
Atul Varma <varmaa@toolness.com>
parents:
40
diff
changeset
|
222 "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
|
223 {"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
|
224 (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
|
225 "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
|
226 {"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
|
227 (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
|
228 "Defines a property on an object."}, |
17
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
229 {"get_property", (PyCFunction) PYM_getProperty, METH_VARARGS, |
0812422ec99e
Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents:
16
diff
changeset
|
230 "Gets the given property for the given JavaScript object."}, |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
231 {NULL, NULL, 0, NULL} |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
232 }; |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
233 |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
234 PyTypeObject PYM_JSContextType = { |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
235 PyObject_HEAD_INIT(NULL) |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
236 0, /*ob_size*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
237 "pymonkey.Context", /*tp_name*/ |
12 | 238 sizeof(PYM_JSContextObject), /*tp_basicsize*/ |
11
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
239 0, /*tp_itemsize*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
240 /*tp_dealloc*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
241 (destructor) PYM_JSContextDealloc, |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
242 0, /*tp_print*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
243 0, /*tp_getattr*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
244 0, /*tp_setattr*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
245 0, /*tp_compare*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
246 0, /*tp_repr*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
247 0, /*tp_as_number*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
248 0, /*tp_as_sequence*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
249 0, /*tp_as_mapping*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
250 0, /*tp_hash */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
251 0, /*tp_call*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
252 0, /*tp_str*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
253 0, /*tp_getattro*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
254 0, /*tp_setattro*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
255 0, /*tp_as_buffer*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
256 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
257 /* tp_doc */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
258 "JavaScript Context.", |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
259 0, /* tp_traverse */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
260 0, /* tp_clear */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
261 0, /* tp_richcompare */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
262 0, /* tp_weaklistoffset */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
263 0, /* tp_iter */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
264 0, /* tp_iternext */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
265 PYM_JSContextMethods, /* tp_methods */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
266 0, /* tp_members */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
267 0, /* tp_getset */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
268 0, /* tp_base */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
269 0, /* tp_dict */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
270 0, /* tp_descr_get */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
271 0, /* tp_descr_set */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
272 0, /* tp_dictoffset */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
273 0, /* tp_init */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
274 0, /* tp_alloc */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
275 0, /* tp_new */ |
551ba05fe6ad
factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff
changeset
|
276 }; |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
277 |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
278 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
|
279 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
|
280 { |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
281 PYM_JSContextObject *context = PyObject_New(PYM_JSContextObject, |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
282 &PYM_JSContextType); |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
283 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
|
284 return NULL; |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
285 |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
286 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
|
287 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
|
288 |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
289 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
|
290 JS_SetContextPrivate(cx, context); |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
291 |
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
|
292 #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
|
293 // 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
|
294 // 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
|
295 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
|
296 #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
|
297 |
19
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
298 return context; |
fbb9a61fa030
Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents:
18
diff
changeset
|
299 } |