|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/licenses/publicdomain/ |
|
4 */ |
|
5 |
|
6 var BUGNUMBER = 501739; |
|
7 var summary = |
|
8 "String.prototype.match should throw when called with a global RegExp " + |
|
9 "whose .lastIndex is non-writable"; |
|
10 |
|
11 print(BUGNUMBER + ": " + summary); |
|
12 |
|
13 /************** |
|
14 * BEGIN TEST * |
|
15 **************/ |
|
16 |
|
17 var s = '0x2x4x6x8'; |
|
18 |
|
19 // First time with .lastIndex === 0 |
|
20 |
|
21 var p1 = /x/g; |
|
22 Object.defineProperty(p1, "lastIndex", { writable: false }); |
|
23 |
|
24 try |
|
25 { |
|
26 s.match(p1); |
|
27 throw "didn't throw"; |
|
28 } |
|
29 catch (e) |
|
30 { |
|
31 assertEq(e instanceof TypeError, true, |
|
32 "should have thrown a TypeError, instead got: " + e); |
|
33 } |
|
34 |
|
35 // Second time with .lastIndex !== 0 |
|
36 |
|
37 var p2 = /x/g; |
|
38 Object.defineProperty(p2, "lastIndex", { writable: false, value: 3 }); |
|
39 |
|
40 try |
|
41 { |
|
42 s.match(p2); |
|
43 throw "didn't throw"; |
|
44 } |
|
45 catch (e) |
|
46 { |
|
47 assertEq(e instanceof TypeError, true, |
|
48 "should have thrown a TypeError, instead got: " + e); |
|
49 } |
|
50 |
|
51 // Third time with .lastIndex === 0, no matches |
|
52 |
|
53 var p3 = /q/g; |
|
54 Object.defineProperty(p3, "lastIndex", { writable: false }); |
|
55 |
|
56 try |
|
57 { |
|
58 s.match(p3); |
|
59 throw "didn't throw"; |
|
60 } |
|
61 catch (e) |
|
62 { |
|
63 assertEq(e instanceof TypeError, true, |
|
64 "should have thrown a TypeError, instead got: " + e); |
|
65 } |
|
66 |
|
67 // Fourth time with .lastIndex !== 0, no matches |
|
68 |
|
69 var p4 = /q/g; |
|
70 Object.defineProperty(p4, "lastIndex", { writable: false, value: 3 }); |
|
71 |
|
72 try |
|
73 { |
|
74 s.match(p4); |
|
75 throw "didn't throw"; |
|
76 } |
|
77 catch (e) |
|
78 { |
|
79 assertEq(e instanceof TypeError, true, |
|
80 "should have thrown a TypeError, instead got: " + e); |
|
81 } |
|
82 |
|
83 /******************************************************************************/ |
|
84 |
|
85 if (typeof reportCompare === "function") |
|
86 reportCompare(true, true); |
|
87 |
|
88 print("Tests complete"); |