changeset 115:f4c550369332

Added documentation for gc() and operation callback functions.
author Atul Varma <varmaa@toolness.com>
date Mon, 17 Aug 2009 03:33:40 -0700
parents 87147faa031a
children 06269ca0b36c
files docs/rendered/_sources/pymonkey.txt docs/rendered/genindex.html docs/rendered/pymonkey.html docs/rendered/searchindex.js docs/src/pymonkey.txt
diffstat 5 files changed, 151 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/docs/rendered/_sources/pymonkey.txt	Mon Aug 17 03:02:51 2009 -0700
+++ b/docs/rendered/_sources/pymonkey.txt	Mon Aug 17 03:33:40 2009 -0700
@@ -76,13 +76,13 @@
       stored within the new JS object; it can be retrieved using
       :meth:`get_object_private()`.
 
-   .. method:: new_function(callable, name)
+   .. method:: new_function(func, name)
 
       Creates a new :class:`Function` instance that wraps the
       given Python callable.  In JS-land, the function will
       have the given name.
 
-      When the function is executed from JavaScript, `callable`
+      When the function is executed from JavaScript, `func`
       will be passed three positional arguments.
 
       The first argument is a :class:`Context` that represents the
@@ -196,6 +196,47 @@
       <https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JS_InitStandardClasses>`_,
       which this method wraps.
 
+   .. method:: gc()
+
+      Performs garbage collection on the context's JavaScript runtime.
+
+   .. method:: set_operation_callback(func)
+
+      Sets the operation callback for the context to the given Python
+      callable. The callback can be triggered via
+      :meth:`trigger_operation_callback()`.
+
+      `func` takes one argument: the context that triggered it.
+
+   .. method:: trigger_operation_callback()
+
+      Triggers the context's operation callback. If no callback has
+      yet been set, this function does nothing.
+
+      This function is one of the few thread-safe functions available
+      to a JS runtime, and together with
+      :meth:`set_operation_callback()` can be used to abort the
+      execution of long-running code.
+
+      For instance:
+
+        >>> import time, threading
+        >>> cx = pymonkey.Runtime().new_context()
+        >>> def stop_running_code(cx):
+        ...   raise Exception('JS took too long to execute.')
+        >>> cx.set_operation_callback(stop_running_code)
+        >>> def watchdog_thread():
+        ...   time.sleep(0.1)
+        ...   cx.trigger_operation_callback()
+        >>> thread = threading.Thread(target=watchdog_thread)
+        >>> thread.start()
+        >>> try:
+        ...   cx.evaluate_script(cx.new_object(), 'while (1) {}',
+        ...                      '<string>', 1)
+        ... except pymonkey.error, e:
+        ...   print cx.get_object_private(e.args[0])
+        JS took too long to execute.
+
 .. class:: Runtime()
 
    Creates a new JavaScript runtime. JS objects created by the runtime
--- a/docs/rendered/genindex.html	Mon Aug 17 03:02:51 2009 -0700
+++ b/docs/rendered/genindex.html	Mon Aug 17 03:33:40 2009 -0700
@@ -43,7 +43,7 @@
 
    <h1 id="index">Index</h1>
 
-   <a href="#C"><strong>C</strong></a> | <a href="#D"><strong>D</strong></a> | <a href="#E"><strong>E</strong></a> | <a href="#F"><strong>F</strong></a> | <a href="#G"><strong>G</strong></a> | <a href="#I"><strong>I</strong></a> | <a href="#N"><strong>N</strong></a> | <a href="#O"><strong>O</strong></a> | <a href="#P"><strong>P</strong></a> | <a href="#R"><strong>R</strong></a> | <a href="#U"><strong>U</strong></a> 
+   <a href="#C"><strong>C</strong></a> | <a href="#D"><strong>D</strong></a> | <a href="#E"><strong>E</strong></a> | <a href="#F"><strong>F</strong></a> | <a href="#G"><strong>G</strong></a> | <a href="#I"><strong>I</strong></a> | <a href="#N"><strong>N</strong></a> | <a href="#O"><strong>O</strong></a> | <a href="#P"><strong>P</strong></a> | <a href="#R"><strong>R</strong></a> | <a href="#S"><strong>S</strong></a> | <a href="#T"><strong>T</strong></a> | <a href="#U"><strong>U</strong></a> 
 
    <hr />
 
@@ -83,12 +83,13 @@
 <table width="100%" class="indextable"><tr><td width="33%" valign="top">
 <dl>
 
+<dt><a href="pymonkey.html#pymonkey.Context.gc">gc() (pymonkey.Context method)</a></dt>
 <dt><a href="pymonkey.html#pymonkey.Context.get_object_private">get_object_private() (pymonkey.Context method)</a></dt>
-<dt><a href="pymonkey.html#pymonkey.Context.get_property">get_property() (pymonkey.Context method)</a></dt>
+<dt><a href="pymonkey.html#pymonkey.Context.get_property">get_property() (pymonkey.Context method)</a></dt></dl></td><td width="33%" valign="top"><dl>
 <dt><a href="pymonkey.html#pymonkey.Context.get_runtime">get_runtime() (pymonkey.Context method)</a></dt>
   <dd><dl>
     <dt><a href="pymonkey.html#pymonkey.Object.get_runtime">(pymonkey.Object method)</a></dt>
-  </dl></dd></dl></td><td width="33%" valign="top"><dl>
+  </dl></dd>
 </dl></td></tr></table>
 
 <h2 id="I">I</h2>
@@ -128,6 +129,20 @@
 <dt><a href="pymonkey.html#pymonkey.Runtime">Runtime (class in pymonkey)</a></dt></dl></td><td width="33%" valign="top"><dl>
 </dl></td></tr></table>
 
+<h2 id="S">S</h2>
+<table width="100%" class="indextable"><tr><td width="33%" valign="top">
+<dl>
+
+<dt><a href="pymonkey.html#pymonkey.Context.set_operation_callback">set_operation_callback() (pymonkey.Context method)</a></dt></dl></td><td width="33%" valign="top"><dl>
+</dl></td></tr></table>
+
+<h2 id="T">T</h2>
+<table width="100%" class="indextable"><tr><td width="33%" valign="top">
+<dl>
+
+<dt><a href="pymonkey.html#pymonkey.Context.trigger_operation_callback">trigger_operation_callback() (pymonkey.Context method)</a></dt></dl></td><td width="33%" valign="top"><dl>
+</dl></td></tr></table>
+
 <h2 id="U">U</h2>
 <table width="100%" class="indextable"><tr><td width="33%" valign="top">
 <dl>
--- a/docs/rendered/pymonkey.html	Mon Aug 17 03:02:51 2009 -0700
+++ b/docs/rendered/pymonkey.html	Mon Aug 17 03:33:40 2009 -0700
@@ -130,11 +130,11 @@
 
 <dl class="method">
 <dt id="pymonkey.Context.new_function">
-<tt class="descname">new_function</tt><big>(</big><em>callable</em>, <em>name</em><big>)</big><a class="headerlink" href="#pymonkey.Context.new_function" title="Permalink to this definition">¶</a></dt>
+<tt class="descname">new_function</tt><big>(</big><em>func</em>, <em>name</em><big>)</big><a class="headerlink" href="#pymonkey.Context.new_function" title="Permalink to this definition">¶</a></dt>
 <dd><p>Creates a new <a title="pymonkey.Function" class="reference" href="#pymonkey.Function"><tt class="xref docutils literal"><span class="pre">Function</span></tt></a> instance that wraps the
 given Python callable.  In JS-land, the function will
 have the given name.</p>
-<p>When the function is executed from JavaScript, <cite>callable</cite>
+<p>When the function is executed from JavaScript, <cite>func</cite>
 will be passed three positional arguments.</p>
 <p>The first argument is a <a title="pymonkey.Context" class="reference" href="#pymonkey.Context"><tt class="xref docutils literal"><span class="pre">Context</span></tt></a> that represents the
 JS context which is calling the function.</p>
@@ -252,6 +252,50 @@
 <a class="reference" href="https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JS_InitStandardClasses">JS_InitStandardClasses()</a>,
 which this method wraps.</dd></dl>
 
+<dl class="method">
+<dt id="pymonkey.Context.gc">
+<tt class="descname">gc</tt><big>(</big><big>)</big><a class="headerlink" href="#pymonkey.Context.gc" title="Permalink to this definition">¶</a></dt>
+<dd>Performs garbage collection on the context&#8217;s JavaScript runtime.</dd></dl>
+
+<dl class="method">
+<dt id="pymonkey.Context.set_operation_callback">
+<tt class="descname">set_operation_callback</tt><big>(</big><em>func</em><big>)</big><a class="headerlink" href="#pymonkey.Context.set_operation_callback" title="Permalink to this definition">¶</a></dt>
+<dd><p>Sets the operation callback for the context to the given Python
+callable. The callback can be triggered via
+<a title="pymonkey.Context.trigger_operation_callback" class="reference" href="#pymonkey.Context.trigger_operation_callback"><tt class="xref docutils literal"><span class="pre">trigger_operation_callback()</span></tt></a>.</p>
+<p><cite>func</cite> takes one argument: the context that triggered it.</p>
+</dd></dl>
+
+<dl class="method">
+<dt id="pymonkey.Context.trigger_operation_callback">
+<tt class="descname">trigger_operation_callback</tt><big>(</big><big>)</big><a class="headerlink" href="#pymonkey.Context.trigger_operation_callback" title="Permalink to this definition">¶</a></dt>
+<dd><p>Triggers the context&#8217;s operation callback. If no callback has
+yet been set, this function does nothing.</p>
+<p>This function is one of the few thread-safe functions available
+to a JS runtime, and together with
+<a title="pymonkey.Context.set_operation_callback" class="reference" href="#pymonkey.Context.set_operation_callback"><tt class="xref docutils literal"><span class="pre">set_operation_callback()</span></tt></a> can be used to abort the
+execution of long-running code.</p>
+<p>For instance:</p>
+<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="k">import</span> <span class="nn">time</span><span class="o">,</span> <span class="nn">threading</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">cx</span> <span class="o">=</span> <span class="n">pymonkey</span><span class="o">.</span><span class="n">Runtime</span><span class="p">()</span><span class="o">.</span><span class="n">new_context</span><span class="p">()</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">stop_running_code</span><span class="p">(</span><span class="n">cx</span><span class="p">):</span>
+<span class="gp">... </span>  <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s">&#39;JS took too long to execute.&#39;</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">cx</span><span class="o">.</span><span class="n">set_operation_callback</span><span class="p">(</span><span class="n">stop_running_code</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">watchdog_thread</span><span class="p">():</span>
+<span class="gp">... </span>  <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.1</span><span class="p">)</span>
+<span class="gp">... </span>  <span class="n">cx</span><span class="o">.</span><span class="n">trigger_operation_callback</span><span class="p">()</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">thread</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="n">watchdog_thread</span><span class="p">)</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="n">thread</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
+<span class="gp">&gt;&gt;&gt; </span><span class="k">try</span><span class="p">:</span>
+<span class="gp">... </span>  <span class="n">cx</span><span class="o">.</span><span class="n">evaluate_script</span><span class="p">(</span><span class="n">cx</span><span class="o">.</span><span class="n">new_object</span><span class="p">(),</span> <span class="s">&#39;while (1) {}&#39;</span><span class="p">,</span>
+<span class="gp">... </span>                     <span class="s">&#39;&lt;string&gt;&#39;</span><span class="p">,</span> <span class="mf">1</span><span class="p">)</span>
+<span class="gp">... </span><span class="k">except</span> <span class="n">pymonkey</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
+<span class="gp">... </span>  <span class="k">print</span> <span class="n">cx</span><span class="o">.</span><span class="n">get_object_private</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">])</span>
+<span class="go">JS took too long to execute.</span>
+</pre></div>
+</div>
+</dd></dl>
+
 </dd></dl>
 
 <dl class="class">
--- a/docs/rendered/searchindex.js	Mon Aug 17 03:02:51 2009 -0700
+++ b/docs/rendered/searchindex.js	Mon Aug 17 03:33:40 2009 -0700
@@ -1,1 +1,1 @@
-Search.setIndex({desctypes:{"0":"method","1":"exception","2":"class","3":"data"},terms:{spidermonkei:[0,1],represent:1,all:0,code:[0,1],untrust:0,lack:0,concept:0,get_object_priv:1,privat:1,depend:0,readabl:0,program:1,isinst:1,liter:1,string:1,veri:[0,1],retriev:1,vast:0,level:1,"try":0,second:1,pass:1,casual:0,even:[],index:0,evaluate_script:1,abl:0,access:[0,1],"new":1,objdir:[],method:1,metadata:1,define_properti:1,full:0,subtyp:1,never:0,onli:[0,1],here:0,objcec:[],path:[],valu:1,search:0,doctest:0,chang:1,tremend:0,via:[0,1],modul:[0,1],filenam:1,api:0,instal:0,test_pymonkei:[],from:[0,1],would:0,memori:0,init_standard_class:1,call:1,scope:1,type:1,more:[0,1],thisobj:1,mozilla:[0,1],line:1,ctype:0,known:0,actual:0,must:0,none:1,join:[],setup:0,work:0,conceptu:1,can:[0,1],learn:0,akin:0,root:0,fetch:0,def:1,give:0,process:0,challeng:0,sudo:0,indic:0,carrot:1,want:[0,1],alwai:0,goal:0,secur:[0,1],write:0,how:0,verifi:1,map:1,product:0,clone:[],usabl:0,befor:0,mai:1,associ:1,third:[0,1],counter:1,inform:1,sandbox:0,environ:0,enter:[],callabl:1,becaus:0,intermediari:0,through:1,dynam:0,platform:0,window:0,bypass:1,easier:0,them:0,js_initstandardclass:1,"return":1,thei:[],python:[0,1],now:[],xpcom:0,name:1,anyth:0,get_runtim:1,easili:0,trap:0,each:1,debug:[0,1],side:0,mean:0,compil:0,everyth:0,realli:0,ensur:0,"static":[],collector:0,out:0,path_to_objdir:[],profil:0,lineno:1,rational:0,print:1,forth:1,math:1,situat:0,free:[],standard:[0,1],reason:[],base:0,thrown:1,thread:1,traceback:0,first:1,singleton:1,obviou:0,pyrex:0,feel:[],arrai:1,number:[0,1],get_properti:1,instruct:[],facil:0,given:1,script:[],interact:1,too:0,"final":0,store:1,relationship:0,tool:[],huh:[],specifi:1,getter:1,than:0,wide:0,kind:[],provid:0,posit:1,browser:0,pre:1,falsi:1,ani:[0,1],packag:0,have:[0,1],tabl:0,need:0,"null":1,engin:[0,1],built:1,equival:1,latter:[],client:0,note:[0,1],also:[0,1],ideal:0,exampl:1,build:0,which:[0,1],noth:[0,1],trace:1,object:[0,1],plai:0,"class":1,don:0,clear:1,later:1,doe:[],runtim:1,awesom:0,text:1,particularli:0,find:1,setter:1,involv:0,current:[0,1],new_object:1,execut:[0,1],solut:0,should:0,busi:0,contribut:0,pave:0,increas:0,requir:0,enabl:0,yield:1,contain:1,where:0,new_context:1,see:1,arg:1,disadvantag:0,best:1,detect:0,someth:0,state:1,won:0,outstand:0,between:0,atul:0,call_funct:1,javascript:[0,1],extens:0,preprocessor:0,complementari:0,come:1,expos:0,cycl:0,howev:0,blargh:[],instanc:[0,1],context:[0,1],logic:0,freeli:1,com:[],private_obj:1,simpli:[],sweep:0,wrap:1,header:0,assum:1,duplic:0,quit:0,java:0,evalu:1,three:1,mark:0,clear_object_priv:[0,1],argument:1,func:1,straight:0,properti:1,durat:1,defin:[0,1],invok:1,error:1,advantag:0,unintuit:[],readm:[],blah:[],develop:0,parti:0,make:0,belong:1,cross:0,same:1,complex:0,document:[0,1],http:[],wherea:0,effect:1,hand:0,fairli:0,moment:[],rais:1,stack:[0,1],pymonkei:[0,1],off:[],macro:0,without:0,thi:[0,1],undefin:1,programm:0,model:0,capi:0,new_funct:1,just:[],less:0,nan:1,obtain:[],languag:0,web:0,easi:0,except:1,add:1,other:[0,1],around:0,read:0,swig:0,envis:0,know:[],world:0,bit:0,like:[0,1],vibrant:0,manual:0,resolv:0,server:0,collect:0,either:[],docutil:1,page:0,right:[],some:0,back:[],global:1,mirror:[],librari:0,rhino:0,refer:0,run:0,garbag:0,broken:0,repositori:0,about:0,central:[],unfortun:[],within:1,due:0,serverj:0,contributor:0,your:0,manag:[],span:1,wai:0,ergonom:0,custom:0,avail:0,interfac:1,low:1,lot:0,suit:0,beet:1,"function":[0,1],properli:0,offer:1,tupl:1,globalobj:1,eas:0,"true":1,count:0,made:0,possibl:[0,1],similar:0,featur:0,creat:[0,1],runtm:1,doesn:[0,1],repres:1,exist:[0,1],file:[0,1],check:[],probabl:0,floor:1,boop:[],todo:[],when:1,field:0,valid:0,test:0,you:[0,1],boof:[],matur:0,relat:1,eval:1,unbind:1,land:[0,1],sphinx:0,directori:[],obj:1,time:0},titles:["Pymonkey Documentation","<tt class=\"docutils literal docutils literal\"><span class=\"pre\">pymonkey</span></tt> &#8212; Access SpiderMonkey from Python"],modules:{pymonkey:1},descrefs:{"pymonkey.Runtime":{new_context:[1,0]},"pymonkey.Object":{get_runtime:[1,0]},"pymonkey.Context":{get_property:[1,0],get_object_private:[1,0],new_object:[1,0],call_function:[1,0],evaluate_script:[1,0],clear_object_private:[1,0],new_function:[1,0],get_runtime:[1,0],define_property:[1,0],init_standard_classes:[1,0]},pymonkey:{Function:[1,2],undefined:[1,3],Object:[1,2],Context:[1,2],error:[1,1],Runtime:[1,2]}},filenames:["index","pymonkey"]})
\ No newline at end of file
+Search.setIndex({desctypes:{"0":"method","1":"exception","2":"class","3":"data"},terms:{spidermonkei:[0,1],represent:1,all:0,code:[0,1],untrust:0,lack:0,concept:0,sleep:1,get_object_priv:1,privat:1,depend:0,readabl:0,program:1,isinst:1,liter:1,string:1,veri:[0,1],join:[],vast:0,level:1,"try":[0,1],eas:0,second:1,pass:1,casual:0,even:[],index:0,evaluate_script:1,abl:0,"while":1,access:[0,1],"new":1,objdir:[],method:1,metadata:1,involv:0,full:0,subtyp:1,never:0,new_object:1,here:0,objcec:[],path:[],valu:1,search:0,doctest:0,chang:1,tremend:0,via:[0,1],modul:[0,1],filenam:1,api:0,instal:0,test_pymonkei:[],from:[0,1],would:0,memori:0,init_standard_class:1,few:1,call:1,scope:1,type:1,more:[0,1],thisobj:1,mozilla:[0,1],ctype:0,known:0,central:[],must:0,none:1,retriev:1,setup:0,work:0,conceptu:1,abort:1,can:[0,1],learn:0,akin:0,root:0,fetch:0,def:1,give:0,process:0,challeng:0,sudo:0,indic:0,carrot:1,want:[0,1],alwai:0,goal:0,secur:[0,1],write:0,how:0,verifi:1,map:1,product:0,clone:[],usabl:0,befor:0,mai:1,associ:1,third:[0,1],counter:1,callback:1,sandbox:0,environ:0,enter:[],callabl:1,becaus:0,intermediari:0,through:1,dynam:0,platform:0,window:0,bypass:1,easier:0,them:0,within:1,"return":1,thei:[],python:[0,1],safe:1,now:[],xpcom:0,name:1,anyth:0,get_runtim:1,easili:0,trigger_operation_callback:1,trap:0,each:1,debug:[0,1],side:0,mean:0,compil:0,everyth:0,realli:0,ensur:0,"static":[],collector:0,out:0,path_to_objdir:[],profil:0,lineno:1,rational:0,print:1,forth:1,math:1,situat:0,free:[],standard:[0,1],reason:[],base:0,thrown:1,thread:1,traceback:0,first:1,oper:1,singleton:1,obviou:0,pyrex:0,feel:[],arrai:1,number:[0,1],get_properti:1,instruct:[],facil:0,given:1,script:[],interact:1,too:[0,1],"final":0,store:1,relationship:0,tool:[],huh:[],took:1,specifi:1,getter:1,than:0,wide:0,kind:[],target:1,provid:0,posit:1,browser:0,pre:1,falsi:1,arg:1,argument:1,packag:0,have:[0,1],tabl:0,need:0,"null":1,engin:[0,1],built:1,equival:1,inform:1,latter:[],client:0,note:[0,1],also:[0,1],ideal:0,exampl:1,take:1,which:[0,1],noth:[0,1],trace:1,object:[0,1],plai:0,"class":1,don:0,clear:1,later:1,doe:1,runtim:1,awesom:0,text:1,particularli:0,find:1,setter:1,define_properti:1,current:[0,1],onli:[0,1],just:[],solut:0,should:0,busi:0,contribut:0,pave:0,increas:0,requir:0,enabl:0,yield:1,contain:1,where:0,set:1,new_context:1,see:1,stop_running_cod:1,disadvantag:0,best:1,detect:0,someth:0,state:1,won:0,outstand:0,between:0,atul:0,"import":1,call_funct:1,watchdog_thread:1,javascript:[0,1],extens:0,preprocessor:0,complementari:0,come:1,easi:0,cycl:0,howev:0,blargh:[],instanc:[0,1],context:[0,1],logic:0,freeli:1,com:[],private_obj:1,simpli:[],sweep:0,header:0,assum:1,duplic:0,quit:0,java:0,creat:[0,1],three:1,been:1,mark:0,trigger:1,clear_object_priv:[0,1],ani:[0,1],togeth:1,func:1,straight:0,properti:1,durat:1,defin:[0,1],invok:1,error:1,advantag:0,unintuit:[],readm:[],contributor:0,blah:[],develop:0,perform:1,parti:0,make:0,belong:1,cross:0,same:1,complex:0,document:[0,1],http:[],wherea:0,effect:1,hand:0,fairli:0,moment:[],rais:1,stack:[0,1],pymonkei:[0,1],off:[],macro:0,without:0,thi:[0,1],undefin:1,programm:0,model:0,know:[],new_funct:1,execut:[0,1],less:0,when:1,obtain:[],yet:1,languag:0,web:0,expos:0,except:1,add:1,valid:0,build:0,around:0,read:0,swig:0,envis:0,capi:0,world:0,bit:0,like:[0,1],vibrant:0,manual:0,resolv:0,server:0,collect:[0,1],either:[],docutil:1,page:0,right:[],some:0,back:[],global:1,mirror:[],librari:0,rhino:0,refer:0,run:[0,1],garbag:[0,1],broken:0,set_operation_callback:1,repositori:0,about:0,actual:0,unfortun:[],js_initstandardclass:1,due:0,serverj:0,wrap:1,your:0,manag:[],span:1,wai:0,ergonom:0,"long":1,custom:0,avail:[0,1],start:1,interfac:1,low:1,lot:0,suit:0,beet:1,"function":[0,1],properli:0,offer:1,tupl:1,globalobj:1,line:1,"true":1,count:0,made:0,possibl:[0,1],similar:0,featur:0,evalu:1,runtm:1,doesn:[0,1],repres:1,exist:[0,1],file:[0,1],check:[],probabl:0,floor:1,boop:[],todo:[],nan:1,field:0,other:[0,1],test:0,you:[0,1],boof:[],matur:0,relat:1,eval:1,unbind:1,land:[0,1],sphinx:0,directori:[],obj:1,time:[0,1]},titles:["Pymonkey Documentation","<tt class=\"docutils literal docutils literal\"><span class=\"pre\">pymonkey</span></tt> &#8212; Access SpiderMonkey from Python"],modules:{pymonkey:1},descrefs:{"pymonkey.Runtime":{new_context:[1,0]},"pymonkey.Object":{get_runtime:[1,0]},"pymonkey.Context":{get_property:[1,0],get_object_private:[1,0],new_object:[1,0],call_function:[1,0],evaluate_script:[1,0],clear_object_private:[1,0],new_function:[1,0],get_runtime:[1,0],define_property:[1,0],trigger_operation_callback:[1,0],gc:[1,0],init_standard_classes:[1,0],set_operation_callback:[1,0]},pymonkey:{Function:[1,2],undefined:[1,3],Object:[1,2],Context:[1,2],error:[1,1],Runtime:[1,2]}},filenames:["index","pymonkey"]})
\ No newline at end of file
--- a/docs/src/pymonkey.txt	Mon Aug 17 03:02:51 2009 -0700
+++ b/docs/src/pymonkey.txt	Mon Aug 17 03:33:40 2009 -0700
@@ -76,13 +76,13 @@
       stored within the new JS object; it can be retrieved using
       :meth:`get_object_private()`.
 
-   .. method:: new_function(callable, name)
+   .. method:: new_function(func, name)
 
       Creates a new :class:`Function` instance that wraps the
       given Python callable.  In JS-land, the function will
       have the given name.
 
-      When the function is executed from JavaScript, `callable`
+      When the function is executed from JavaScript, `func`
       will be passed three positional arguments.
 
       The first argument is a :class:`Context` that represents the
@@ -196,6 +196,47 @@
       <https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JS_InitStandardClasses>`_,
       which this method wraps.
 
+   .. method:: gc()
+
+      Performs garbage collection on the context's JavaScript runtime.
+
+   .. method:: set_operation_callback(func)
+
+      Sets the operation callback for the context to the given Python
+      callable. The callback can be triggered via
+      :meth:`trigger_operation_callback()`.
+
+      `func` takes one argument: the context that triggered it.
+
+   .. method:: trigger_operation_callback()
+
+      Triggers the context's operation callback. If no callback has
+      yet been set, this function does nothing.
+
+      This function is one of the few thread-safe functions available
+      to a JS runtime, and together with
+      :meth:`set_operation_callback()` can be used to abort the
+      execution of long-running code.
+
+      For instance:
+
+        >>> import time, threading
+        >>> cx = pymonkey.Runtime().new_context()
+        >>> def stop_running_code(cx):
+        ...   raise Exception('JS took too long to execute.')
+        >>> cx.set_operation_callback(stop_running_code)
+        >>> def watchdog_thread():
+        ...   time.sleep(0.1)
+        ...   cx.trigger_operation_callback()
+        >>> thread = threading.Thread(target=watchdog_thread)
+        >>> thread.start()
+        >>> try:
+        ...   cx.evaluate_script(cx.new_object(), 'while (1) {}',
+        ...                      '<string>', 1)
+        ... except pymonkey.error, e:
+        ...   print cx.get_object_private(e.args[0])
+        JS took too long to execute.
+
 .. class:: Runtime()
 
    Creates a new JavaScript runtime. JS objects created by the runtime