Bug 469739 - Add support for displaying Vista UAC shield icon; r=joe sr=vladimir
[wine-gecko.git] / js / tests / js1_5 / Regress / regress-179524.js
blob55d83a769ba4a6bfd79a8ed78e80f1625d577951
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corp.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * pschwartau@netscape.com
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 * Date: 11 Nov 2002
42 * SUMMARY: JS shouldn't crash on extraneous args to str.match(), etc.
43 * See http://bugzilla.mozilla.org/show_bug.cgi?id=179524
45 * Note that when testing str.replace(), we have to be careful if the first
46 * argument provided to str.replace() is not a regexp object. ECMA-262 says
47 * it is NOT converted to one, unlike the case for str.match(), str.search().
49 * See http://bugzilla.mozilla.org/show_bug.cgi?id=83293#c21. This means
50 * we have to be careful how we test meta-characters in the first argument
51 * to str.replace(), if that argument is a string -
53 //-----------------------------------------------------------------------------
54 var gTestfile = 'regress-179524.js';
55 var UBound = 0;
56 var BUGNUMBER = 179524;
57 var summary = "Don't crash on extraneous arguments to str.match(), etc.";
58 var status = '';
59 var statusitems = [];
60 var actual = '';
61 var actualvalues = [];
62 var expect= '';
63 var expectedvalues = [];
66 str = 'ABC abc';
67 var re = /z/ig;
69 status = inSection(1);
70 actual = str.match(re);
71 expect = null;
72 addThis();
74 status = inSection(2);
75 actual = str.match(re, 'i');
76 expect = null;
77 addThis();
79 status = inSection(3);
80 actual = str.match(re, 'g', '');
81 expect = null;
82 addThis();
84 status = inSection(4);
85 actual = str.match(re, 'z', new Object(), new Date());
86 expect = null;
87 addThis();
91 * Now try the same thing with str.search()
93 status = inSection(5);
94 actual = str.search(re);
95 expect = -1;
96 addThis();
98 status = inSection(6);
99 actual = str.search(re, 'i');
100 expect = -1;
101 addThis();
103 status = inSection(7);
104 actual = str.search(re, 'g', '');
105 expect = -1;
106 addThis();
108 status = inSection(8);
109 actual = str.search(re, 'z', new Object(), new Date());
110 expect = -1;
111 addThis();
115 * Now try the same thing with str.replace()
117 status = inSection(9);
118 actual = str.replace(re, 'Z');
119 expect = str;
120 addThis();
122 status = inSection(10);
123 actual = str.replace(re, 'Z', 'i');
124 expect = str;
125 addThis();
127 status = inSection(11);
128 actual = str.replace(re, 'Z', 'g', '');
129 expect = str;
130 addThis();
132 status = inSection(12);
133 actual = str.replace(re, 'Z', 'z', new Object(), new Date());
134 expect = str;
135 addThis();
140 * Now test the case where str.match()'s first argument is not a regexp object.
141 * In that case, JS follows ECMA-262 Ed.3 by converting the 1st argument to a
142 * regexp object using the argument as a regexp pattern, but then extends ECMA
143 * by taking any optional 2nd argument to be a regexp flag string (e.g.'ig').
145 * Reference: http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c10
147 status = inSection(13);
148 actual = str.match('a').toString();
149 expect = str.match(/a/).toString();
150 addThis();
152 status = inSection(14);
153 actual = str.match('a', 'i').toString();
154 expect = str.match(/a/i).toString();
155 addThis();
157 status = inSection(15);
158 actual = str.match('a', 'ig').toString();
159 expect = str.match(/a/ig).toString();
160 addThis();
162 status = inSection(16);
163 actual = str.match('\\s', 'm').toString();
164 expect = str.match(/\s/m).toString();
165 addThis();
169 * Now try the previous three cases with extraneous parameters
171 status = inSection(17);
172 actual = str.match('a', 'i', 'g').toString();
173 expect = str.match(/a/i).toString();
174 addThis();
176 status = inSection(18);
177 actual = str.match('a', 'ig', new Object()).toString();
178 expect = str.match(/a/ig).toString();
179 addThis();
181 status = inSection(19);
182 actual = str.match('\\s', 'm', 999).toString();
183 expect = str.match(/\s/m).toString();
184 addThis();
188 * Try an invalid second parameter (i.e. an invalid regexp flag)
190 status = inSection(20);
193 actual = str.match('a', 'z').toString();
194 expect = 'SHOULD HAVE FALLEN INTO CATCH-BLOCK!';
195 addThis();
197 catch (e)
199 actual = e instanceof SyntaxError;
200 expect = true;
201 addThis();
207 * Now test str.search() where the first argument is not a regexp object.
208 * The same considerations as above apply -
210 * Reference: http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c16
212 status = inSection(21);
213 actual = str.search('a');
214 expect = str.search(/a/);
215 addThis();
217 status = inSection(22);
218 actual = str.search('a', 'i');
219 expect = str.search(/a/i);
220 addThis();
222 status = inSection(23);
223 actual = str.search('a', 'ig');
224 expect = str.search(/a/ig);
225 addThis();
227 status = inSection(24);
228 actual = str.search('\\s', 'm');
229 expect = str.search(/\s/m);
230 addThis();
234 * Now try the previous three cases with extraneous parameters
236 status = inSection(25);
237 actual = str.search('a', 'i', 'g');
238 expect = str.search(/a/i);
239 addThis();
241 status = inSection(26);
242 actual = str.search('a', 'ig', new Object());
243 expect = str.search(/a/ig);
244 addThis();
246 status = inSection(27);
247 actual = str.search('\\s', 'm', 999);
248 expect = str.search(/\s/m);
249 addThis();
253 * Try an invalid second parameter (i.e. an invalid regexp flag)
255 status = inSection(28);
258 actual = str.search('a', 'z');
259 expect = 'SHOULD HAVE FALLEN INTO CATCH-BLOCK!';
260 addThis();
262 catch (e)
264 actual = e instanceof SyntaxError;
265 expect = true;
266 addThis();
272 * Now test str.replace() where the first argument is not a regexp object.
273 * The same considerations as above apply, EXCEPT for meta-characters.
274 * See introduction to testcase above. References:
276 * http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c16
277 * http://bugzilla.mozilla.org/show_bug.cgi?id=83293#c21
279 status = inSection(29);
280 actual = str.replace('a', 'Z');
281 expect = str.replace(/a/, 'Z');
282 addThis();
284 status = inSection(30);
285 actual = str.replace('a', 'Z', 'i');
286 expect = str.replace(/a/i, 'Z');
287 addThis();
289 status = inSection(31);
290 actual = str.replace('a', 'Z', 'ig');
291 expect = str.replace(/a/ig, 'Z');
292 addThis();
294 status = inSection(32);
295 actual = str.replace('\\s', 'Z', 'm'); //<--- NO!!! No meta-characters 1st arg!
296 actual = str.replace(' ', 'Z', 'm'); //<--- Have to do this instead
297 expect = str.replace(/\s/m, 'Z');
298 addThis();
302 * Now try the previous three cases with extraneous parameters
304 status = inSection(33);
305 actual = str.replace('a', 'Z', 'i', 'g');
306 expect = str.replace(/a/i, 'Z');
307 addThis();
309 status = inSection(34);
310 actual = str.replace('a', 'Z', 'ig', new Object());
311 expect = str.replace(/a/ig, 'Z');
312 addThis();
314 status = inSection(35);
315 actual = str.replace('\\s', 'Z', 'm', 999); //<--- NO meta-characters 1st arg!
316 actual = str.replace(' ', 'Z', 'm', 999); //<--- Have to do this instead
317 expect = str.replace(/\s/m, 'Z');
318 addThis();
322 * Try an invalid third parameter (i.e. an invalid regexp flag)
324 status = inSection(36);
327 actual = str.replace('a', 'Z', 'z');
328 expect = 'SHOULD HAVE FALLEN INTO CATCH-BLOCK!';
329 addThis();
331 catch (e)
333 actual = e instanceof SyntaxError;
334 expect = true;
335 addThis();
341 //-----------------------------------------------------------------------------
342 test();
343 //-----------------------------------------------------------------------------
347 function addThis()
349 statusitems[UBound] = status;
350 actualvalues[UBound] = actual;
351 expectedvalues[UBound] = expect;
352 UBound++;
356 function test()
358 enterFunc('test');
359 printBugNumber(BUGNUMBER);
360 printStatus(summary);
362 for (var i=0; i<UBound; i++)
364 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
367 exitFunc ('test');