annotate context.c @ 38:6cd870a2b81e

If the JS engine supports GC zeal setting, we enable it automatically to help find any memory management bugs.
author Atul Varma <varmaa@toolness.com>
date Thu, 02 Jul 2009 22:56:59 -0700
parents d4efcbb06964
children 8a7abd0bb48d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
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
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
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
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
27 static PyObject *
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
28 PYM_newObject(PYM_JSContextObject *self, PyObject *args)
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
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
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
32 PyErr_SetString(PYM_error, "JS_NewObject() failed");
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
33 return NULL;
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
34 }
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
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
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
39 }
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
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
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
138 if (PYM_pyObjectToJsval(self->cx, value, &jsValue) == -1)
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 *
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
154 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
155 {
74b7ad049542 Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
156 PyObject *callable;
74b7ad049542 Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
157 const char *name;
74b7ad049542 Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
158
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
159 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
160 return NULL;
74b7ad049542 Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
161
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
162 return (PyObject *) PYM_newJSFunction(self, callable, name);
24
74b7ad049542 Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
163 }
74b7ad049542 Added very primitive support for calling python functions from JS.
Atul Varma <varmaa@toolness.com>
parents: 21
diff changeset
164
11
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
165 static PyMethodDef PYM_JSContextMethods[] = {
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
166 {"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
167 "Get the JavaScript runtime associated with this context."},
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
168 {"new_object", (PyCFunction) PYM_newObject, METH_VARARGS,
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 12
diff changeset
169 "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
170 {"init_standard_classes",
9edcdb4ab12d added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents: 13
diff changeset
171 (PyCFunction) PYM_initStandardClasses, METH_VARARGS,
9edcdb4ab12d added an init_standard_classes() method to context objects.
Atul Varma <varmaa@toolness.com>
parents: 13
diff changeset
172 "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
173 {"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
174 (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
175 "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
176 "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
177 "and line number information."},
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
178 {"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
179 (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
180 "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
181 {"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
182 (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
183 "Defines a property on an object."},
17
0812422ec99e Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents: 16
diff changeset
184 {"get_property", (PyCFunction) PYM_getProperty, METH_VARARGS,
0812422ec99e Added a context.get_property() method.
Atul Varma <varmaa@toolness.com>
parents: 16
diff changeset
185 "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
186 {NULL, NULL, 0, NULL}
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
187 };
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
188
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
189 PyTypeObject PYM_JSContextType = {
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
190 PyObject_HEAD_INIT(NULL)
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
191 0, /*ob_size*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
192 "pymonkey.Context", /*tp_name*/
12
6d95cfaa1e0b Fixed a code typo.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
193 sizeof(PYM_JSContextObject), /*tp_basicsize*/
11
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
194 0, /*tp_itemsize*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
195 /*tp_dealloc*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
196 (destructor) PYM_JSContextDealloc,
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
197 0, /*tp_print*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
198 0, /*tp_getattr*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
199 0, /*tp_setattr*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
200 0, /*tp_compare*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
201 0, /*tp_repr*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
202 0, /*tp_as_number*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
203 0, /*tp_as_sequence*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
204 0, /*tp_as_mapping*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
205 0, /*tp_hash */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
206 0, /*tp_call*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
207 0, /*tp_str*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
208 0, /*tp_getattro*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
209 0, /*tp_setattro*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
210 0, /*tp_as_buffer*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
211 Py_TPFLAGS_DEFAULT, /*tp_flags*/
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
212 /* tp_doc */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
213 "JavaScript Context.",
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
214 0, /* tp_traverse */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
215 0, /* tp_clear */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
216 0, /* tp_richcompare */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
217 0, /* tp_weaklistoffset */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
218 0, /* tp_iter */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
219 0, /* tp_iternext */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
220 PYM_JSContextMethods, /* tp_methods */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
221 0, /* tp_members */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
222 0, /* tp_getset */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
223 0, /* tp_base */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
224 0, /* tp_dict */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
225 0, /* tp_descr_get */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
226 0, /* tp_descr_set */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
227 0, /* tp_dictoffset */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
228 0, /* tp_init */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
229 0, /* tp_alloc */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
230 0, /* tp_new */
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
231 };
19
fbb9a61fa030 Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
232
fbb9a61fa030 Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
233 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
234 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
235 {
fbb9a61fa030 Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
236 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
237 &PYM_JSContextType);
fbb9a61fa030 Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
238 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
239 return NULL;
fbb9a61fa030 Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
240
fbb9a61fa030 Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
241 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
242 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
243
fbb9a61fa030 Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
244 context->cx = cx;
fbb9a61fa030 Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
245
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
246 #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
247 // 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
248 // 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
249 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
250 #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
251
19
fbb9a61fa030 Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
252 return context;
fbb9a61fa030 Moved context creation code into its own public function in context.c.
Atul Varma <varmaa@toolness.com>
parents: 18
diff changeset
253 }