annotate docs/src/pydermonkey.txt @ 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 478c672348dc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
1 :mod:`pydermonkey` --- Access SpiderMonkey from Python
171
478c672348dc ReST underline/overline fixes.
Atul Varma <varmaa@toolness.com>
parents: 170
diff changeset
2 ======================================================
51
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
3
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
4 .. module:: pydermonkey
51
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
5 :synopsis: Access SpiderMonkey from Python
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
6
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
7 .. testsetup:: *
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
8
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
9 import pydermonkey
51
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
10
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
11 This module offers a low-level interface to the `Mozilla SpiderMonkey
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
12 <https://developer.mozilla.org/en/SpiderMonkey>`_ JavaScript engine.
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
13
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
14 .. exception:: error
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
15
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
16 This is the type of any SpiderMonkey-related errors thrown by this
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
17 module.
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
18
169
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
19 If the error is a wrapped JavaScript exception, the first argument
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
20 will be the thrown JS exception, and the second argument will be
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
21 the JS exception converted to a string. Otherwise, the error
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
22 will only contain a descriptive string argument.
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
23
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
24 For example:
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
25
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
26 >>> cx = pydermonkey.Runtime().new_context()
169
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
27 >>> cx.evaluate_script(cx.new_object(), 'throw 1', '<string>', 1)
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
28 Traceback (most recent call last):
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
29 ...
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
30 error: (1, u'1')
2b98d4643c44 Added more useful docs for pymonkey.error.
Atul Varma <varmaa@toolness.com>
parents: 168
diff changeset
31
54
234fca1c4b86 Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents: 53
diff changeset
32 .. data:: undefined
234fca1c4b86 Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents: 53
diff changeset
33
234fca1c4b86 Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents: 53
diff changeset
34 This is the singleton that represents the JavaScript value
234fca1c4b86 Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents: 53
diff changeset
35 ``undefined``, as Python has no equivalent representation
234fca1c4b86 Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents: 53
diff changeset
36 (JavaScript's ``null`` is mapped to Python's ``None`` object).
234fca1c4b86 Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents: 53
diff changeset
37 For instance:
234fca1c4b86 Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents: 53
diff changeset
38
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
39 >>> cx = pydermonkey.Runtime().new_context()
56
72e84bd75905 Made another doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 55
diff changeset
40 >>> cx.evaluate_script(cx.new_object(), '', '<string>', 1)
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
41 pydermonkey.undefined
54
234fca1c4b86 Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents: 53
diff changeset
42
57
a2b617731398 pymonkey.undefined now has a 'falsy' value.
Atul Varma <varmaa@toolness.com>
parents: 56
diff changeset
43 This object also has a "falsy" value:
54
234fca1c4b86 Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents: 53
diff changeset
44
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
45 >>> if not pydermonkey.undefined:
57
a2b617731398 pymonkey.undefined now has a 'falsy' value.
Atul Varma <varmaa@toolness.com>
parents: 56
diff changeset
46 ... print "See, it's falsy!"
a2b617731398 pymonkey.undefined now has a 'falsy' value.
Atul Varma <varmaa@toolness.com>
parents: 56
diff changeset
47 See, it's falsy!
54
234fca1c4b86 Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents: 53
diff changeset
48
53
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
49 .. class:: Object
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
50
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
51 This is the type of JavaScript objects. Such objects can only be
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
52 created via Pydermonkey calls like :meth:`Context.new_object()` or
53
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
53 through the execution of JS code, but this type object can be used
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
54 with Python's built-in :func:`isinstance()` to verify that an
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
55 object is a JS object, like so:
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
56
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
57 >>> obj = pydermonkey.Runtime().new_context().new_object()
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
58 >>> isinstance(obj, pydermonkey.Object)
53
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
59 True
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
60
163
4edaa0e6f382 Added notes on identity perseverance for objects.
Atul Varma <varmaa@toolness.com>
parents: 161
diff changeset
61 Note that :class:`Object` and all its subclasses are
164
3fadba042201 Minor rewording in docs.
Atul Varma <varmaa@toolness.com>
parents: 163
diff changeset
62 identity-preserving when passed between Python and
3fadba042201 Minor rewording in docs.
Atul Varma <varmaa@toolness.com>
parents: 163
diff changeset
63 JavaScript code. For instance:
163
4edaa0e6f382 Added notes on identity perseverance for objects.
Atul Varma <varmaa@toolness.com>
parents: 161
diff changeset
64
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
65 >>> cx = pydermonkey.Runtime().new_context()
163
4edaa0e6f382 Added notes on identity perseverance for objects.
Atul Varma <varmaa@toolness.com>
parents: 161
diff changeset
66 >>> obj1 = cx.new_object()
4edaa0e6f382 Added notes on identity perseverance for objects.
Atul Varma <varmaa@toolness.com>
parents: 161
diff changeset
67 >>> obj2 = cx.evaluate_script(obj1, 'this', '<string>', 1)
4edaa0e6f382 Added notes on identity perseverance for objects.
Atul Varma <varmaa@toolness.com>
parents: 161
diff changeset
68 >>> obj1 is obj2
4edaa0e6f382 Added notes on identity perseverance for objects.
Atul Varma <varmaa@toolness.com>
parents: 161
diff changeset
69 True
4edaa0e6f382 Added notes on identity perseverance for objects.
Atul Varma <varmaa@toolness.com>
parents: 161
diff changeset
70
78
c48b393f6461 Added docs for Object.get_runtime().
Atul Varma <varmaa@toolness.com>
parents: 58
diff changeset
71 .. method:: get_runtime()
c48b393f6461 Added docs for Object.get_runtime().
Atul Varma <varmaa@toolness.com>
parents: 58
diff changeset
72
c48b393f6461 Added docs for Object.get_runtime().
Atul Varma <varmaa@toolness.com>
parents: 58
diff changeset
73 Returns the :class:`Runtime` that the object belongs to.
c48b393f6461 Added docs for Object.get_runtime().
Atul Varma <varmaa@toolness.com>
parents: 58
diff changeset
74
85
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
75 .. class:: Function
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
76
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
77 This is the type of JavaScript functions, which is a subtype of
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
78 :class:`Object`.
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
79
159
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
80 .. data:: filename
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
81
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
82 Name of the file that contains the function's original JS source
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
83 code. If the function isn't a JS function, this value is
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
84 ``None``.
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
85
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
86 .. data:: base_lineno
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
87
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
88 The line number at which the function's JS source code begins.
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
89
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
90 .. data:: line_extent
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
91
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
92 The number of lines comprising the function's JS source code.
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
93
161
28d067082390 Added docs for function.is_python.
Atul Varma <varmaa@toolness.com>
parents: 159
diff changeset
94 .. data:: is_python
28d067082390 Added docs for function.is_python.
Atul Varma <varmaa@toolness.com>
parents: 159
diff changeset
95
28d067082390 Added docs for function.is_python.
Atul Varma <varmaa@toolness.com>
parents: 159
diff changeset
96 Whether or not the function is actually implemented in Python.
28d067082390 Added docs for function.is_python.
Atul Varma <varmaa@toolness.com>
parents: 159
diff changeset
97 If it is, you can use :meth:`Context.get_object_private()` to
28d067082390 Added docs for function.is_python.
Atul Varma <varmaa@toolness.com>
parents: 159
diff changeset
98 retrieve this Python function.
28d067082390 Added docs for function.is_python.
Atul Varma <varmaa@toolness.com>
parents: 159
diff changeset
99
139
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
100 .. class:: Script
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
101
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
102 This is the type of compiled JavaScript scripts; it's actually a
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
103 subtype of :class:`Object`, though when exposed to JS code it
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
104 doesn't provide access to any special data or functionality.
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
105
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
106 Script instances have a read-only buffer interface that exposes
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
107 their bytecode. This can be accessed by passing an instance to
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
108 Python's built-in ``buffer()`` function.
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
109
144
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
110 .. data:: filename
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
111
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
112 The filename of the script's original source code.
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
113
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
114 .. data:: base_lineno
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
115
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
116 The line number at which the script's original source code
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
117 begins.
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
118
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
119 .. data:: line_extent
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
120
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
121 The number of lines comprising the original source code.
ab612d2ad96a Updated docs to reflect new script members.
Atul Varma <varmaa@toolness.com>
parents: 140
diff changeset
122
51
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
123 .. class:: Context
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
124
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
125 This is the type of JavaScript context objects. Contexts can only
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
126 be created via a call to :meth:`Runtime.new_context()`, but this
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
127 type object can be used with Python's built-in :func:`isinstance()`
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
128 to verify that an object is a context, like so:
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
129
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
130 >>> cx = pydermonkey.Runtime().new_context()
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
131 >>> isinstance(cx, pydermonkey.Context)
51
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
132 True
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
133
130
4705522c7431 Added notes about weak-referencability to docs.
Atul Varma <varmaa@toolness.com>
parents: 119
diff changeset
134 JS contexts are weak-referencable.
4705522c7431 Added notes about weak-referencability to docs.
Atul Varma <varmaa@toolness.com>
parents: 119
diff changeset
135
58
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
136 .. method:: get_runtime()
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
137
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
138 Returns the :class:`Runtime` that the context belongs to.
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
139
148
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
140 .. method:: get_stack()
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
141
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
142 Returns a dictionary containing information about the context's
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
143 current stack.
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
144
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
145 The dictionary contains the following string keys:
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
146
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
147 +------------------------------+-------------------------------------+
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
148 | key | value |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
149 +==============================+=====================================+
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
150 | :const:`script` | :class:`Script` of the frame. |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
151 | | This may be ``None`` if the frame |
159
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
152 | | isn't a scripted frame, or if it's |
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
153 | | not possible to expose the script |
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
154 | | to Python for some reason. |
148
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
155 +------------------------------+-------------------------------------+
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
156 | :const:`lineno` | Line number of the frame, if the |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
157 | | frame is scripted. |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
158 +------------------------------+-------------------------------------+
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
159 | :const:`pc` | Program counter of the frame; this |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
160 | | is an index into the bytecode of |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
161 | | the frame's script, if the frame |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
162 | | is scripted. |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
163 +------------------------------+-------------------------------------+
159
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
164 | :const:`function` | The :class:`Function` in which the |
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
165 | | frame is executing, if any. |
e57d8083fb3d Added more documentation and a unit test.
Atul Varma <varmaa@toolness.com>
parents: 150
diff changeset
166 +------------------------------+-------------------------------------+
148
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
167 | :const:`caller` | Dictionary containing information |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
168 | | about the stack frame of the |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
169 | | caller of this frame. If this frame |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
170 | | has no caller, this value is |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
171 | | ``None``. |
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
172 +------------------------------+-------------------------------------+
0b1020c817b3 Added docs for context.get_stack().
Atul Varma <varmaa@toolness.com>
parents: 144
diff changeset
173
150
aea82140758c Added more to get_stack() docs.
Atul Varma <varmaa@toolness.com>
parents: 148
diff changeset
174 If the context isn't currently executing any code (i.e., the stack
aea82140758c Added more to get_stack() docs.
Atul Varma <varmaa@toolness.com>
parents: 148
diff changeset
175 is empty), this method returns ``None``.
aea82140758c Added more to get_stack() docs.
Atul Varma <varmaa@toolness.com>
parents: 148
diff changeset
176
79
228a56e7e793 Added docs for context.get_object_private().
Atul Varma <varmaa@toolness.com>
parents: 78
diff changeset
177 .. method:: new_object([private_obj])
228a56e7e793 Added docs for context.get_object_private().
Atul Varma <varmaa@toolness.com>
parents: 78
diff changeset
178
228a56e7e793 Added docs for context.get_object_private().
Atul Varma <varmaa@toolness.com>
parents: 78
diff changeset
179 Creates a new :class:`Object` instance and returns
228a56e7e793 Added docs for context.get_object_private().
Atul Varma <varmaa@toolness.com>
parents: 78
diff changeset
180 it. ``private_obj`` is any Python object that is privately
228a56e7e793 Added docs for context.get_object_private().
Atul Varma <varmaa@toolness.com>
parents: 78
diff changeset
181 stored within the new JS object; it can be retrieved using
80
4945e4073110 Fixed typos in docs.
Atul Varma <varmaa@toolness.com>
parents: 79
diff changeset
182 :meth:`get_object_private()`.
58
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
183
115
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
184 .. method:: new_function(func, name)
85
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
185
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
186 Creates a new :class:`Function` instance that wraps the
90
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
187 given Python callable. In JS-land, the function will
85
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
188 have the given name.
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
189
115
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
190 When the function is executed from JavaScript, `func`
90
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
191 will be passed three positional arguments.
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
192
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
193 The first argument is a :class:`Context` that represents the
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
194 JS context which is calling the function.
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
195
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
196 The second argument is an :class:`Object` that represents the
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
197 value of ``this`` for the duration of the call.
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
198
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
199 The third argument is a tuple containing the arguments
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
200 passed to the function.
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
201
111
df607254de2d Added a doctest.
Atul Varma <varmaa@toolness.com>
parents: 90
diff changeset
202 For instance:
df607254de2d Added a doctest.
Atul Varma <varmaa@toolness.com>
parents: 90
diff changeset
203
df607254de2d Added a doctest.
Atul Varma <varmaa@toolness.com>
parents: 90
diff changeset
204 >>> def add(cx, this, args):
df607254de2d Added a doctest.
Atul Varma <varmaa@toolness.com>
parents: 90
diff changeset
205 ... return args[0] + args[1]
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
206 >>> cx = pydermonkey.Runtime().new_context()
111
df607254de2d Added a doctest.
Atul Varma <varmaa@toolness.com>
parents: 90
diff changeset
207 >>> obj = cx.new_object()
df607254de2d Added a doctest.
Atul Varma <varmaa@toolness.com>
parents: 90
diff changeset
208 >>> cx.define_property(obj, 'add', cx.new_function(add, 'add'))
df607254de2d Added a doctest.
Atul Varma <varmaa@toolness.com>
parents: 90
diff changeset
209 >>> cx.evaluate_script(obj, 'add(1, 1);', '<string>', 1)
df607254de2d Added a doctest.
Atul Varma <varmaa@toolness.com>
parents: 90
diff changeset
210 2
df607254de2d Added a doctest.
Atul Varma <varmaa@toolness.com>
parents: 90
diff changeset
211
114
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
212 .. method:: define_property(object, name, value)
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
213
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
214 Creates a new property on `object`, bypassing any JavaScript setters.
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
215
134
0c81cb18c935 Added docs for context.has_property().
Atul Varma <varmaa@toolness.com>
parents: 130
diff changeset
216 .. method:: has_property(object, name)
0c81cb18c935 Added docs for context.has_property().
Atul Varma <varmaa@toolness.com>
parents: 130
diff changeset
217
0c81cb18c935 Added docs for context.has_property().
Atul Varma <varmaa@toolness.com>
parents: 130
diff changeset
218 Returns whether or not `object` has the specified property.
0c81cb18c935 Added docs for context.has_property().
Atul Varma <varmaa@toolness.com>
parents: 130
diff changeset
219
114
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
220 .. method:: get_property(object, name)
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
221
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
222 Finds the specified property on `object` and returns its value,
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
223 possibly invoking a JavaScript getter.
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
224
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
225 Example:
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
226
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
227 >>> cx = pydermonkey.Runtime().new_context()
114
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
228 >>> obj = cx.new_object()
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
229 >>> cx.define_property(obj, 'beets', 'i like beets.')
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
230 >>> cx.get_property(obj, 'beets')
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
231 u'i like beets.'
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
232
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
233 Note also that calling this function on undefined properties
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
234 yields :data:`undefined`:
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
235
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
236 >>> cx.get_property(obj, 'carrots')
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
237 pydermonkey.undefined
114
87147faa031a Added docs for define_property() and get_property().
Atul Varma <varmaa@toolness.com>
parents: 113
diff changeset
238
79
228a56e7e793 Added docs for context.get_object_private().
Atul Varma <varmaa@toolness.com>
parents: 78
diff changeset
239 .. method:: get_object_private(object)
228a56e7e793 Added docs for context.get_object_private().
Atul Varma <varmaa@toolness.com>
parents: 78
diff changeset
240
80
4945e4073110 Fixed typos in docs.
Atul Varma <varmaa@toolness.com>
parents: 79
diff changeset
241 Returns the ``private_obj`` passed to :meth:`new_object()`
79
228a56e7e793 Added docs for context.get_object_private().
Atul Varma <varmaa@toolness.com>
parents: 78
diff changeset
242 when `object` was first created. If it doesn't exist, ``None``
228a56e7e793 Added docs for context.get_object_private().
Atul Varma <varmaa@toolness.com>
parents: 78
diff changeset
243 is returned.
228a56e7e793 Added docs for context.get_object_private().
Atul Varma <varmaa@toolness.com>
parents: 78
diff changeset
244
85
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
245 If `object` was created with :meth:`new_function()`, then this
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
246 method returns the Python callable wrapped by `object`.
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
247
90
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
248 This functionality is useful if you want to securely represent
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
249 Python objects in JS-land.
58
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
250
85
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
251 .. method:: clear_object_private(object)
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
252
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
253 Clears the ``private_obj`` passed to :meth:`new_object()`
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
254 when `object` was first created. If it doesn't exist, this
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
255 function returns nothing.
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
256
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
257 If `object` was created with :meth:`new_function()`, then this
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
258 method effectively "unbinds" the Python callable wrapped by
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
259 `object`. If `object` is later called, an exception will be
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
260 raised.
e9f450d30c0e Added more documentation.
Atul Varma <varmaa@toolness.com>
parents: 80
diff changeset
261
90
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
262 .. method:: evaluate_script(globalobj, code, filename, lineno)
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
263
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
264 Evaluates the text `code` using `globalobj` as the global
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
265 object/scope.
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
266
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
267 It's assumed that `code` is coming from the file named by `filename`;
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
268 the first line of `code` is assumed to be line number `lineno` of
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
269 `filename`. This metadata is very useful for debugging stack traces,
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
270 exceptions, and so forth.
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
271
113
e616b4605db0 Added doctest for evaluate_script().
Atul Varma <varmaa@toolness.com>
parents: 112
diff changeset
272 For example:
e616b4605db0 Added doctest for evaluate_script().
Atul Varma <varmaa@toolness.com>
parents: 112
diff changeset
273
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
274 >>> cx = pydermonkey.Runtime().new_context()
113
e616b4605db0 Added doctest for evaluate_script().
Atul Varma <varmaa@toolness.com>
parents: 112
diff changeset
275 >>> obj = cx.new_object()
e616b4605db0 Added doctest for evaluate_script().
Atul Varma <varmaa@toolness.com>
parents: 112
diff changeset
276 >>> cx.init_standard_classes(obj)
e616b4605db0 Added doctest for evaluate_script().
Atul Varma <varmaa@toolness.com>
parents: 112
diff changeset
277 >>> cx.evaluate_script(obj, '5 * Math', '<string>', 1)
e616b4605db0 Added doctest for evaluate_script().
Atul Varma <varmaa@toolness.com>
parents: 112
diff changeset
278 nan
e616b4605db0 Added doctest for evaluate_script().
Atul Varma <varmaa@toolness.com>
parents: 112
diff changeset
279
140
ce8099238c01 As per a discussion with jorendorff, it looks like we can pass NULL to compile_script(), since we're not using object principals (and instead just using an object capability model for now).
Atul Varma <varmaa@toolness.com>
parents: 139
diff changeset
280 .. method:: compile_script(code, filename, lineno)
139
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
281
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
282 Compiles the given string of code and returns a :class:`Script`
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
283 instance that can be executed via :meth:`execute_script()`.
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
284
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
285 `filename` and `lineno` are used just as in
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
286 :meth:`evaluate_script()`.
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
287
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
288 .. method:: execute_script(globalobj, script)
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
289
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
290 Executes the code in the given :class:`Script` object, using
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
291 `globalobj` as the global object/scope, and returns the result.
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
292
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
293 For example:
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
294
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
295 >>> cx = pydermonkey.Runtime().new_context()
139
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
296 >>> obj = cx.new_object()
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
297 >>> cx.init_standard_classes(obj)
140
ce8099238c01 As per a discussion with jorendorff, it looks like we can pass NULL to compile_script(), since we're not using object principals (and instead just using an object capability model for now).
Atul Varma <varmaa@toolness.com>
parents: 139
diff changeset
298 >>> script = cx.compile_script('5 * Math', '<string>', 1)
139
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
299 >>> cx.execute_script(obj, script)
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
300 nan
d08cb5a06c66 Added docs for Script, compile_script() and execute_script().
Atul Varma <varmaa@toolness.com>
parents: 134
diff changeset
301
90
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
302 .. method:: call_function(thisobj, func, args)
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
303
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
304 Calls a JavaScript function.
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
305
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
306 `thisobj` is an :class:`Object` that will be used as the value
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
307 of ``this`` when the function executes, `func` is the
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
308 :class:`Function` to execute, and `args` is a tuple of arguments
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
309 to pass to the function.
c41f1d2e8f9d Added more docs.
Atul Varma <varmaa@toolness.com>
parents: 85
diff changeset
310
112
2086377c0abe Added doctest for call_function().
Atul Varma <varmaa@toolness.com>
parents: 111
diff changeset
311 For instance:
2086377c0abe Added doctest for call_function().
Atul Varma <varmaa@toolness.com>
parents: 111
diff changeset
312
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
313 >>> cx = pydermonkey.Runtime().new_context()
112
2086377c0abe Added doctest for call_function().
Atul Varma <varmaa@toolness.com>
parents: 111
diff changeset
314 >>> obj = cx.new_object()
2086377c0abe Added doctest for call_function().
Atul Varma <varmaa@toolness.com>
parents: 111
diff changeset
315 >>> cx.init_standard_classes(obj)
2086377c0abe Added doctest for call_function().
Atul Varma <varmaa@toolness.com>
parents: 111
diff changeset
316 >>> Math = cx.get_property(obj, 'Math')
2086377c0abe Added doctest for call_function().
Atul Varma <varmaa@toolness.com>
parents: 111
diff changeset
317 >>> floor = cx.get_property(Math, 'floor')
2086377c0abe Added doctest for call_function().
Atul Varma <varmaa@toolness.com>
parents: 111
diff changeset
318 >>> cx.call_function(Math, floor, (5.3,))
2086377c0abe Added doctest for call_function().
Atul Varma <varmaa@toolness.com>
parents: 111
diff changeset
319 5
2086377c0abe Added doctest for call_function().
Atul Varma <varmaa@toolness.com>
parents: 111
diff changeset
320
58
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
321 .. method:: init_standard_classes(object)
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
322
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
323 Defines the standard JavaScript classes on the given
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
324 :class:`Object`, such as ``Array``, ``eval``, ``undefined``, and
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
325 so forth. For more information, see the documentation to
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
326 `JS_InitStandardClasses()
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
327 <https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JS_InitStandardClasses>`_,
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
328 which this method wraps.
7a3461ccaf1d Added documentation for Context methods get_runtime(), new_object(), and init_standard_classes().
Atul Varma <varmaa@toolness.com>
parents: 57
diff changeset
329
115
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
330 .. method:: gc()
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
331
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
332 Performs garbage collection on the context's JavaScript runtime.
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
333
167
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
334 .. method:: is_exception_pending()
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
335
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
336 Returns whether an exception is currently being propagated in
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
337 the context.
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
338
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
339 .. method:: get_pending_exception()
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
340
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
341 Returns the current exception being propagated in the context. If
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
342 no exception is being propagated, this method returns ``None``.
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
343
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
344 If you need to disambiguate between whether ``None`` is the
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
345 pending exception or there is no pending exception, use
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
346 :meth:`is_exception_pending()`.
b745c9d8eef9 Added docs for pending exception methods.
Atul Varma <varmaa@toolness.com>
parents: 164
diff changeset
347
168
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
348 .. method:: set_throw_hook(func)
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
349
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
350 Sets the throw hook for the context to the given Python callable.
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
351 The hook is triggered whenever an exception is thrown in the
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
352 context.
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
353
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
354 `func` takes one argument: the context that triggered it.
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
355
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
356 For example, here's a throw hook that prints information about
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
357 an exception as it's being propagated through the stack:
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
358
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
359 >>> def throwhook(cx):
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
360 ... stack = cx.get_stack()
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
361 ... if stack['function']:
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
362 ... where = stack['function'].name
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
363 ... else:
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
364 ... where = stack['script'].filename
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
365 ... exc = cx.get_pending_exception()
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
366 ... print "%s being thrown in %s" % (exc, where)
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
367
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
368 Here's the hook in action:
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
369
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
370 >>> cx = pydermonkey.Runtime().new_context()
168
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
371 >>> cx.set_throw_hook(throwhook)
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
372 >>> obj = cx.new_object()
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
373 >>> code = "(function foo() { throw 'oops' })()"
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
374 >>> try:
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
375 ... cx.evaluate_script(obj, code, '<string>', 1)
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
376 ... except pydermonkey.error, e:
168
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
377 ... print "caught %s" % e.args[0]
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
378 oops being thrown in foo
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
379 oops being thrown in <string>
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
380 caught oops
68d9e1ed19f8 Added docs for set_throw_hook().
Atul Varma <varmaa@toolness.com>
parents: 167
diff changeset
381
115
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
382 .. method:: set_operation_callback(func)
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
383
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
384 Sets the operation callback for the context to the given Python
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
385 callable. The callback can be triggered via
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
386 :meth:`trigger_operation_callback()`.
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
387
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
388 `func` takes one argument: the context that triggered it.
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
389
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
390 .. method:: trigger_operation_callback()
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
391
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
392 Triggers the context's operation callback. If no callback has
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
393 yet been set, this function does nothing.
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
394
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
395 This function is one of the few thread-safe functions available
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
396 to a JS runtime, and together with
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
397 :meth:`set_operation_callback()` can be used to abort the
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
398 execution of long-running code.
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
399
116
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
400 For instance, we first create an operation callback to stop
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
401 long-running code by throwing an exception:
115
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
402
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
403 >>> import time, threading
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
404 >>> cx = pydermonkey.Runtime().new_context()
115
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
405 >>> def stop_running_code(cx):
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
406 ... raise Exception('JS took too long to execute.')
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
407 >>> cx.set_operation_callback(stop_running_code)
116
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
408
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
409 Then we create a watchdog thread to trigger the operation
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
410 callback once a long amount of time has passed:
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
411
115
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
412 >>> def watchdog_thread():
116
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
413 ... time.sleep(0.1) # An eternity to a computer!
115
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
414 ... cx.trigger_operation_callback()
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
415 >>> thread = threading.Thread(target=watchdog_thread)
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
416 >>> thread.start()
116
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
417
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
418 Now, when we execute code that takes too long to run, it gets
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
419 aborted:
06269ca0b36c Made the operation callback doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents: 115
diff changeset
420
115
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
421 >>> try:
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
422 ... cx.evaluate_script(cx.new_object(), 'while (1) {}',
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
423 ... '<string>', 1)
170
dd32a92f6b4f Initial attempt at renaming pymonkey to pydermonkey.
Atul Varma <varmaa@toolness.com>
parents: 169
diff changeset
424 ... except pydermonkey.error, e:
115
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
425 ... print cx.get_object_private(e.args[0])
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
426 JS took too long to execute.
f4c550369332 Added documentation for gc() and operation callback functions.
Atul Varma <varmaa@toolness.com>
parents: 114
diff changeset
427
51
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
428 .. class:: Runtime()
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
429
53
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
430 Creates a new JavaScript runtime. JS objects created by the runtime
2055d853b995 Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents: 51
diff changeset
431 may only interact with other JS objects of the same runtime.
51
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
432
119
d30576edf797 Added notes on thread safety to documentation.
Atul Varma <varmaa@toolness.com>
parents: 116
diff changeset
433 With few exceptions, objects belonging to a runtime can currently
d30576edf797 Added notes on thread safety to documentation.
Atul Varma <varmaa@toolness.com>
parents: 116
diff changeset
434 only be used in the same thread that the runtime was created
d30576edf797 Added notes on thread safety to documentation.
Atul Varma <varmaa@toolness.com>
parents: 116
diff changeset
435 in. This may be changed in the future, since SpiderMonkey itself
d30576edf797 Added notes on thread safety to documentation.
Atul Varma <varmaa@toolness.com>
parents: 116
diff changeset
436 has support for thread safety.
d30576edf797 Added notes on thread safety to documentation.
Atul Varma <varmaa@toolness.com>
parents: 116
diff changeset
437
130
4705522c7431 Added notes about weak-referencability to docs.
Atul Varma <varmaa@toolness.com>
parents: 119
diff changeset
438 JS runtimes are weak-referencable.
4705522c7431 Added notes about weak-referencability to docs.
Atul Varma <varmaa@toolness.com>
parents: 119
diff changeset
439
51
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
440 .. method:: new_context()
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
441
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
442 Creates a new Context object and returns it. Contexts are best
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
443 conceptualized as threads of execution in a JS runtme; each one
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
444 has a program counter, a current exception state, and so
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
445 forth. JS objects may be freely accessed and changed by contexts
fabd3f2271fa Added some basic, incomplete docs on the pymonkey module, which include a doctest that's run when pymonkey is built.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
446 that are associated with the same JS runtime as the objects.