]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_5/Regress/regress-179524.js
31a7f3050d89e9fd98ddd09ed094b5f60ea1a63b
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Netscape Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/NPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is JavaScript Engine testing utilities.
16 * The Initial Developer of the Original Code is Netscape Communications Corp.
17 * Portions created by the Initial Developer are Copyright (C) 2002
18 * the Initial Developer. All Rights Reserved.
20 * Contributor(s): pschwartau@netscape.com
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the NPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the NPL, the GPL or the LGPL.
34 * ***** END LICENSE BLOCK *****
38 * SUMMARY: JS shouldn't crash on extraneous args to str.match(), etc.
39 * See http://bugzilla.mozilla.org/show_bug.cgi?id=179524
41 * Note that when testing str.replace(), we have to be careful if the first
42 * argument provided to str.replace() is not a regexp object. ECMA-262 says
43 * it is NOT converted to one, unlike the case for str.match(), str.search().
45 * See http://bugzilla.mozilla.org/show_bug.cgi?id=83293#c21. This means
46 * we have to be careful how we test meta-characters in the first argument
47 * to str.replace(), if that argument is a string -
49 //-----------------------------------------------------------------------------
52 var summary
= "Don't crash on extraneous arguments to str.match(), etc.";
56 var actualvalues
= [];
58 var expectedvalues
= [];
64 status
= inSection(1);
65 actual
= str
.match(re
);
69 status
= inSection(2);
70 actual
= str
.match(re
, 'i');
74 status
= inSection(3);
75 actual
= str
.match(re
, 'g', '');
79 status
= inSection(4);
80 actual
= str
.match(re
, 'z', new Object(), new Date());
86 * Now try the same thing with str.search()
88 status
= inSection(5);
89 actual
= str
.search(re
);
93 status
= inSection(6);
94 actual
= str
.search(re
, 'i');
98 status
= inSection(7);
99 actual
= str
.search(re
, 'g', '');
103 status
= inSection(8);
104 actual
= str
.search(re
, 'z', new Object(), new Date());
110 * Now try the same thing with str.replace()
112 status
= inSection(9);
113 actual
= str
.replace(re
, 'Z');
117 status
= inSection(10);
118 actual
= str
.replace(re
, 'Z', 'i');
122 status
= inSection(11);
123 actual
= str
.replace(re
, 'Z', 'g', '');
127 status
= inSection(12);
128 actual
= str
.replace(re
, 'Z', 'z', new Object(), new Date());
135 * Now test the case where str.match()'s first argument is not a regexp object.
136 * In that case, JS follows ECMA-262 Ed.3 by converting the 1st argument to a
137 * regexp object using the argument as a regexp pattern, but then extends ECMA
138 * by taking any optional 2nd argument to be a regexp flag string (e.g.'ig').
140 * Reference: http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c10
142 status
= inSection(13);
143 actual
= str
.match('a').toString();
144 expect
= str
.match(/a
/).toString();
147 status
= inSection(14);
148 actual
= str
.match('a', 'i').toString();
149 expect
= str
.match(/a
/i
).toString();
152 status
= inSection(15);
153 actual
= str
.match('a', 'ig').toString();
154 expect
= str
.match(/a
/ig
).toString();
157 status
= inSection(16);
158 actual
= str
.match('\\s', 'm').toString();
159 expect
= str
.match(/\s/m).toString();
164 * Now try the previous three cases with extraneous parameters
166 status
= inSection(17);
167 actual
= str
.match('a', 'i', 'g').toString();
168 expect
= str
.match(/a
/i
).toString();
171 status
= inSection(18);
172 actual
= str
.match('a', 'ig', new Object()).toString();
173 expect
= str
.match(/a
/ig
).toString();
176 status
= inSection(19);
177 actual
= str
.match('\\s', 'm', 999).toString();
178 expect
= str
.match(/\s/m).toString();
183 * Try an invalid second parameter (i.e. an invalid regexp flag)
185 status
= inSection(20);
188 actual
= str
.match('a', 'z').toString();
189 expect
= 'SHOULD HAVE FALLEN INTO CATCH-BLOCK!';
194 actual
= e
instanceof SyntaxError
;
202 * Now test str.search() where the first argument is not a regexp object.
203 * The same considerations as above apply -
205 * Reference: http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c16
207 status
= inSection(21);
208 actual
= str
.search('a');
209 expect
= str
.search(/a
/);
212 status
= inSection(22);
213 actual
= str
.search('a', 'i');
214 expect
= str
.search(/a
/i
);
217 status
= inSection(23);
218 actual
= str
.search('a', 'ig');
219 expect
= str
.search(/a
/ig
);
222 status
= inSection(24);
223 actual
= str
.search('\\s', 'm');
224 expect
= str
.search(/\s/m);
229 * Now try the previous three cases with extraneous parameters
231 status
= inSection(25);
232 actual
= str
.search('a', 'i', 'g');
233 expect
= str
.search(/a
/i
);
236 status
= inSection(26);
237 actual
= str
.search('a', 'ig', new Object());
238 expect
= str
.search(/a
/ig
);
241 status
= inSection(27);
242 actual
= str
.search('\\s', 'm', 999);
243 expect
= str
.search(/\s/m);
248 * Try an invalid second parameter (i.e. an invalid regexp flag)
250 status
= inSection(28);
253 actual
= str
.search('a', 'z');
254 expect
= 'SHOULD HAVE FALLEN INTO CATCH-BLOCK!';
259 actual
= e
instanceof SyntaxError
;
267 * Now test str.replace() where the first argument is not a regexp object.
268 * The same considerations as above apply, EXCEPT for meta-characters.
269 * See introduction to testcase above. References:
271 * http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c16
272 * http://bugzilla.mozilla.org/show_bug.cgi?id=83293#c21
274 status
= inSection(29);
275 actual
= str
.replace('a', 'Z');
276 expect
= str
.replace(/a
/, 'Z');
279 status
= inSection(30);
280 actual
= str
.replace('a', 'Z', 'i');
281 expect
= str
.replace(/a
/i
, 'Z');
284 status
= inSection(31);
285 actual
= str
.replace('a', 'Z', 'ig');
286 expect
= str
.replace(/a
/ig
, 'Z');
289 status
= inSection(32);
290 actual
= str
.replace('\\s', 'Z', 'm'); //<--- NO!!! No meta-characters 1st arg!
291 actual
= str
.replace(' ', 'Z', 'm'); //<--- Have to do this instead
292 expect
= str
.replace(/\s/m, 'Z');
297 * Now try the previous three cases with extraneous parameters
299 status
= inSection(33);
300 actual
= str
.replace('a', 'Z', 'i', 'g');
301 expect
= str
.replace(/a
/i
, 'Z');
304 status
= inSection(34);
305 actual
= str
.replace('a', 'Z', 'ig', new Object());
306 expect
= str
.replace(/a
/ig
, 'Z');
309 status
= inSection(35);
310 actual
= str
.replace('\\s', 'Z', 'm', 999); //<--- NO meta-characters 1st arg!
311 actual
= str
.replace(' ', 'Z', 'm', 999); //<--- Have to do this instead
312 expect
= str
.replace(/\s/m, 'Z');
317 * Try an invalid third parameter (i.e. an invalid regexp flag)
319 status
= inSection(36);
322 actual
= str
.replace('a', 'Z', 'z');
323 expect
= 'SHOULD HAVE FALLEN INTO CATCH-BLOCK!';
328 actual
= e
instanceof SyntaxError
;
336 //-----------------------------------------------------------------------------
338 //-----------------------------------------------------------------------------
344 statusitems
[UBound
] = status
;
345 actualvalues
[UBound
] = actual
;
346 expectedvalues
[UBound
] = expect
;
355 printStatus(summary
);
357 for (var i
=0; i
<UBound
; i
++)
359 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);