Browse Source

guide updates on Duktape.line() and Duktape.act()

pull/2/head
Sami Vaarala 11 years ago
parent
commit
b6d341ae1e
  1. 57
      website/guide/duktapebuiltins.html

57
website/guide/duktapebuiltins.html

@ -378,6 +378,63 @@ debugging and diagnosis, e.g. when estimating rough memory usage of objects.</p>
</table>
</div>
<h3>line()</h3>
<p>Get the line number of the call site. This may be useful for debugging, e.g.:</p>
<pre class="ecmascript-code">
log.info('reached line:', Duktape.line());
</pre>
<div class="note">
As <code>Duktape.act()</code> provides more information, this function
will probably be removed.
</div>
<h3>act()</h3>
<p>Get information about a call stack entry. Takes a single number argument
indicating depth in the call stack: -1 is the top entry, -2 is the one below
that etc. Returns an object describing the call stack entry, or <code>undefined</code>
if the entry doesn't exist. Example:</p>
<pre class="ecmascript-code">
function dump() {
var i, t;
for (i = -1; ; i--) {
t = Duktape.act(i);
if (!t) { break; }
print(i, t.lineNumber, t.function.name, Duktape.enc('jsonx', t));
}
}
dump();
</pre>
<p>The example, when executed with the command line tool, currently prints
something like:</p>
<pre>
-1 0 act {lineNumber:0,pc:0,function:{_func:true}}
-2 4 dump {lineNumber:4,pc:16,function:{_func:true}}
-3 10 global {lineNumber:10,pc:5,function:{_func:true}}
</pre>
<p>The interesting entries are <code>lineNumber</code> and <code>function</code>
which provides e.g. the function name.</p>
<p>You can also implement a helper to get the current line number using
<code>Duktape.act()</code>:</p>
<pre class="ecmascript-code">
function getCurrentLine() {
// indices: -1 = Duktape.act, -2 = getCurrentLine, -3 = caller
var a = Duktape.act(-3) || {};
return a.lineNumber;
}
print('running on line:', getCurrentLine());
</pre>
<div class="note">
The properties provided for call stack entries may change between versions.
</div>
<h3>gc()</h3>
<p>Trigger a forced mark-and-sweep collection. If mark-and-sweep is disabled,

Loading…
Cancel
Save