comparison docs.txt @ 24:c2c369402a2e

Added more docs, fixed edge cases.
author Atul Varma <varmaa@toolness.com>
date Thu, 10 Sep 2009 22:32:45 -0700
parents 7cbbec55aef6
children 351819baecd1
comparison
equal deleted inserted replaced
23:7cbbec55aef6 24:c2c369402a2e
3 ========= 3 =========
4 4
5 Pydertron is a high-level wrapper for `Pydermonkey`__ that 5 Pydertron is a high-level wrapper for `Pydermonkey`__ that
6 provides convenient, secure object wrapping between JS and Python 6 provides convenient, secure object wrapping between JS and Python
7 space. 7 space.
8
9 Note that Pydertron is just one example of a high-level interface
10 between Python and JavaScript: it assumes, for instance, that the JS
11 code it executes isn't trusted, which affects the nature of the
12 inter-language interaction.
13
14 The Basics
15 ----------
8 16
9 The ``JsSandbox`` class encapsulates a JavaScript runtime, context, global 17 The ``JsSandbox`` class encapsulates a JavaScript runtime, context, global
10 object, and a simple `SecurableModule`__ implementation that complies 18 object, and a simple `SecurableModule`__ implementation that complies
11 with the `CommonJS`__ standard. It also provides a high-level bridge between 19 with the `CommonJS`__ standard. It also provides a high-level bridge between
12 Python and JavaScript so that you don't need to deal with any of the 20 Python and JavaScript so that you don't need to deal with any of the
75 File "<string>", line 1, in <module> 83 File "<string>", line 1, in <module>
76 File "<string>", line 1, in foo 84 File "<string>", line 1, in foo
77 ReferenceError: bar is not defined 85 ReferenceError: bar is not defined
78 -1 86 -1
79 87
80 Note that the traceback displayed is actually referring to 88 Note that the traceback displayed is actually referring to JavaScript
81 JavaScript code: one of Pydertron's helpful conveniences is that 89 code: one of Pydertron's aims is to make debugging JS code as much
82 it makes debugging JS code as much like debugging Python code as 90 like debugging Python code as possible.
83 possible. 91
92 Exceptions
93 ----------
94
95 Any exceptions raised by wrapped Python functions need to be of type
96 ``pydermonkey.error`` to be propagated into calling JavaScript code;
97 if they're not, then for security purposes, the entire JavaScript call
98 stack is unrolled.
99
100 For example, here's a function that's bound to fail:
101
102 >>> @jsexposed
103 ... def fail():
104 ... o()
105 >>> sandbox.root.fail = fail
106
107 Now, even though the following JS code calls the function in a
108 try-catch block, the JS code doesn't catch anything and its execution
109 is simply halted:
110
111 >>> sandbox.run_script("try { fail(); } catch (e) {}",
112 ... stderr=sys.stdout) #doctest: +ELLIPSIS
113 An internal error occurred.
114 Traceback (most recent call last):
115 ...
116 NameError: global name 'o' is not defined
117 -1
118
119 Note that a ``KeyboardInterrupt`` triggered while JS is executing will
120 have similar effect.