By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,905 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,905 IT Pros & Developers. It's quick & easy.

Function.caller if not called from within a function

P: n/a
Hi,

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?

Greetings,
Thomas

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


Thomas Mlynarczyk wrote:

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:

<html lang="en">
<head>
<title>caller property of function</title>
<script type="text/javascript">
function f () {
var result = 'function f called : ';
result += 'typeof f.caller: ' + (typeof f.caller) + '; ';
result += 'f.caller: ' + f.caller;
document.write('<p>' + result + '<\/p>\r\n');
}
function g () {
f();
}
</script>
</head>
<body>

<h1>caller property of function</h1>

<script type="text/javascript">
f();
</script>

<script type="text/javascript">
g();
</script>

</body>
</html>

Output is

function f called : typeof f.caller: object; f.caller: null

function f called : typeof f.caller: function; f.caller: function g() {
f(); }

and I see nothing wrong with that, there is certainly no hang.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

P: n/a
Also sprach Martin Honnen:
What kind of access do you try?
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:
[code]
Output is
function f called : typeof f.caller: object; f.caller: null
function f called : typeof f.caller: function; f.caller: function g() { f(); } and I see nothing wrong with that, there is certainly no hang.


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.

Jul 23 '05 #3

P: n/a


Thomas Mlynarczyk wrote:

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, 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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4

P: n/a
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?
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.