js/src/tests/js1_5/Exceptions/errstack-001.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: 28 Feb 2002
michael@0 9 * SUMMARY: Testing that Error.stack distinguishes between:
michael@0 10 *
michael@0 11 * A) top-level calls: myFunc();
michael@0 12 * B) no-name function calls: function() { myFunc();} ()
michael@0 13 *
michael@0 14 * The stack frame for A) should begin with '@'
michael@0 15 * The stack frame for B) should begin with '()'
michael@0 16 *
michael@0 17 * This behavior was coded by Brendan during his fix for bug 127136.
michael@0 18 * See http://bugzilla.mozilla.org/show_bug.cgi?id=127136#c13
michael@0 19 *
michael@0 20 * Note: our function getStackFrames(err) orders the array of stack frames
michael@0 21 * so that the 0th element will correspond to the highest frame, i.e. will
michael@0 22 * correspond to a line in top-level code. The 1st element will correspond
michael@0 23 * to the function that is called first, and so on...
michael@0 24 *
michael@0 25 * NOTE: At present Rhino does not have an Error.stack property. It is an
michael@0 26 * ECMA extension, see http://bugzilla.mozilla.org/show_bug.cgi?id=123177
michael@0 27 */
michael@0 28 //-----------------------------------------------------------------------------
michael@0 29 var UBound = 0;
michael@0 30 var BUGNUMBER = '(none)';
michael@0 31 var summary = 'Testing Error.stack';
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 var myErr = '';
michael@0 39 var stackFrames = '';
michael@0 40
michael@0 41
michael@0 42 function A(x,y)
michael@0 43 {
michael@0 44 return B(x+1,y+1);
michael@0 45 }
michael@0 46
michael@0 47 function B(x,z)
michael@0 48 {
michael@0 49 return C(x+1,z+1);
michael@0 50 }
michael@0 51
michael@0 52 function C(x,y)
michael@0 53 {
michael@0 54 return D(x+1,y+1);
michael@0 55 }
michael@0 56
michael@0 57 function D(x,z)
michael@0 58 {
michael@0 59 try
michael@0 60 {
michael@0 61 throw new Error('meep!');
michael@0 62 }
michael@0 63 catch (e)
michael@0 64 {
michael@0 65 return e;
michael@0 66 }
michael@0 67 }
michael@0 68
michael@0 69
michael@0 70 myErr = A(44,13);
michael@0 71 stackFrames = getStackFrames(myErr);
michael@0 72 status = inSection(1);
michael@0 73 actual = stackFrames[0].substring(0,1);
michael@0 74 expect = '@';
michael@0 75 addThis();
michael@0 76
michael@0 77 status = inSection(2);
michael@0 78 actual = stackFrames[1].substring(0,2);
michael@0 79 expect = 'A@';
michael@0 80 addThis();
michael@0 81
michael@0 82 status = inSection(3);
michael@0 83 actual = stackFrames[2].substring(0,2);
michael@0 84 expect = 'B@';
michael@0 85 addThis();
michael@0 86
michael@0 87 status = inSection(4);
michael@0 88 actual = stackFrames[3].substring(0,2);
michael@0 89 expect = 'C@';
michael@0 90 addThis();
michael@0 91
michael@0 92 status = inSection(5);
michael@0 93 actual = stackFrames[4].substring(0,2);
michael@0 94 expect = 'D@';
michael@0 95 addThis();
michael@0 96
michael@0 97
michael@0 98
michael@0 99 myErr = A('44:foo','13:bar');
michael@0 100 stackFrames = getStackFrames(myErr);
michael@0 101 status = inSection(6);
michael@0 102 actual = stackFrames[0].substring(0,1);
michael@0 103 expect = '@';
michael@0 104 addThis();
michael@0 105
michael@0 106 status = inSection(7);
michael@0 107 actual = stackFrames[1].substring(0,2);
michael@0 108 expect = 'A@';
michael@0 109 addThis();
michael@0 110
michael@0 111 status = inSection(8);
michael@0 112 actual = stackFrames[2].substring(0,2);
michael@0 113 expect = 'B@';
michael@0 114 addThis();
michael@0 115
michael@0 116 status = inSection(9);
michael@0 117 actual = stackFrames[3].substring(0,2);
michael@0 118 expect = 'C@';
michael@0 119 addThis();
michael@0 120
michael@0 121 status = inSection(10);
michael@0 122 actual = stackFrames[4].substring(0,2);
michael@0 123 expect = 'D@';;
michael@0 124 addThis();
michael@0 125
michael@0 126
michael@0 127
michael@0 128 /*
michael@0 129 * Make the first frame occur in a function with an empty name -
michael@0 130 */
michael@0 131 myErr = function() { return A(44,13); } ();
michael@0 132 stackFrames = getStackFrames(myErr);
michael@0 133 status = inSection(11);
michael@0 134 actual = stackFrames[0].substring(0,1);
michael@0 135 expect = '@';
michael@0 136 addThis();
michael@0 137
michael@0 138 status = inSection(12);
michael@0 139 actual = stackFrames[1].substring(0,7);
michael@0 140 expect = 'myErr<@';
michael@0 141 addThis();
michael@0 142
michael@0 143 status = inSection(13);
michael@0 144 actual = stackFrames[2].substring(0,2);
michael@0 145 expect = 'A@';
michael@0 146 addThis();
michael@0 147
michael@0 148 // etc. for the rest of the frames as above
michael@0 149
michael@0 150
michael@0 151
michael@0 152 /*
michael@0 153 * Make the first frame occur in a function with name 'anonymous' -
michael@0 154 */
michael@0 155 var f = Function('return A(44,13);');
michael@0 156 myErr = f();
michael@0 157 stackFrames = getStackFrames(myErr);
michael@0 158 status = inSection(14);
michael@0 159 actual = stackFrames[0].substring(0,1);
michael@0 160 expect = '@';
michael@0 161 addThis();
michael@0 162
michael@0 163 status = inSection(15);
michael@0 164 actual = stackFrames[1].substring(0,10);
michael@0 165 expect = 'anonymous@';
michael@0 166 addThis();
michael@0 167
michael@0 168 status = inSection(16);
michael@0 169 actual = stackFrames[2].substring(0,2);
michael@0 170 expect = 'A@';
michael@0 171 addThis();
michael@0 172
michael@0 173 // etc. for the rest of the frames as above
michael@0 174
michael@0 175
michael@0 176
michael@0 177 /*
michael@0 178 * Make a user-defined error via the Error() function -
michael@0 179 */
michael@0 180 var message = 'Hi there!'; var fileName = 'file name'; var lineNumber = 0;
michael@0 181 myErr = Error(message, fileName, lineNumber);
michael@0 182 stackFrames = getStackFrames(myErr);
michael@0 183 status = inSection(17);
michael@0 184 actual = stackFrames[0].substring(0,1);
michael@0 185 expect = '@';
michael@0 186 addThis();
michael@0 187
michael@0 188
michael@0 189 /*
michael@0 190 * Now use the |new| keyword. Re-use the same params -
michael@0 191 */
michael@0 192 myErr = new Error(message, fileName, lineNumber);
michael@0 193 stackFrames = getStackFrames(myErr);
michael@0 194 status = inSection(18);
michael@0 195 actual = stackFrames[0].substring(0,1);
michael@0 196 expect = '@';
michael@0 197 addThis();
michael@0 198
michael@0 199
michael@0 200
michael@0 201
michael@0 202 //-----------------------------------------------------------------------------
michael@0 203 test();
michael@0 204 //-----------------------------------------------------------------------------
michael@0 205
michael@0 206
michael@0 207
michael@0 208 /*
michael@0 209 * Split the string |err.stack| along its '\n' delimiter.
michael@0 210 * As of 2002-02-28 |err.stack| ends with the delimiter, so
michael@0 211 * the resulting array has an empty string as its last element.
michael@0 212 *
michael@0 213 * Pop that useless element off before doing anything.
michael@0 214 * Then reverse the array, for convenience of indexing -
michael@0 215 */
michael@0 216 function getStackFrames(err)
michael@0 217 {
michael@0 218 var arr = err.stack.split('\n');
michael@0 219 arr.pop();
michael@0 220 return arr.reverse();
michael@0 221 }
michael@0 222
michael@0 223
michael@0 224 function addThis()
michael@0 225 {
michael@0 226 statusitems[UBound] = status;
michael@0 227 actualvalues[UBound] = actual;
michael@0 228 expectedvalues[UBound] = expect;
michael@0 229 UBound++;
michael@0 230 }
michael@0 231
michael@0 232
michael@0 233 function test()
michael@0 234 {
michael@0 235 enterFunc('test');
michael@0 236 printBugNumber(BUGNUMBER);
michael@0 237 printStatus(summary);
michael@0 238
michael@0 239 for (var i=0; i<UBound; i++)
michael@0 240 {
michael@0 241 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
michael@0 242 }
michael@0 243
michael@0 244 exitFunc ('test');
michael@0 245 }

mercurial