This bug grew out of bug 83293. Bug 83293 addressed this: 'abc'.replace('', 'Z') should be 'Zabc' SpiderMonkey gave no return. Here we consider this: 'abc'.replace(undefined, 'Z') should be 'abc' SpiderMonkey returns 'Zabc' Both bugs derive from ECMA-262 Final Edition, Section 126.96.36.199 String.prototype.replace (searchValue, replaceValue) The Final Edition states that searchValue, if not of type RegExp, should be converted to String(searchValue), and the replace() method should then search for the first occurrence of this string and replace it. So, since String(undefined) == 'undefined', and there is no occurrence of 'undefined' in the string 'abc', we should have: 'abc'.replace(undefined, 'Z') == 'abc'
Note: the ECMA Final Edition differs vis-a-vis the ECMA Final Draft on the syntax for the replace() method, and is inconsistent with the Final Edition syntax for the related methods search(), match() of String.prototype in the case where searchValue is not of type RegExp. See bug 83293 for details. The testcase for this bug is js/tests/ecma_3/String/regress-83293.js
Retargeting for 9.8.
Created attachment 68823 [details] [diff] [review] proposed Hoping kenton doesn't mind the intrusion, I was working on related stuff and believe simply taking out the special handling for 'undefined' will do the job...
Comment on attachment 68823 [details] [diff] [review] proposed Patch is not up to date with respect to the cvs trunk, but no worries -- just update before you commit, no need for another patch. email@example.com. /be
Comment on attachment 68823 [details] [diff] [review] proposed r=khanson
Fix checked in.
Marking Verified FIXED. The testcase above, ecma_3/String/regress-83293.js, now passes in the debug/optimized JS shell on WinNT, Linux, and Mac9.1.