Closed Bug 468250 Opened 17 years ago Closed 13 years ago

JavaScript this keyword does not resolve correctly in SeaMonkey

Categories

(Core :: JavaScript Engine, defect)

1.8 Branch
x86
Windows Vista
defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: tboronczyk, Unassigned)

Details

(Whiteboard: js-triage-needed)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.18) Gecko/20081031 SeaMonkey/1.1.13 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.18) Gecko/20081031 SeaMonkey/1.1.13 I apologize if this may be a duplicate bug report, but I'm sure you'll forgive me and understand the frustration of searching for something that contains "this" as an important keyword that lead me to submit this report perhaps without due-diligent research. It doesn't appear the JavaScript runtime in SeaMonkey is properly dereferencing the "this" keyword to an object when it appears within an anonymous function passed as an argument to another function which then binds the anonymous function to the object as an event handler. Reproducible: Always Steps to Reproduce: Here is a small sample of JavaScript code that reproduces the error: // encapsulate performing a request using an XMLHttpRequest object function doXMLHttpRequest(method, url, data, callback) { var http; if (typeof XMLHttpRequest != 'undefined') { http = new XMLHttpRequest(); } else if (window.ActiveXObject) { var vers = ['Microsoft.XmlHttp', 'MSXML2.XmlHttp', 'MSXML2.XmlHttp.3.0', 'MSXML2.XmlHttp.4.0', 'MSXML2.XmlHttp.5.0']; for (var i = vers.length - 1; i >= 0; i--) { try { http = new ActiveXObject(vers[i]); break; } catch(e) {} } } // perform GET request if (method == 'GET') { http.open('GET', url, true); http.onreadystatechange = callback; http.send(null); } // perform POST request else if (method == 'POST') { http.open('POST', url, true); http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); http.setRequestHeader('Content-Length', data.length); http.setRequestHeader('Connection', 'close'); http.onreadystatechange = callback; http.send(data); } } // retrieve data and do something with it doXMLHttpRequest('GET', 'example-fetch.php', null, function() { alert(this); // if (this.readyState == 4 && this.responseText) { // document.getElementById('myDiv').innerHTML = this.responseText; // } }); Actual Results: Seamonkey displays the function definition. function() { alert(this); } But in other browsers, "this" is a reference to the XMLHttpRequest object. IE: [object] Firefox, Chrome, Opera: [object XMLHttpRequest] Safari: [object JSXMLHttpRequest] Expected Results: I would expect that the results would be consistent with that of the other browsers when the script is run in SeaMonkey. This behavior is not limited to the Windows build; the same unexpected behavior has been observed in the latest Linux build as well.
Can you reproduce with SeaMonkey v2.0a1 / current v2.0a2pre ? Which Firefox version did you test ?
Version: unspecified → SeaMonkey 1.1 Branch
Firefox version string: "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4" Downloaded and installed SeaMonkey 2.0 Alpha 1 from http://www.seamonkey-project.org/releases/2.0a1. "this" resolves as expected in 2.0a1, and is NOT reproducible in that version.
Assignee: nobody → general
Component: General → JavaScript Engine
Product: SeaMonkey → Core
QA Contact: general → general
Version: SeaMonkey 1.1 Branch → 1.8 Branch
Whiteboard: js-triage-needed
marking wfm based on comment #2
Status: UNCONFIRMED → RESOLVED
Closed: 13 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.