js/src/tests/js1_5/Regress/regress-179524.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 *
michael@0 8 * Date: 11 Nov 2002
michael@0 9 * SUMMARY: JS shouldn't crash on extraneous args to str.match(), etc.
michael@0 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=179524
michael@0 11 *
michael@0 12 * Note that when testing str.replace(), we have to be careful if the first
michael@0 13 * argument provided to str.replace() is not a regexp object. ECMA-262 says
michael@0 14 * it is NOT converted to one, unlike the case for str.match(), str.search().
michael@0 15 *
michael@0 16 * See http://bugzilla.mozilla.org/show_bug.cgi?id=83293#c21. This means
michael@0 17 * we have to be careful how we test meta-characters in the first argument
michael@0 18 * to str.replace(), if that argument is a string -
michael@0 19 */
michael@0 20 //-----------------------------------------------------------------------------
michael@0 21 var UBound = 0;
michael@0 22 var BUGNUMBER = 179524;
michael@0 23 var summary = "Don't crash on extraneous arguments to str.match(), etc.";
michael@0 24 var status = '';
michael@0 25 var statusitems = [];
michael@0 26 var actual = '';
michael@0 27 var actualvalues = [];
michael@0 28 var expect= '';
michael@0 29 var expectedvalues = [];
michael@0 30
michael@0 31
michael@0 32 str = 'ABC abc';
michael@0 33 var re = /z/ig;
michael@0 34
michael@0 35 status = inSection(1);
michael@0 36 actual = str.match(re);
michael@0 37 expect = null;
michael@0 38 addThis();
michael@0 39
michael@0 40 status = inSection(2);
michael@0 41 actual = str.match(re, 'i');
michael@0 42 expect = null;
michael@0 43 addThis();
michael@0 44
michael@0 45 status = inSection(3);
michael@0 46 actual = str.match(re, 'g', '');
michael@0 47 expect = null;
michael@0 48 addThis();
michael@0 49
michael@0 50 status = inSection(4);
michael@0 51 actual = str.match(re, 'z', new Object(), new Date());
michael@0 52 expect = null;
michael@0 53 addThis();
michael@0 54
michael@0 55
michael@0 56 /*
michael@0 57 * Now try the same thing with str.search()
michael@0 58 */
michael@0 59 status = inSection(5);
michael@0 60 actual = str.search(re);
michael@0 61 expect = -1;
michael@0 62 addThis();
michael@0 63
michael@0 64 status = inSection(6);
michael@0 65 actual = str.search(re, 'i');
michael@0 66 expect = -1;
michael@0 67 addThis();
michael@0 68
michael@0 69 status = inSection(7);
michael@0 70 actual = str.search(re, 'g', '');
michael@0 71 expect = -1;
michael@0 72 addThis();
michael@0 73
michael@0 74 status = inSection(8);
michael@0 75 actual = str.search(re, 'z', new Object(), new Date());
michael@0 76 expect = -1;
michael@0 77 addThis();
michael@0 78
michael@0 79
michael@0 80 /*
michael@0 81 * Now try the same thing with str.replace()
michael@0 82 */
michael@0 83 status = inSection(9);
michael@0 84 actual = str.replace(re, 'Z');
michael@0 85 expect = str;
michael@0 86 addThis();
michael@0 87
michael@0 88 status = inSection(10);
michael@0 89 actual = str.replace(re, 'Z', 'i');
michael@0 90 expect = str;
michael@0 91 addThis();
michael@0 92
michael@0 93 status = inSection(11);
michael@0 94 actual = str.replace(re, 'Z', 'g', '');
michael@0 95 expect = str;
michael@0 96 addThis();
michael@0 97
michael@0 98 status = inSection(12);
michael@0 99 actual = str.replace(re, 'Z', 'z', new Object(), new Date());
michael@0 100 expect = str;
michael@0 101 addThis();
michael@0 102
michael@0 103
michael@0 104
michael@0 105 /*
michael@0 106 * Now test the case where str.match()'s first argument is not a regexp object.
michael@0 107 * In that case, JS follows ECMA-262 Ed.3 by converting the 1st argument to a
michael@0 108 * regexp object using the argument as a regexp pattern, but then extends ECMA
michael@0 109 * by taking any optional 2nd argument to be a regexp flag string (e.g.'ig').
michael@0 110 *
michael@0 111 * Reference: http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c10
michael@0 112 */
michael@0 113 status = inSection(13);
michael@0 114 actual = str.match('a').toString();
michael@0 115 expect = str.match(/a/).toString();
michael@0 116 addThis();
michael@0 117
michael@0 118 status = inSection(14);
michael@0 119 actual = str.match('a', 'i').toString();
michael@0 120 expect = str.match(/a/i).toString();
michael@0 121 addThis();
michael@0 122
michael@0 123 status = inSection(15);
michael@0 124 actual = str.match('a', 'ig').toString();
michael@0 125 expect = str.match(/a/ig).toString();
michael@0 126 addThis();
michael@0 127
michael@0 128 status = inSection(16);
michael@0 129 actual = str.match('\\s', 'm').toString();
michael@0 130 expect = str.match(/\s/m).toString();
michael@0 131 addThis();
michael@0 132
michael@0 133
michael@0 134 /*
michael@0 135 * Now try the previous three cases with extraneous parameters
michael@0 136 */
michael@0 137 status = inSection(17);
michael@0 138 actual = str.match('a', 'i', 'g').toString();
michael@0 139 expect = str.match(/a/i).toString();
michael@0 140 addThis();
michael@0 141
michael@0 142 status = inSection(18);
michael@0 143 actual = str.match('a', 'ig', new Object()).toString();
michael@0 144 expect = str.match(/a/ig).toString();
michael@0 145 addThis();
michael@0 146
michael@0 147 status = inSection(19);
michael@0 148 actual = str.match('\\s', 'm', 999).toString();
michael@0 149 expect = str.match(/\s/m).toString();
michael@0 150 addThis();
michael@0 151
michael@0 152
michael@0 153 /*
michael@0 154 * Try an invalid second parameter (i.e. an invalid regexp flag)
michael@0 155 */
michael@0 156 status = inSection(20);
michael@0 157 try
michael@0 158 {
michael@0 159 actual = str.match('a', 'z').toString();
michael@0 160 expect = 'SHOULD HAVE FALLEN INTO CATCH-BLOCK!';
michael@0 161 addThis();
michael@0 162 }
michael@0 163 catch (e)
michael@0 164 {
michael@0 165 actual = e instanceof SyntaxError;
michael@0 166 expect = true;
michael@0 167 addThis();
michael@0 168 }
michael@0 169
michael@0 170
michael@0 171
michael@0 172 /*
michael@0 173 * Now test str.search() where the first argument is not a regexp object.
michael@0 174 * The same considerations as above apply -
michael@0 175 *
michael@0 176 * Reference: http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c16
michael@0 177 */
michael@0 178 status = inSection(21);
michael@0 179 actual = str.search('a');
michael@0 180 expect = str.search(/a/);
michael@0 181 addThis();
michael@0 182
michael@0 183 status = inSection(22);
michael@0 184 actual = str.search('a', 'i');
michael@0 185 expect = str.search(/a/i);
michael@0 186 addThis();
michael@0 187
michael@0 188 status = inSection(23);
michael@0 189 actual = str.search('a', 'ig');
michael@0 190 expect = str.search(/a/ig);
michael@0 191 addThis();
michael@0 192
michael@0 193 status = inSection(24);
michael@0 194 actual = str.search('\\s', 'm');
michael@0 195 expect = str.search(/\s/m);
michael@0 196 addThis();
michael@0 197
michael@0 198
michael@0 199 /*
michael@0 200 * Now try the previous three cases with extraneous parameters
michael@0 201 */
michael@0 202 status = inSection(25);
michael@0 203 actual = str.search('a', 'i', 'g');
michael@0 204 expect = str.search(/a/i);
michael@0 205 addThis();
michael@0 206
michael@0 207 status = inSection(26);
michael@0 208 actual = str.search('a', 'ig', new Object());
michael@0 209 expect = str.search(/a/ig);
michael@0 210 addThis();
michael@0 211
michael@0 212 status = inSection(27);
michael@0 213 actual = str.search('\\s', 'm', 999);
michael@0 214 expect = str.search(/\s/m);
michael@0 215 addThis();
michael@0 216
michael@0 217
michael@0 218 /*
michael@0 219 * Try an invalid second parameter (i.e. an invalid regexp flag)
michael@0 220 */
michael@0 221 status = inSection(28);
michael@0 222 try
michael@0 223 {
michael@0 224 actual = str.search('a', 'z');
michael@0 225 expect = 'SHOULD HAVE FALLEN INTO CATCH-BLOCK!';
michael@0 226 addThis();
michael@0 227 }
michael@0 228 catch (e)
michael@0 229 {
michael@0 230 actual = e instanceof SyntaxError;
michael@0 231 expect = true;
michael@0 232 addThis();
michael@0 233 }
michael@0 234
michael@0 235
michael@0 236
michael@0 237 /*
michael@0 238 * Now test str.replace() where the first argument is not a regexp object.
michael@0 239 * The same considerations as above apply, EXCEPT for meta-characters.
michael@0 240 * See introduction to testcase above. References:
michael@0 241 *
michael@0 242 * http://bugzilla.mozilla.org/show_bug.cgi?id=179524#c16
michael@0 243 * http://bugzilla.mozilla.org/show_bug.cgi?id=83293#c21
michael@0 244 */
michael@0 245 status = inSection(29);
michael@0 246 actual = str.replace('a', 'Z');
michael@0 247 expect = str.replace(/a/, 'Z');
michael@0 248 addThis();
michael@0 249
michael@0 250 status = inSection(30);
michael@0 251 actual = str.replace('a', 'Z', 'i');
michael@0 252 expect = str.replace(/a/i, 'Z');
michael@0 253 addThis();
michael@0 254
michael@0 255 status = inSection(31);
michael@0 256 actual = str.replace('a', 'Z', 'ig');
michael@0 257 expect = str.replace(/a/ig, 'Z');
michael@0 258 addThis();
michael@0 259
michael@0 260 status = inSection(32);
michael@0 261 actual = str.replace('\\s', 'Z', 'm'); //<--- NO!!! No meta-characters 1st arg!
michael@0 262 actual = str.replace(' ', 'Z', 'm'); //<--- Have to do this instead
michael@0 263 expect = str.replace(/\s/m, 'Z');
michael@0 264 addThis();
michael@0 265
michael@0 266
michael@0 267 /*
michael@0 268 * Now try the previous three cases with extraneous parameters
michael@0 269 */
michael@0 270 status = inSection(33);
michael@0 271 actual = str.replace('a', 'Z', 'i', 'g');
michael@0 272 expect = str.replace(/a/i, 'Z');
michael@0 273 addThis();
michael@0 274
michael@0 275 status = inSection(34);
michael@0 276 actual = str.replace('a', 'Z', 'ig', new Object());
michael@0 277 expect = str.replace(/a/ig, 'Z');
michael@0 278 addThis();
michael@0 279
michael@0 280 status = inSection(35);
michael@0 281 actual = str.replace('\\s', 'Z', 'm', 999); //<--- NO meta-characters 1st arg!
michael@0 282 actual = str.replace(' ', 'Z', 'm', 999); //<--- Have to do this instead
michael@0 283 expect = str.replace(/\s/m, 'Z');
michael@0 284 addThis();
michael@0 285
michael@0 286
michael@0 287 /*
michael@0 288 * Try an invalid third parameter (i.e. an invalid regexp flag)
michael@0 289 */
michael@0 290 status = inSection(36);
michael@0 291 try
michael@0 292 {
michael@0 293 actual = str.replace('a', 'Z', 'z');
michael@0 294 expect = 'SHOULD HAVE FALLEN INTO CATCH-BLOCK!';
michael@0 295 addThis();
michael@0 296 }
michael@0 297 catch (e)
michael@0 298 {
michael@0 299 actual = e instanceof SyntaxError;
michael@0 300 expect = true;
michael@0 301 addThis();
michael@0 302 }
michael@0 303
michael@0 304
michael@0 305
michael@0 306
michael@0 307 //-----------------------------------------------------------------------------
michael@0 308 test();
michael@0 309 //-----------------------------------------------------------------------------
michael@0 310
michael@0 311
michael@0 312
michael@0 313 function addThis()
michael@0 314 {
michael@0 315 statusitems[UBound] = status;
michael@0 316 actualvalues[UBound] = actual;
michael@0 317 expectedvalues[UBound] = expect;
michael@0 318 UBound++;
michael@0 319 }
michael@0 320
michael@0 321
michael@0 322 function test()
michael@0 323 {
michael@0 324 enterFunc('test');
michael@0 325 printBugNumber(BUGNUMBER);
michael@0 326 printStatus(summary);
michael@0 327
michael@0 328 for (var i=0; i<UBound; i++)
michael@0 329 {
michael@0 330 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
michael@0 331 }
michael@0 332
michael@0 333 exitFunc ('test');
michael@0 334 }

mercurial