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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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: 10 October 2001
michael@0 9 * SUMMARY: Regression test for Bugzilla bug 104077
michael@0 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=104077
michael@0 11 * "JS crash: with/finally/return"
michael@0 12 *
michael@0 13 * Also http://bugzilla.mozilla.org/show_bug.cgi?id=120571
michael@0 14 * "JS crash: try/catch/continue."
michael@0 15 *
michael@0 16 * SpiderMonkey crashed on this code - it shouldn't.
michael@0 17 *
michael@0 18 * NOTE: the finally-blocks below should execute even if their try-blocks
michael@0 19 * have return or throw statements in them:
michael@0 20 *
michael@0 21 * ------- Additional Comment #76 From Mike Shaver 2001-12-07 01:21 -------
michael@0 22 * finally trumps return, and all other control-flow constructs that cause
michael@0 23 * program execution to jump out of the try block: throw, break, etc. Once you
michael@0 24 * enter a try block, you will execute the finally block after leaving the try,
michael@0 25 * regardless of what happens to make you leave the try.
michael@0 26 *
michael@0 27 */
michael@0 28 //-----------------------------------------------------------------------------
michael@0 29 var UBound = 0;
michael@0 30 var BUGNUMBER = 104077;
michael@0 31 var summary = "Just testing that we don't crash on with/finally/return -";
michael@0 32 var status = '';
michael@0 33 var statusitems = [];
michael@0 34 var actual = '';
michael@0 35 var actualvalues = [];
michael@0 36 var expect= '';
michael@0 37 var expectedvalues = [];
michael@0 38
michael@0 39
michael@0 40 function addValues(obj)
michael@0 41 {
michael@0 42 var sum;
michael@0 43 with (obj)
michael@0 44 {
michael@0 45 try
michael@0 46 {
michael@0 47 sum = arg1 + arg2;
michael@0 48 }
michael@0 49 finally
michael@0 50 {
michael@0 51 return sum;
michael@0 52 }
michael@0 53 }
michael@0 54 }
michael@0 55
michael@0 56 status = inSection(1);
michael@0 57 var obj = new Object();
michael@0 58 obj.arg1 = 1;
michael@0 59 obj.arg2 = 2;
michael@0 60 actual = addValues(obj);
michael@0 61 expect = 3;
michael@0 62 captureThis();
michael@0 63
michael@0 64
michael@0 65
michael@0 66 function tryThis()
michael@0 67 {
michael@0 68 var sum = 4 ;
michael@0 69 var i = 0;
michael@0 70
michael@0 71 while (sum < 10)
michael@0 72 {
michael@0 73 try
michael@0 74 {
michael@0 75 sum += 1;
michael@0 76 i += 1;
michael@0 77 }
michael@0 78 finally
michael@0 79 {
michael@0 80 print("In finally case of tryThis() function");
michael@0 81 }
michael@0 82 }
michael@0 83 return i;
michael@0 84 }
michael@0 85
michael@0 86 status = inSection(2);
michael@0 87 actual = tryThis();
michael@0 88 expect = 6;
michael@0 89 captureThis();
michael@0 90
michael@0 91
michael@0 92
michael@0 93 function myTest(x)
michael@0 94 {
michael@0 95 var obj = new Object();
michael@0 96 var msg;
michael@0 97
michael@0 98 with (obj)
michael@0 99 {
michael@0 100 msg = (x != null) ? "NO" : "YES";
michael@0 101 print("Is the provided argument to myTest() null? : " + msg);
michael@0 102
michael@0 103 try
michael@0 104 {
michael@0 105 throw "ZZZ";
michael@0 106 }
michael@0 107 catch(e)
michael@0 108 {
michael@0 109 print("Caught thrown exception = " + e);
michael@0 110 }
michael@0 111 }
michael@0 112
michael@0 113 return 1;
michael@0 114 }
michael@0 115
michael@0 116 status = inSection(3);
michael@0 117 actual = myTest(null);
michael@0 118 expect = 1;
michael@0 119 captureThis();
michael@0 120
michael@0 121
michael@0 122
michael@0 123 function addValues_2(obj)
michael@0 124 {
michael@0 125 var sum = 0;
michael@0 126 with (obj)
michael@0 127 {
michael@0 128 try
michael@0 129 {
michael@0 130 sum = arg1 + arg2;
michael@0 131 with (arg3)
michael@0 132 {
michael@0 133 while (sum < 10)
michael@0 134 {
michael@0 135 try
michael@0 136 {
michael@0 137 if (sum > 5)
michael@0 138 return sum;
michael@0 139 sum += 1;
michael@0 140 }
michael@0 141 catch(e)
michael@0 142 {
michael@0 143 print('Caught an exception in addValues_2() function: ' + e);
michael@0 144 }
michael@0 145 }
michael@0 146 }
michael@0 147 }
michael@0 148 finally
michael@0 149 {
michael@0 150 return sum;
michael@0 151 }
michael@0 152 }
michael@0 153 }
michael@0 154
michael@0 155 status = inSection(4);
michael@0 156 obj = new Object();
michael@0 157 obj.arg1 = 1;
michael@0 158 obj.arg2 = 2;
michael@0 159 obj.arg3 = new Object();
michael@0 160 obj.arg3.a = 10;
michael@0 161 obj.arg3.b = 20;
michael@0 162 actual = addValues_2(obj);
michael@0 163 expect = 6;
michael@0 164 captureThis();
michael@0 165
michael@0 166
michael@0 167
michael@0 168 status = inSection(5);
michael@0 169 try
michael@0 170 {
michael@0 171 throw new A();
michael@0 172 }
michael@0 173 catch(e)
michael@0 174 {
michael@0 175 }
michael@0 176 finally
michael@0 177 {
michael@0 178 try
michael@0 179 {
michael@0 180 throw new A();
michael@0 181 }
michael@0 182 catch(e)
michael@0 183 {
michael@0 184 }
michael@0 185 finally
michael@0 186 {
michael@0 187 actual = 'a';
michael@0 188 }
michael@0 189 actual = 'b';
michael@0 190 }
michael@0 191 expect = 'b';
michael@0 192 captureThis();
michael@0 193
michael@0 194
michael@0 195
michael@0 196
michael@0 197 function testfunc(mode)
michael@0 198 {
michael@0 199 var obj = new Object();
michael@0 200 with (obj)
michael@0 201 {
michael@0 202 var num = 100;
michael@0 203 var str = "abc" ;
michael@0 204
michael@0 205 if (str == null)
michael@0 206 {
michael@0 207 try
michael@0 208 {
michael@0 209 throw "authentication.0";
michael@0 210 }
michael@0 211 catch(e)
michael@0 212 {
michael@0 213 }
michael@0 214 finally
michael@0 215 {
michael@0 216 }
michael@0 217
michael@0 218 return num;
michael@0 219 }
michael@0 220 else
michael@0 221 {
michael@0 222 try
michael@0 223 {
michael@0 224 if (mode == 0)
michael@0 225 throw "authentication.0";
michael@0 226 else
michael@0 227 mytest();
michael@0 228 }
michael@0 229 catch(e)
michael@0 230 {
michael@0 231 }
michael@0 232 finally
michael@0 233 {
michael@0 234 }
michael@0 235
michael@0 236 return num;
michael@0 237 }
michael@0 238 }
michael@0 239 }
michael@0 240
michael@0 241 status = inSection(6);
michael@0 242 actual = testfunc(0);
michael@0 243 expect = 100;
michael@0 244 captureThis();
michael@0 245
michael@0 246 status = inSection(7);
michael@0 247 actual = testfunc();
michael@0 248 expect = 100;
michael@0 249 captureThis();
michael@0 250
michael@0 251
michael@0 252
michael@0 253
michael@0 254 function entry_menu()
michael@0 255 {
michael@0 256 var document = new Object();
michael@0 257 var dialog = new Object();
michael@0 258 var num = 100;
michael@0 259
michael@0 260 with (document)
michael@0 261 {
michael@0 262 with (dialog)
michael@0 263 {
michael@0 264 try
michael@0 265 {
michael@0 266 while (true)
michael@0 267 {
michael@0 268 return num;
michael@0 269 }
michael@0 270 }
michael@0 271 finally
michael@0 272 {
michael@0 273 }
michael@0 274 }
michael@0 275 }
michael@0 276 }
michael@0 277
michael@0 278 status = inSection(8);
michael@0 279 actual = entry_menu();
michael@0 280 expect = 100;
michael@0 281 captureThis();
michael@0 282
michael@0 283
michael@0 284
michael@0 285
michael@0 286 function addValues_5(obj)
michael@0 287 {
michael@0 288 var sum = 0;
michael@0 289
michael@0 290 with (obj)
michael@0 291 {
michael@0 292 try
michael@0 293 {
michael@0 294 sum = arg1 + arg2;
michael@0 295 with (arg3)
michael@0 296 {
michael@0 297 while (sum < 10)
michael@0 298 {
michael@0 299 try
michael@0 300 {
michael@0 301 if (sum > 5)
michael@0 302 return sum;
michael@0 303 sum += 1;
michael@0 304 }
michael@0 305 catch (e)
michael@0 306 {
michael@0 307 sum += 1;
michael@0 308 }
michael@0 309 }
michael@0 310 }
michael@0 311 }
michael@0 312 finally
michael@0 313 {
michael@0 314 try
michael@0 315 {
michael@0 316 sum += 1;
michael@0 317 print("In finally block of addValues_5() function: sum = " + sum);
michael@0 318 }
michael@0 319 catch (e)
michael@0 320 {
michael@0 321 sum += 1;
michael@0 322 print("In finally catch block of addValues_5() function: sum = " + sum + ", e = " + e);
michael@0 323 }
michael@0 324 finally
michael@0 325 {
michael@0 326 sum += 1;
michael@0 327 print("In finally finally block of addValues_5() function: sum = " + sum);
michael@0 328 return sum;
michael@0 329 }
michael@0 330 }
michael@0 331 }
michael@0 332 }
michael@0 333
michael@0 334 status = inSection(11);
michael@0 335 obj = new Object();
michael@0 336 obj.arg1 = 1;
michael@0 337 obj.arg2 = 2;
michael@0 338 obj.arg3 = new Object();
michael@0 339 obj.arg3.a = 10;
michael@0 340 obj.arg3.b = 20;
michael@0 341 actual = addValues_5(obj);
michael@0 342 expect = 8;
michael@0 343 captureThis();
michael@0 344
michael@0 345
michael@0 346
michael@0 347
michael@0 348 function testObj(obj)
michael@0 349 {
michael@0 350 var x = 42;
michael@0 351
michael@0 352 try
michael@0 353 {
michael@0 354 with (obj)
michael@0 355 {
michael@0 356 if (obj.p)
michael@0 357 throw obj.p;
michael@0 358 x = obj.q;
michael@0 359 }
michael@0 360 }
michael@0 361 finally
michael@0 362 {
michael@0 363 print("in finally block of testObj() function");
michael@0 364 return 999;
michael@0 365 }
michael@0 366 }
michael@0 367
michael@0 368 status = inSection(12);
michael@0 369 obj = {p:43};
michael@0 370 actual = testObj(obj);
michael@0 371 expect = 999;
michael@0 372 captureThis();
michael@0 373
michael@0 374
michael@0 375
michael@0 376 /*
michael@0 377 * Next two cases are from http://bugzilla.mozilla.org/show_bug.cgi?id=120571
michael@0 378 */
michael@0 379 function a120571()
michael@0 380 {
michael@0 381 while(0)
michael@0 382 {
michael@0 383 try
michael@0 384 {
michael@0 385 }
michael@0 386 catch(e)
michael@0 387 {
michael@0 388 continue;
michael@0 389 }
michael@0 390 }
michael@0 391 }
michael@0 392
michael@0 393 // this caused a crash! Test to see that it doesn't now.
michael@0 394 print(a120571);
michael@0 395
michael@0 396 // Now test that we have a non-null value for a120571.toString()
michael@0 397 status = inSection(13);
michael@0 398 try
michael@0 399 {
michael@0 400 actual = a120571.toString().match(/continue/)[0];
michael@0 401 }
michael@0 402 catch(e)
michael@0 403 {
michael@0 404 actual = 'FAILED! Did not find "continue" in function body';
michael@0 405 }
michael@0 406 expect = 'continue';
michael@0 407 captureThis();
michael@0 408
michael@0 409
michael@0 410
michael@0 411
michael@0 412 function b()
michael@0 413 {
michael@0 414 for(;;)
michael@0 415 {
michael@0 416 try
michael@0 417 {
michael@0 418 }
michael@0 419 catch(e)
michael@0 420 {
michael@0 421 continue;
michael@0 422 }
michael@0 423 }
michael@0 424 }
michael@0 425
michael@0 426 // this caused a crash!!! Test to see that it doesn't now.
michael@0 427 print(b);
michael@0 428
michael@0 429 // Now test that we have a non-null value for b.toString()
michael@0 430 status = inSection(14);
michael@0 431 try
michael@0 432 {
michael@0 433 actual = b.toString().match(/continue/)[0];
michael@0 434 }
michael@0 435 catch(e)
michael@0 436 {
michael@0 437 actual = 'FAILED! Did not find "continue" in function body';
michael@0 438 }
michael@0 439 expect = 'continue';
michael@0 440 captureThis();
michael@0 441
michael@0 442
michael@0 443
michael@0 444
michael@0 445
michael@0 446 //-----------------------------------------------------------------------------
michael@0 447 test();
michael@0 448 //-----------------------------------------------------------------------------
michael@0 449
michael@0 450
michael@0 451
michael@0 452 function captureThis()
michael@0 453 {
michael@0 454 statusitems[UBound] = status;
michael@0 455 actualvalues[UBound] = actual;
michael@0 456 expectedvalues[UBound] = expect;
michael@0 457 UBound++;
michael@0 458 }
michael@0 459
michael@0 460
michael@0 461 function test()
michael@0 462 {
michael@0 463 enterFunc ('test');
michael@0 464 printBugNumber(BUGNUMBER);
michael@0 465 printStatus (summary);
michael@0 466
michael@0 467 for (var i=0; i<UBound; i++)
michael@0 468 {
michael@0 469 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
michael@0 470 }
michael@0 471
michael@0 472 exitFunc ('test');
michael@0 473 }

mercurial