Mercurial > pydertron
comparison docs.html @ 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 |
---|---|
11 <div class="document" id="pydertron"> | 11 <div class="document" id="pydertron"> |
12 <h1 class="title">Pydertron</h1> | 12 <h1 class="title">Pydertron</h1> |
13 <p>Pydertron is a high-level wrapper for <a class="reference" href="http://code.google.com/p/pydermonkey">Pydermonkey</a> that | 13 <p>Pydertron is a high-level wrapper for <a class="reference" href="http://code.google.com/p/pydermonkey">Pydermonkey</a> that |
14 provides convenient, secure object wrapping between JS and Python | 14 provides convenient, secure object wrapping between JS and Python |
15 space.</p> | 15 space.</p> |
16 <p>Note that Pydertron is just one example of a high-level interface | |
17 between Python and JavaScript: it assumes, for instance, that the JS | |
18 code it executes isn't trusted, which affects the nature of the | |
19 inter-language interaction.</p> | |
20 <div class="section"> | |
21 <h1><a id="the-basics" name="the-basics">The Basics</a></h1> | |
16 <p>The <tt class="docutils literal"><span class="pre">JsSandbox</span></tt> class encapsulates a JavaScript runtime, context, global | 22 <p>The <tt class="docutils literal"><span class="pre">JsSandbox</span></tt> class encapsulates a JavaScript runtime, context, global |
17 object, and a simple <a class="reference" href="http://wiki.commonjs.org/wiki/CommonJS/Modules/SecurableModules">SecurableModule</a> implementation that complies | 23 object, and a simple <a class="reference" href="http://wiki.commonjs.org/wiki/CommonJS/Modules/SecurableModules">SecurableModule</a> implementation that complies |
18 with the <a class="reference" href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a> standard. It also provides a high-level bridge between | 24 with the <a class="reference" href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a> standard. It also provides a high-level bridge between |
19 Python and JavaScript so that you don't need to deal with any of the | 25 Python and JavaScript so that you don't need to deal with any of the |
20 low-level details of the Pydermonkey API.</p> | 26 low-level details of the Pydermonkey API.</p> |
88 File "<string>", line 1, in foo | 94 File "<string>", line 1, in foo |
89 ReferenceError: bar is not defined | 95 ReferenceError: bar is not defined |
90 -1 | 96 -1 |
91 </pre> | 97 </pre> |
92 </blockquote> | 98 </blockquote> |
93 <p>Note that the traceback displayed is actually referring to | 99 <p>Note that the traceback displayed is actually referring to JavaScript |
94 JavaScript code: one of Pydertron's helpful conveniences is that | 100 code: one of Pydertron's aims is to make debugging JS code as much |
95 it makes debugging JS code as much like debugging Python code as | 101 like debugging Python code as possible.</p> |
96 possible.</p> | 102 </div> |
103 <div class="section"> | |
104 <h1><a id="exceptions" name="exceptions">Exceptions</a></h1> | |
105 <p>Any exceptions raised by wrapped Python functions need to be of type | |
106 <tt class="docutils literal"><span class="pre">pydermonkey.error</span></tt> to be propagated into calling JavaScript code; | |
107 if they're not, then for security purposes, the entire JavaScript call | |
108 stack is unrolled.</p> | |
109 <p>For example, here's a function that's bound to fail:</p> | |
110 <blockquote> | |
111 <pre class="doctest-block"> | |
112 >>> @jsexposed | |
113 ... def fail(): | |
114 ... o() | |
115 >>> sandbox.root.fail = fail | |
116 </pre> | |
117 </blockquote> | |
118 <p>Now, even though the following JS code calls the function in a | |
119 try-catch block, the JS code doesn't catch anything and its execution | |
120 is simply halted:</p> | |
121 <blockquote> | |
122 <pre class="doctest-block"> | |
123 >>> sandbox.run_script("try { fail(); } catch (e) {}", | |
124 ... stderr=sys.stdout) #doctest: +ELLIPSIS | |
125 An internal error occurred. | |
126 Traceback (most recent call last): | |
127 ... | |
128 NameError: global name 'o' is not defined | |
129 -1 | |
130 </pre> | |
131 </blockquote> | |
132 <p>Note that a <tt class="docutils literal"><span class="pre">KeyboardInterrupt</span></tt> triggered while JS is executing will | |
133 have similar effect.</p> | |
134 </div> | |
97 </div> | 135 </div> |
98 <div class="footer"> | 136 <div class="footer"> |
99 <hr class="footer" /> | 137 <hr class="footer" /> |
100 <a class="reference" href="docs.txt">View document source</a>. | 138 <a class="reference" href="docs.txt">View document source</a>. |
101 | 139 |