Function.caller if not called from within a function

T

Thomas Mlynarczyk

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
 
M

Martin Honnen

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

Thomas Mlynarczyk

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.[/QUOTE]

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

Martin Honnen

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

Thomas Mlynarczyk

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top