Function toString method very, very broken (Safari, JavaScript)

I submitted the following in Bug Reporter (#5359265) but no response yet and I am hoping someone could tell me if it has been fixed. It is a major pain in the rear, Safari seems to go out of its way to be difficult.

=============================================

Summary:
In JavaScript, the toString method of a Function object is supposed to return useable code. In Safari (at least as far as I have been able to upgrade software), numerous flaws in the returned code string prevent it from being usable.

Steps to Reproduce:
1. Create a web page with the following script:
function f()
{
for (var i=0;i<10;i++)
"asdf\"fdsa".replace(/asdf/g,'1"2');
var x={asdf:"",sss:"ss","dd.d":2};
var y=[1,2,3,4];
var z="Please\nfix!";
}
alert(f);

Expected Results:
Open the page in any browser except Safari. The alerted value will be exactly the same as the code above.

Actual Results:
Open the page in Safari. The alerted value will be:
function f()
{
for (i = 0; i < 10; i++)
"asdf"fdsa".replace(asdf,"");
var x = { asd:""sss:"ss"dd.d:2 };
var y = [1234];
var z="Please
fix!";
}
Note the exceptional number of missing vital pieces in the string code:
1. The var statement in front of the i in the for loop.
2. The \ escaping the " in the first string.
3. The / needed at each end of the regular expression declaration.
4. The g needed to declare the global flag of the regular expression.
5. The single quotes defining the replacement string were changed to
double quotes, and the string will no longer compile.
6. The , delimiting the properties of the object declaration.
7. The " surrounding the "dd.d" property name, the object will
not compile without them because of the period in the name.
8. The , delimiting the values in the array declaration.
9. The \n instead of a newline character, as the string will not
compile on separate lines.

Regression:
Safari 1.2 (v125) to 1.3.2 (v312.6), the latest available for me to download on OS 10.3.9 (7W98).

Notes:
No workarounds that I can see. The bug is a serious issue for some AJAX foundations. It is detrimental one to the foundation I use. I hope you all can fix this.

Strawberry one piece, Mac OS X (10.3.9), Ebay special

Posted on Aug 1, 2007 4:48 PM

Reply
3 replies

Aug 1, 2007 4:57 PM in response to snesin

Well that is just perfect. The forums are broken too. Why are indented lines deleted?

I will try again:
Original function (with no indenting):

function f()
{
for (var i=0;i<10;i++)
"asdf\"fdsa".replace(/asdf/g,'1"2');
var x={asdf:"",sss:"ss","dd.d":2};
var y=[1,2,3,4];
var z="Please\nfix!";
}
alert(f);

Bad code returned from Safari:

function f()
{
for (i = 0; i < 10; i++)
"asdf"fdsa".replace(asdf,"");
var x = { asd:""sss:"ss"dd.d:2 };
var y = [1234];
var z="Please
fix!";
}

Missing vital pieces:

Note the exceptional number of missing vital pieces in the string code:
1. The var statement in front of the i in the for loop.
2. The \ escaping the " in the first string.
3. The / needed at each end of the regular expression declaration.
4. The g needed to declare the global flag of the regular expression.
5. The single quotes defining the replacement string were changed to double quotes, and the string will no longer compile.
6. The , delimiting the properties of the object declaration.
7. The " surrounding the "dd.d" property name, the object will not compile without them because of the period in the name.
8. The , delimiting the values in the array declaration.
9. The \n instead of a newline character, as the string will not compile on separate lines.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Function toString method very, very broken (Safari, JavaScript)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.