Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get stack trace without arguments.caller property?

2 views
Skip to first unread message

Christopher Balz

unread,
Sep 20, 2001, 1:39:15 PM9/20/01
to
I've searched the doc, and it clearly tells how arguments.callee is
supported in JS1.5, but that arguments.caller is not. I noticed that
Rhino has access to a Context object; does JS1.5 do things that way?
Where should I look to learn how to get, for example, for a stack trace
without being able to use arguments.caller? I do large app's in
JavaScript and need a stack trace.
Hope someone has a brief answer.
Thank you.
- Christo...@yahoo.com

Norris Boyd

unread,
Sep 20, 2001, 1:56:20 PM9/20/01
to Christopher Balz, mozill...@mozilla.org
If you're just looking for a stack trace in a string and you're in
compilation mode, you can use
(new java.lang.Exception()).printStackTrace();
You should be able to see the source names passed in for compilation in
the stack trace.

If you're in interpretive mode, the only API for this information is the
debug API. The information isn't kept for performance reasons unless a
debugger is attached. See org.mozilla.javascript.debug.DebuggableEngine,
methods getFrameCount and getFrame.

--N

John Bandhauer

unread,
Sep 20, 2001, 2:18:43 PM9/20/01
to

Ah, sorry, you've asked twice.

Norris answered for Rhino. I thought you were asking about Spidermonkey.
Brendan might offer a better amswer, but... For a simple stack trace
you can use function.caller...

js> function f(){for(c = arguments.callee; c; c = c.caller){print(c.name);}}
js> function g() {f();}
js> function h() {g();}
js> function i() {h();}
js> i()
f
g
h
i
js>

This gets you the strack trace of the functions, but not access to the call
objects - the arguments objects - of each caller. As I understand things
that is being intensionally hidden from running JS code.

Hope this help,

John.

0 new messages