473,216 Members | 1,279 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,216 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 3599


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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.