js/src/tests/js1_5/extensions/regress-226507.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:    24 Nov 2003
     9  * SUMMARY: Testing for recursion check in js_EmitTree
    10  *
    11  * See http://bugzilla.mozilla.org/show_bug.cgi?id=226507
    12  * Igor's comments:
    13  *
    14  * "For example, with N in the test  set to 35, I got on my RedHat
    15  * Linux 10 box a segmentation fault from js after setting the stack limit
    16  * to 100K. When I set the stack limit to 20K I still got the segmentation fault.
    17  * Only after -s was changed to 15K, too-deep recursion was detected:
    18  *
    20  ~/w/js/x> ulimit -s
    21  100
    22  ~/w/js/x> js  fintest.js
    23  Segmentation fault
    24  ~/w/js/x> js -S $((20*1024)) fintest.js
    25  Segmentation fault
    26  ~/w/js/x> js -S $((15*1024)) fintest.js
    27  fintest.js:19: InternalError: too much recursion
    29  *
    30  * After playing with numbers it seems that while processing try/finally the
    31  * recursion in js_Emit takes 10 times more space the corresponding recursion
    32  * in the parser."
    33  *
    34  *
    35  * Note the use of the new -S option to the JS shell to limit stack size.
    36  * See http://bugzilla.mozilla.org/show_bug.cgi?id=225061. This in turn
    37  * can be passed to the JS shell by the test driver's -o option, as in:
    38  *
    39  * perl jsDriver.pl -e smdebug -fTEST.html -o "-S 100" -l js1_5/Regress
    40  *
    41  */
    42 //-----------------------------------------------------------------------------
    43 var UBound = 0;
    44 var BUGNUMBER = 226507;
    45 var summary = 'Testing for recursion check in js_EmitTree';
    46 var status = '';
    47 var statusitems = [];
    48 var actual = '';
    49 var actualvalues = [];
    50 var expect= '';
    51 var expectedvalues = [];
    54 /*
    55  * With stack limit 100K on Linux debug build even N=30 already can cause
    56  * stack overflow; use 35 to trigger it for sure.
    57  */
    58 var N = 350;
    60 var counter = 0;
    61 function f()
    62 {
    63   ++counter;
    64 }
    67 /*
    68  * Example: if N were 3, this is what |source|
    69  * would end up looking like:
    70  *
    71  *     try { f(); } finally {
    72  *     try { f(); } finally {
    73  *     try { f(); } finally {
    74  *     f(1,1,1,1);
    75  *     }}}
    76  *
    77  */
    78 var source = "".concat(
    79   repeat_str("try { f(); } finally {\n", N),
    80   "f(",
    81   repeat_str("1,", N),
    82   "1);\n",
    83   repeat_str("}", N));
    85 // Repeat it for additional stress testing
    86 source += source;
    88 /*
    89  * In Rhino, eval() always uses interpreted mode.
    90  * To use compiled mode, use Script.exec() instead.
    91  */
    92 if (typeof Script == 'undefined')
    93 {
    94   print('Test skipped. Script not defined.');
    95   expect = actual = 0;
    96 }
    97 else
    98 {
    99   try
   100   {
   101     var script = Script(source);
   102     script();
   105     status = inSection(1);
   106     actual = counter;
   107     expect = (N + 1) * 2;
   108   }
   109   catch(ex)
   110   {
   111     actual = ex + '';
   112   }
   113 }
   114 addThis();
   117 //-----------------------------------------------------------------------------
   118 test();
   119 //-----------------------------------------------------------------------------
   123 function repeat_str(str, repeat_count)
   124 {
   125   var arr = new Array(--repeat_count);
   126   while (repeat_count != 0)
   127     arr[--repeat_count] = str;
   128   return str.concat.apply(str, arr);
   129 }
   132 function addThis()
   133 {
   134   statusitems[UBound] = status;
   135   actualvalues[UBound] = actual;
   136   expectedvalues[UBound] = expect;
   137   UBound++;
   138 }
   141 function test()
   142 {
   143   enterFunc('test');
   144   printBugNumber(BUGNUMBER);
   145   printStatus(summary);
   147   for (var i=0; i<UBound; i++)
   148   {
   149     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   150   }
   152   exitFunc ('test');
   153 }

mercurial