michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: var BUGNUMBER = 501739; michael@0: var summary = michael@0: "String.prototype.relace should zero the .lastIndex when called with a " + michael@0: "global RegExp"; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: var s = '0x2x4x6x8'; michael@0: michael@0: var p1 = /x/g; michael@0: p1.lastIndex = 3; michael@0: s.replace(p1, ''); michael@0: assertEq(p1.lastIndex, 0); michael@0: michael@0: var p2 = /x/g; michael@0: p2.lastIndex = 3; michael@0: var c = 0; michael@0: s.replace(p2, function(s) { michael@0: assertEq(p2.lastIndex++, c++); michael@0: return 'y'; michael@0: }); michael@0: assertEq(p2.lastIndex, 4); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");