Function toString method very, very broken (Safari, JavaScript)
=============================================
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