Closed Bug 457000 Opened 16 years ago Closed 15 years ago

.toString() method on Functions is removing certain strings

Categories

(Firefox :: File Handling, defect)

2.0 Branch
defect
Not set
major

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: rowan.laurence, Unassigned)

References

()

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.17) Gecko/20080829 Firefox/2.0.0.17
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.17) Gecko/20080829 Firefox/2.0.0.17

if a while loop is in a function that you want to set toString()

e.g.

 for (var prop in config) {
       if (prop == "flashId") continue;
       if (typeof(config[prop]) == "function" || typeof(config[prop]) == "object") continue;
       
       configItems += "&" + prop + "=" + escapeValue(config[prop]);
    }

When it comes back from the toString method it looks like

for(config) {..}

removing the 'var prop in' String





Reproducible: Always

Steps to Reproduce:
1.create a function with the above code then use functionName.toString()
2.see the difference between the function and the string
3.
Actual Results:  
Skips out the code 'var prop in' from the while loop

Expected Results:  
Should send the whole function back as a string with no missing code
I've seen the exact same thing, except mine is changed to a while.  The example we have is:

for (var g in animationGroup) {
   animationGroup[g].update;
}

which, when run through .toString() becomes:

while (animationGroup) {
   animationGroup[g].update;
}
Have you also tested the latest release, Firefox 3 ( http://www.mozilla.com/en-US/ )or the latest 3.1 test build ( http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-mozilla-central/ )?
As does mine I think
I have tried this in 3.0.2, which doesn't exhibit the same issue.  Have not tried in 3.1 yet.
This only happens in 2.0.0.17
Version: unspecified → 2.0 Branch
Hardware: PC → All
OS: Windows XP → All
I'm seeing the identical (bad) behavior as well.  It's only in 2.0.0.17 (as well as the .18 nightly).  3.0.3 does not suffer the problem, nor does the latest 3.1b1 nightly I downloaded.  Have only tried on a couple of XP boxes.

A quick test for this is as follows (paste into URL entry bar):

javascript:alert((function test() { for (var x in {}); }).toString());

If you get a for loop, you're fine.  If you get a while loop, it's busted.

In the Echo3 web framework, we're relying on function.toString() to generate duplicates of functions.  This is done to avoid having to create closures that wrap function.apply() in our JS inheritance code.  It makes things a bit quicker (especially in clunky old browsers like IE6).  Ecma262v3 does spec that function.toString() return an implementation specific string representation of a function.

If we shouldn't be using this, I'm happy to switch to closure-apply() style (fortunately it's only used in one critical place :D).
This bug was reported using a version of Firefox that security and stability updates are no longer provided for.  All users are strongly encouraged to upgrade to Firefox 3 by selecting 'Check for Updates' in the Help menu or by going to http://www.mozilla.com/en-US/firefox/firefox.html

If you can no longer reproduce this bug using the latest Firefox 3.0.x version, please change the status of this bug to 'RESOLVED' 'WORKSFORME'.

If you can still reproduce this bug, please provide additional details to help resolve this issue.
No reply, INCOMPLETE. Please reply if you can still reproduce this bug with Firefox 3.5.3 or later in a new profile with the latest plugins (flash, quicktime, java, etc.).
Status: UNCONFIRMED → RESOLVED
Closed: 15 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.