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.match should throw when called with a global RegExp " + michael@0: "whose .lastIndex is non-writable"; 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: // First time with .lastIndex === 0 michael@0: michael@0: var p1 = /x/g; michael@0: Object.defineProperty(p1, "lastIndex", { writable: false }); michael@0: michael@0: try michael@0: { michael@0: s.match(p1); michael@0: throw "didn't throw"; michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e instanceof TypeError, true, michael@0: "should have thrown a TypeError, instead got: " + e); michael@0: } michael@0: michael@0: // Second time with .lastIndex !== 0 michael@0: michael@0: var p2 = /x/g; michael@0: Object.defineProperty(p2, "lastIndex", { writable: false, value: 3 }); michael@0: michael@0: try michael@0: { michael@0: s.match(p2); michael@0: throw "didn't throw"; michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e instanceof TypeError, true, michael@0: "should have thrown a TypeError, instead got: " + e); michael@0: } michael@0: michael@0: // Third time with .lastIndex === 0, no matches michael@0: michael@0: var p3 = /q/g; michael@0: Object.defineProperty(p3, "lastIndex", { writable: false }); michael@0: michael@0: try michael@0: { michael@0: s.match(p3); michael@0: throw "didn't throw"; michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e instanceof TypeError, true, michael@0: "should have thrown a TypeError, instead got: " + e); michael@0: } michael@0: michael@0: // Fourth time with .lastIndex !== 0, no matches michael@0: michael@0: var p4 = /q/g; michael@0: Object.defineProperty(p4, "lastIndex", { writable: false, value: 3 }); michael@0: michael@0: try michael@0: { michael@0: s.match(p4); michael@0: throw "didn't throw"; michael@0: } michael@0: catch (e) michael@0: { michael@0: assertEq(e instanceof TypeError, true, michael@0: "should have thrown a TypeError, instead got: " + e); michael@0: } michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");