onreadystatechange not handline "this" correctly inside of Objects

RESOLVED INCOMPLETE

Status

()

Firefox
General
RESOLVED INCOMPLETE
9 years ago
7 years ago

People

(Reporter: Christopher McCulloh, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [CLOSEME 2010-11-01])

(Reporter)

Description

9 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3

This is probably related to bug #393221 in some way.

When referenced from inside of a parent function, the function specified for onreadystatechange does not view itself as being inside of that parent function. Therefor, the parent function's properties can not be accessed from inside of the function. The function views itself as a standalone function, not part of the parent function when called from onreadystatechange.

Here is an example:

convertLink("http://www.google.com");
function convertLink(oldLink){
	var url = "linkConverter.html";
	var newLink;
	request.open("POST", url, false);
	request.onreadystatechange = function(){
		if(request.readyState == 4){
			if(request.status == 200){
				newLink = request.responseText;
			}
		}
	}
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	request.send("url=" + oldLink);

	alert(newLink);
	return newLink;			
}


Reproducible: Always

Steps to Reproduce:
1. Take the code from the details and place it inside of a blank html page (inside <script type="text/javascript"></script> tags).
2. Create a "linkConverter.html" page that just returns a URL
3. Load the blank html page in the browser
Actual Results:  
Nothing happens.

Expected Results:  
an alert box appears with your converted URL. (This is the way it works in IE7 and Google Chrome)

The software should have treated the onreadystatefunction as a member of the convertLink() function and used the local newLink variable from the convertLink() function in the onreadystatechange function.

Comment 1

9 years ago
Your bug looks like it could be this: 
https://bugzilla.mozilla.org/show_bug.cgi?id=313646

"synchronous XMLHttpRequest does not fire 'readystatechange' event"

I believe they plan to fix it when they can.

Comment 2

9 years ago
bug 313646 is about something else.
At least per summary this bug is about the 'this', though seems like this is
about scope.

Anyway, this is code which has changed since 3.0. Anyone willing to re-try
with 3.1beta ?

And a minimal working testcase would be great.

Comment 3

9 years ago
Well, bug 313646 is definitely a problem here because his "newLink" variable won't get set in synchronous mode... So maybe you have two problems then?

Both can be worked around though by FF users like me, so that's the good news.  (I posted a source example over at 313646 if anybody needs; plugged snippets of it in the above example and seems to work fine).

And just wondered but isn't the example code above enough of a test case??
But good luck, I know you guys are deluged with bug reports.  Hope somebody on the ff dev team payroll can fix this other user's bug somehow.
This is a mass search for bugs which are in the Firefox General component, are
UNCO, have not been changed for 500 days and have an unspecified version. 

Reporter, can you please update to Firefox 3.6.10 or later, create a fresh profile, http://support.mozilla.com/en-US/kb/managing+profiles, and test again. If you still see the issue, please update this bug. If the issue is gone, please set the status to RESOLVED > WORKSFORME.
Whiteboard: [CLOSEME 2010-11-01]
No reply from reporter, INCOMPLETE. Please retest with Firefox 3.6.12 or later and a new profile (http://support.mozilla.com/kb/Managing+profiles). If you continue to see this issue with the newest firefox and a new profile, then please comment on this bug.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.