.toString() method on Functions is removing certain strings

RESOLVED INCOMPLETE

Status

()

--
major
RESOLVED INCOMPLETE
10 years ago
9 years ago

People

(Reporter: rowan.laurence, Unassigned)

Tracking

2.0 Branch
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(URL)

(Reporter)

Description

10 years ago
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

Comment 1

10 years ago
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/ )?
(Reporter)

Comment 3

10 years ago
As does mine I think

Comment 4

10 years ago
I have tried this in 3.0.2, which doesn't exhibit the same issue.  Have not tried in 3.1 yet.
(Reporter)

Comment 5

10 years ago
This only happens in 2.0.0.17
(Reporter)

Updated

10 years ago
Version: unspecified → 2.0 Branch
(Reporter)

Updated

10 years ago
Hardware: PC → All
(Reporter)

Updated

10 years ago
OS: Windows XP → All

Comment 6

10 years ago
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).

Comment 7

9 years ago
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
Last Resolved: 9 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.