Browse Source

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

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

59
website/guide/duktapebuiltins.html

@ -56,7 +56,7 @@ does not block.</p>
<tr><td class="propname">dec</td><td>Decode a value (hex, base-64, JSONX, JSONC): <code>Duktape.dec('base64', 'Zm9v')</code>.</td></tr>
<tr><td class="propname">info</td><td>Get internal information (such as heap address and alloc size) of a value in a version specific format.</td></tr>
<tr><td class="propname">line</td><td>Get current line number.</td></tr>
<tr><td class="propname">act</td><td>Get information about callstack entry.</td></tr>
<tr><td class="propname">act</td><td>Get information about call stack entry.</td></tr>
<tr><td class="propname">gc</td><td>Trigger mark-and-sweep garbage collection.</td></tr>
<tr><td class="propname">compact</td><td>Compact the memory allocated for a value (object).</td></tr>
<tr><td class="propname">errcreate</td><td>Callback to modify/replace a created error.</td></tr>
@ -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,

2
website/guide/limitations.html

@ -197,7 +197,7 @@ There are a few limitations, though:</p>
may be left in a non-<code>null</code> state even after coroutine call
stacks have been fully unwound. Also, if a coroutine is garbage collected
before its call stack is unwound, the <code>caller</code> property of
functions in its callstack will not get updated now.</li>
functions in its call stack will not get updated now.</li>
</ul>
<p>See the internal <code>test-bi-function-nonstd-caller-prop.js</code> test

Loading…
Cancel
Save