[Project_owners] Q: how to access calling XUL window from XPCOM component code?

Godmar Back godmar at gmail.com
Thu Feb 5 05:55:57 PST 2009

On Wed, Feb 4, 2009 at 12:39 PM, Malte Kraus <firefox at maltekraus.de> wrote:
>> Is it possible to walk the stack in some way in case the function is
>> called indirectly along a chain of calls, as in
>> 'name.caller.caller....' until a __parent__ property is found?
> Sure:
> var caller = arguments.callee.caller;
> var globalObject = {}.__parent__;
> while(caller.__parent__ != globalObject) {
>  caller = caller.caller;
> }

Turns out this approach is not very useful since 'caller' appears to
be defined only if the calling function is defined via a 'function
name() { }' statement.  If the calling function is defined via
variable assignment as in name = function (), or if the call occurs in
a top-level context, caller is null and no parent property can be

Aside from that, I don't understand the intent of "caller.__parent__
!= globalObject" - are you trying to walk up the call chain until the
function's __parent__ is equal to the current function's global

I also tried using the nsIStackFrame
interface, but it appears that these stack frames do not have a
__parent__, nor do they contain a reference to the Function object
that's being associated with each frame.

 - Godmar

More information about the Project_owners mailing list