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.

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

mercurial