RobG wrote:[color=blue]
> Csaba Gabor said on 21/03/2006 4:03 AM AEST:[color=green][color=darkred]
> >>RobG said on 20/03/2006 3:51 PM AEST:
> >>>Csaba Gabor said on 20/03/2006 8:10 AM AEST:
> >>>>Inside a function, I'd like to know the call stack. By this I mean
> >>>>that I'd like to know the function that called this one, that one's
> >>>>caller and so on.[/color]
> > ...[/color]
> Ah, I think that holds the key. The caller property references the
> function object, not the activation object that the now removed
> __caller__ property referred to.
>
> Following is a Brendan Eich comment on Mozilla 0.9 (2001-01-10):
>
> "All traces of a caller property were removed a while ago,
> to follow ECMA-262 and to avoid any chance of a security exploit.
> The removal seems to me to have been overzealous, because it axed
> the caller property of function objects *and* the
> much-more-exploitable caller (or __caller__) property of
> activation objects.
>
> "Confirming, we should consider restoring the caller property
> of function objects for old time's sake (JScript imitated it
> faithfully in cloning JS1.1, where it originated)."
>
>
> I suppose that for a recursive function, each recursion has the same
> function object but different activation object. If you could reference
> the activation object, then you could climb any stack. But Brendan's
> comment says that support for __caller__ was removed long ago.
>
>[color=green]
> > So I'm really wondering whether I'm missing an angle on this, cause I
> > just don't see the rationale. It's does not seem to be a security
> > issue because arguments.callee.caller of the first call into the
> > recursive function can reach out to its caller.[/color]
>
> I think getting a reference to the activation object was seen as a
> potential security exploit, hence caller was reinstated but not __caller__.[/color]
To be clear on what is happening [it is as you say], arguments.callee
returns the original function object (and by that I mean the reference
that you get when you define:
function foo(...) {...}
I tested this by calling a function and in the function doing
arguments.callee.funcProp="frob" and checking foo.funcProp after
finishing the function call and sure enough, there was "frob".
The implication is that each time a call is made the function object
has a property, .caller, placed on it that points to the calling
function object ** for the duration of that call **. Sure enough, this
checks out too.
Frankly, this seems like a really whacked out way to go. I haven't
seen anything so far to give me notions to the contrary. Appears to me
that what is needed is a property of arguments that is essentially
..parent, which would point to the arguments object of the activation
object that called this one. In this fashion there would not even need
to be a .caller property anymore, considering that .caller on the
original function object is a crutch anyway (ie. the interpreter is not
making use of it).
Csaba
By the way, Eric Lippert has a really interesting read about activation
objects, execution variables, scopes, this, and more at:
http://blogs.msdn.com/ericlippert/ar...04/414684.aspx