Mercurial > pymonkey
annotate docs/rendered/_sources/pymonkey.txt @ 56:72e84bd75905
Made another doctest easier to read.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 10 Jul 2009 17:39:48 -0700 |
parents | 40a404b9c467 |
children | a2b617731398 |
rev | line source |
---|---|
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
|
1 :mod:`pymonkey` --- 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
|
2 =================================================== |
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 |
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
|
4 .. module:: pymonkey |
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 |
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
|
9 import pymonkey |
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 |
54
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
19 .. data:: undefined |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
20 |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
21 This is the singleton that represents the JavaScript value |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
22 ``undefined``, as Python has no equivalent representation |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
23 (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
|
24 For instance: |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
25 |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
26 >>> cx = pymonkey.Runtime().new_context() |
56
72e84bd75905
Made another doctest easier to read.
Atul Varma <varmaa@toolness.com>
parents:
55
diff
changeset
|
27 >>> cx.evaluate_script(cx.new_object(), '', '<string>', 1) |
54
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
28 <type 'pymonkey.undefined'> |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
29 |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
30 Unfortunately, this object currently does not have a "falsy" value, |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
31 e.g.: |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
32 |
55
40a404b9c467
Made a doctest more readable.
Atul Varma <varmaa@toolness.com>
parents:
54
diff
changeset
|
33 >>> if pymonkey.undefined: |
54
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
34 ... print 'Huh, this is kind of unintuitive.' |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
35 Huh, this is kind of unintuitive. |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
36 |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
37 The reason for this is simply that we don't currently know how to |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
38 make this object have a falsy value, if it's even possible. |
234fca1c4b86
Added docs for pymonkey.undefined.
Atul Varma <varmaa@toolness.com>
parents:
53
diff
changeset
|
39 |
53
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
40 .. class:: Object |
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
41 |
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
42 This is the type of JavaScript objects. Such objects can only be |
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
43 created via Pymonkey calls like :meth:`Context.new_object()` or |
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
44 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
|
45 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
|
46 object is a JS object, like so: |
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
47 |
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
48 >>> obj = pymonkey.Runtime().new_context().new_object() |
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
49 >>> isinstance(obj, pymonkey.Object) |
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
50 True |
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
51 |
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
|
52 .. 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
|
53 |
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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 |
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
|
59 >>> cx = pymonkey.Runtime().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
|
60 >>> isinstance(cx, pymonkey.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
|
61 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
|
62 |
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
|
63 .. 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
|
64 |
53
2055d853b995
Added docs for pymonkey.Object.
Atul Varma <varmaa@toolness.com>
parents:
51
diff
changeset
|
65 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
|
66 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
|
67 |
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
|
68 .. 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
|
69 |
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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 that are associated with the same JS runtime as the objects. |