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.

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

mercurial