Closed Bug 360267 Opened 18 years ago Closed 18 years ago

Javascript: Cannot add members (i.e. functions) to Function.prototype

Categories

(Firefox :: General, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 355161

People

(Reporter: raoul, Unassigned)

Details

Attachments

(3 files)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de; rv:1.8.1) Gecko/20061010 Firefox/2.0 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; de; rv:1.8.1) Gecko/20061010 Firefox/2.0 It is not stable to enhance Function.prototype in a new opened window within a javascript file. i.e. main.html opens new.html and new.html includes inc.js and in inc.js you have Function.prototype.bind=function .. A call to function(){}.bind() will fail in 50% on a windows-system (I checked it out on 3 systems). It seems to be OK on mac and linux systems. Reproducible: Sometimes Steps to Reproduce: 1. create 3 files: main.html, new.html and inc.js (see below) 2. open main.html 3. if there are no errors click the link in main.html and try again Actual Results: ERROR: test OK: test2 Expected Results: OK: test OK: test2 ##################################################### main.html ##################################################### <html> <head> <script> function doit() { window.open('new.html','width=100,height=100'); } </script> </head> <body onload="doit();"> <a href="#" onclick="javascript:doit();return false;"> Click here to open the window </a> </body> </html> ##################################################### new.html: ##################################################### <html> <head> <script type="text/javascript"> /* save a handle for test2() */ var FUNCTION_PROTOTYPE = Function.prototype; var str = ""; </script> <script type="text/javascript" src="inc.js"></script> <script type="text/javascript"> var func = function() {}; try { /* this causes an error in 50% off all tests */ func.test(); str += "OK: test\n"; } catch (e) { str += "ERROR: test\n"; } try { /* this seems to be fine */ func.test2(); str += "OK: test2\n"; } catch (e) { str += "ERROR: test2\n"; } alert(str); /* close the window so it's easier to test */ window.close(); </script> </head> <body>...</body> </html> ##################################################### inc.js ##################################################### /* this can cause a problem */ Function.prototype.test=function(){ /* ... */ }; /* a saved reference to Function.prototype seems to be ok */ if (FUNCTION_PROTOTYPE) FUNCTION_PROTOTYPE.test2 = Function.prototype.test; #####################################################
Attached file open this file
Comment on attachment 245219 [details] open this file ><HTML><HEAD> > > <SCRIPT> > function doit() { > window.open('http://bugzilla.mozilla.org/attachment.cgi?id=245217','width=100,height=100'); > } > </SCRIPT></HEAD><BODY onload="doit();"> > <A onclick="javascript:doit();return false;" href="#"> > Click here to open the window > </A> > ></BODY></HTML>
Please try either a nightly Firefox 2.0.0.1 <http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-mozilla1.8/> build or a trunk build <http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/> to verify the fix. *** This bug has been marked as a duplicate of 355161 ***
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → DUPLICATE
(In reply to comment #5) > Please try either a nightly Firefox 2.0.0.1 It seems to be fixed. I cannot reproduce the malicious behaviour with an actual nightly build.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: