473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Function.caller if not called from within a function

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
4 3606


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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Newsgroup - Ann | last post by:
Gurus, I have the following implementation of a member function: class A { // ... virtual double func(double v); void caller(int i, int j, double (* callee)(double)); void foo() {caller(1,...
2
by: Mark | last post by:
The situtation is that I'm trying to ensure that certain functions are only called by functions that I want them to be called from. I have a popup window which has a function which calls a function...
1
by: Yasutaka Ito | last post by:
Hi, Is there a way to programmatically find out the caller of your function? For example, let's say I have a function called MyFunction(), and I want to debug print the caller of this function...
1
by: TheOne | last post by:
I have two classes: class OntologyParser { ... protected: virtual void startElement(void *userData, const char *name, const char **atts); virtual void endElement(void *userData, const char...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
4
by: Danny Liberty | last post by:
Hi, I would like to be able to execute code when a function exits. In c++ I would have created an object on the stack in the function entry point and it's destructor would be called when the...
26
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null);...
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
3
by: william | last post by:
My situation is here: an array of two dimension can only be defined locally within a function(because the caller don't know the exact size ). Then the question is: how should the caller access...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.