annotate src/pydermonkey.cpp @ 173:5cfb47c9e916 default tip

Minor line wrap and spacing fixes.
author Atul Varma <varmaa@toolness.com>
date Tue, 01 Sep 2009 03:22:33 -0700
parents dd32a92f6b4f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
1 /* ***** BEGIN LICENSE BLOCK *****
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
3 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
4 * The contents of this file are subject to the Mozilla Public License Version
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
5 * 1.1 (the "License"); you may not use this file except in compliance with
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
6 * the License. You may obtain a copy of the License at
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
7 * http://www.mozilla.org/MPL/
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
8 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
9 * Software distributed under the License is distributed on an "AS IS" basis,
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
11 * for the specific language governing rights and limitations under the
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
12 * License.
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
13 *
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 151
diff changeset
14 * The Original Code is Pydermonkey.
48
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
15 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
16 * The Initial Developer of the Original Code is Mozilla.
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
17 * Portions created by the Initial Developer are Copyright (C) 2007
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
18 * the Initial Developer. All Rights Reserved.
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
19 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
20 * Contributor(s):
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
21 * Atul Varma <atul@mozilla.com>
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
22 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
23 * Alternatively, the contents of this file may be used under the terms of
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
26 * in which case the provisions of the GPL or the LGPL are applicable instead
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
27 * of those above. If you wish to allow use of your version of this file only
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
28 * under the terms of either the GPL or the LGPL, and not to allow others to
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
29 * use your version of this file under the terms of the MPL, indicate your
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
30 * decision by deleting the provisions above and replace them with the notice
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
31 * and other provisions required by the GPL or the LGPL. If you do not delete
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
32 * the provisions above, a recipient may use your version of this file under
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
33 * the terms of any one of the MPL, the GPL or the LGPL.
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
34 *
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
35 * ***** END LICENSE BLOCK ***** */
bc4263c6ae82 Added license blocks to all .c/.h files.
Atul Varma <varmaa@toolness.com>
parents: 37
diff changeset
36
10
29eaa1fceff1 Moved definition of undefined type into a separate module.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
37 #include "undefined.h"
11
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents: 10
diff changeset
38 #include "runtime.h"
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents: 10
diff changeset
39 #include "context.h"
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
40 #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: 27
diff changeset
41 #include "function.h"
136
b4e216d06e83 Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents: 117
diff changeset
42 #include "script.h"
11
551ba05fe6ad factored out Runtime, Context, and utils into separate files.
Atul Varma <varmaa@toolness.com>
parents: 10
diff changeset
43 #include "utils.h"
8
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
44
151
657afb7307eb Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
45 static PyObject *
657afb7307eb Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
46 PYM_getDebugInfo(PyObject *self, PyObject *args)
657afb7307eb Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
47 {
657afb7307eb Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
48 PyObject *info = Py_BuildValue("{sI}",
657afb7307eb Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
49 "runtime_count", PYM_getJSRuntimeCount());
657afb7307eb Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
50 return info;
657afb7307eb Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
51 }
657afb7307eb Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
52
0
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
53 static PyMethodDef PYM_methods[] = {
151
657afb7307eb Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
54 {"get_debug_info", PYM_getDebugInfo, METH_VARARGS,
657afb7307eb Added a pymonkey.get_debug_info() function and used it on test teardown to ensure that unit tests don't leak.
Atul Varma <varmaa@toolness.com>
parents: 136
diff changeset
55 "Get debugging information about the module."},
0
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
56 {NULL, NULL, 0, NULL}
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
57 };
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
58
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
59 PyMODINIT_FUNC
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 151
diff changeset
60 initpydermonkey(void)
0
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
61 {
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
62 PyObject *module;
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
63
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 151
diff changeset
64 module = Py_InitModule("pydermonkey", PYM_methods);
0
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
65 if (module == NULL)
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
66 return;
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
67
8
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
68 if (PyType_Ready(&PYM_undefinedType) < 0)
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
69 return;
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
70
57
a2b617731398 pymonkey.undefined now has a 'falsy' value.
Atul Varma <varmaa@toolness.com>
parents: 48
diff changeset
71 PYM_undefined = PyObject_New(PYM_undefinedObject, &PYM_undefinedType);
a2b617731398 pymonkey.undefined now has a 'falsy' value.
Atul Varma <varmaa@toolness.com>
parents: 48
diff changeset
72 if (PYM_undefined == NULL)
a2b617731398 pymonkey.undefined now has a 'falsy' value.
Atul Varma <varmaa@toolness.com>
parents: 48
diff changeset
73 return;
8
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
74 Py_INCREF(PYM_undefined);
57
a2b617731398 pymonkey.undefined now has a 'falsy' value.
Atul Varma <varmaa@toolness.com>
parents: 48
diff changeset
75 PyModule_AddObject(module, "undefined", (PyObject *) PYM_undefined);
8
6647870380cc Added support for undefined.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
76
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 151
diff changeset
77 PYM_error = PyErr_NewException("pydermonkey.error", NULL, NULL);
0
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
78 Py_INCREF(PYM_error);
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
79 PyModule_AddObject(module, "error", PYM_error);
9
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
80
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
81 if (!PyType_Ready(&PYM_JSRuntimeType) < 0)
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
82 return;
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
83
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
84 Py_INCREF(&PYM_JSRuntimeType);
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
85 PyModule_AddObject(module, "Runtime", (PyObject *) &PYM_JSRuntimeType);
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
86
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
87 if (!PyType_Ready(&PYM_JSContextType) < 0)
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
88 return;
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
89
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
90 Py_INCREF(&PYM_JSContextType);
032cfc448079 Added pymonkey.Runtime and pymonkey.Context as new types.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
91 PyModule_AddObject(module, "Context", (PyObject *) &PYM_JSContextType);
13
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
92
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
93 if (!PyType_Ready(&PYM_JSObjectType) < 0)
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
94 return;
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
95
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
96 Py_INCREF(&PYM_JSObjectType);
ca17531e8c81 Added an object class.
Atul Varma <varmaa@toolness.com>
parents: 11
diff changeset
97 PyModule_AddObject(module, "Object", (PyObject *) &PYM_JSObjectType);
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: 27
diff changeset
98
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: 27
diff changeset
99 PYM_JSFunctionType.tp_base = &PYM_JSObjectType;
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: 27
diff changeset
100 if (!PyType_Ready(&PYM_JSFunctionType) < 0)
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: 27
diff changeset
101 return;
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: 27
diff changeset
102
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: 27
diff changeset
103 Py_INCREF(&PYM_JSFunctionType);
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: 27
diff changeset
104 PyModule_AddObject(module, "Function", (PyObject *) &PYM_JSFunctionType);
136
b4e216d06e83 Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents: 117
diff changeset
105
b4e216d06e83 Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents: 117
diff changeset
106 PYM_JSScriptType.tp_base = &PYM_JSObjectType;
b4e216d06e83 Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents: 117
diff changeset
107 if (!PyType_Ready(&PYM_JSScriptType) < 0)
b4e216d06e83 Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents: 117
diff changeset
108 return;
b4e216d06e83 Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents: 117
diff changeset
109
b4e216d06e83 Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents: 117
diff changeset
110 Py_INCREF(&PYM_JSScriptType);
b4e216d06e83 Added pymonkey.Script, which wraps a JSScript object, and context.compile_script()/execute_script().
Atul Varma <varmaa@toolness.com>
parents: 117
diff changeset
111 PyModule_AddObject(module, "Script", (PyObject *) &PYM_JSScriptType);
0
21aa6e3abb49 Origination.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
112 }