Function.caller if not called from within a function

I stumbled over a strange behaviour of Mozilla. When I want to access the
caller property of a function that was not called from within another
function, Mozilla seems to abort the script. No error message, no hang, just
stopping script execution at that point. Why? And what is the remedy?

Advertisements

> I stumbled over a strange behaviour of Mozilla. When I want to access the
> caller property of a function that was not called from within another
> function, Mozilla seems to abort the script. No error message, no hang, just
> stopping script execution at that point. Why? And what is the remedy?

What kind of access do you try? Of course if there is no caller that
property is null so you can't do much with it.

The following test case works for me without problems in Firefox 1.0 and
in some recent Mozilla nightly:

Advertisements

Basically the same way as in your example code.
> Of course if there is no caller that property is null so you can't do much
with it.

But if I call "caller" and it doesn't exist, I should get an error message,
which does not happen.
> The following test case works for me without problems in Firefox 1.0
> and in some recent Mozilla nightly:

OK, these are not the most recent versions of both browers and I can cope
with the "undefined" case, but that Mozilla 1.1a thing is annoying - there
is no error message and it seems the whole function call is aborted. Even
when I comment out the line which actually accesses f.caller, the result is
the same - merely asking for the type of f.caller causes the problem.

> Mozilla 1.1a (Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.1a)
> Gecko/20020611) only shows the second line of the output.
> Netscape 6 (Mozilla/5.0 (Windows; U; Win98; de-DE; PC-Welt-DE)
> Gecko/20001106 Netscape6/6.0) says typeof f.caller is undefined (for both
> calls).
>
> OK, these are not the most recent versions of both browers and I can cope
> with the "undefined" case, but that Mozilla 1.1a thing is annoying - there
> is no error message and it seems the whole function call is aborted. Even
> when I comment out the line which actually accesses f.caller, the result is
> the same - merely asking for the type of f.caller causes the problem.

As for Netscape 6, yes, bughttps://bugzilla.mozilla.org/show_bug.cgi?id=65683 suggests that at that
time function.caller was not implemented at all which is fine I think,
it is not required by the ECMAScript standard.
I can understand that the Mozilla 1.1a behavior you find hurts your
script attempts but obviously that problem has been fixed in later
releases so there is not much to do about that now. I think bughttps://bugzilla.mozilla.org/show_bug.cgi?id=168081 covers the problem
and got somehow fixed by other changes without anyone trying to fix it.

Also sprach Martin Honnen:
> As for Netscape 6, yes, bug
> https://bugzilla.mozilla.org/show_bug.cgi?id=65683 suggests that at
> that time function.caller was not implemented at all which is fine I
> think, it is not required by the ECMAScript standard.
> I can understand that the Mozilla 1.1a behavior you find hurts your
> script attempts but obviously that problem has been fixed in later
> releases so there is not much to do about that now. I think bug
> https://bugzilla.mozilla.org/show_bug.cgi?id=168081 covers the problem
> and got somehow fixed by other changes without anyone trying to fix
> it.

So there's no way for Mozilla 1.1a to make it at least behave as if it did
not support Function.caller if the function wasn't called from within
another function?

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!