Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Function.caller if not called from within a function

Reply
Thread Tools

Function.caller if not called from within a function

 
 
Thomas Mlynarczyk
Guest
Posts: n/a
 
      02-26-2005
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



 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      02-26-2005


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/
 
Reply With Quote
 
 
 
 
Thomas Mlynarczyk
Guest
Posts: n/a
 
      02-26-2005
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.



 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      02-26-2005


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/
 
Reply With Quote
 
Thomas Mlynarczyk
Guest
Posts: n/a
 
      02-26-2005
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?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is a button Click event also called when a textbox TextChanged event is called??? S_K ASP .Net 6 11-08-2007 07:44 PM
template member function can be called from outside class but not within er C++ 2 09-13-2007 06:56 PM
What is called carry chain structure in FPGA is called in IC? Weng Tianxiang VHDL 6 09-12-2007 07:19 AM
Can a function be called within a function ? Peter Moscatt Python 4 04-18-2005 09:33 PM
three times copy ctor called, one ctor called, why? Apricot C++ 4 04-16-2004 07:55 AM



Advertisments