tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

regress-181654.js (2865B)


      1 /* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 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/. */
      5 
      6 /*
      7 *
      8 * Date:    23 Nov 2002
      9 * SUMMARY: Calling toString for an object derived from the Error class
     10 *		   results in an TypeError (Rhino only)
     11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=181654
     12 */
     13 //-----------------------------------------------------------------------------
     14 var UBound = 0;
     15 var BUGNUMBER = '181654';
     16 var summary = 'Calling toString for an object derived from the Error class should be possible.';
     17 var status = '';
     18 var statusitems = [];
     19 var actual = '';
     20 var actualvalues = [];
     21 var expect= '';
     22 var expectedvalues = [];
     23 var EMPTY_STRING = '';
     24 var EXPECTED_FORMAT = 0;
     25 
     26 
     27 // derive MyError from Error
     28 function MyError( msg )
     29 {
     30  this.message = msg;
     31 }
     32 MyError.prototype = new Error();
     33 MyError.prototype.name = "MyError";
     34 
     35 
     36 status = inSection(1);
     37 var err1 = new MyError('msg1');
     38 actual = examineThis(err1, 'msg1');
     39 expect = EXPECTED_FORMAT;
     40 addThis();
     41 
     42 status = inSection(2);
     43 var err2 = new MyError(String(err1));
     44 actual = examineThis(err2, err1);
     45 expect = EXPECTED_FORMAT;
     46 addThis();
     47 
     48 status = inSection(3);
     49 var err3 = new MyError();
     50 actual = examineThis(err3, EMPTY_STRING);
     51 expect = EXPECTED_FORMAT;
     52 addThis();
     53 
     54 status = inSection(4);
     55 var err4 = new MyError(EMPTY_STRING);
     56 actual = examineThis(err4, EMPTY_STRING);
     57 expect = EXPECTED_FORMAT;
     58 addThis();
     59 
     60 // now generate an error -
     61 status = inSection(5);
     62 try
     63 {
     64  throw new MyError("thrown");
     65 }
     66 catch(err5)
     67 {
     68  actual = examineThis(err5, "thrown");
     69 }
     70 expect = EXPECTED_FORMAT;
     71 addThis();
     72 
     73 
     74 
     75 //-----------------------------------------------------------------------------
     76 test();
     77 //-----------------------------------------------------------------------------
     78 
     79 
     80 
     81 /*
     82 * Searches err.toString() for err.name + ':' + err.message,
     83 * with possible whitespace on each side of the colon sign.
     84 *
     85 * We allow for no colon in case err.message was not provided by the user.
     86 * In such a case, SpiderMonkey and Rhino currently set err.message = '',
     87 * as allowed for by ECMA 15.11.4.3. This makes |pattern| work in this case.
     88 *
     89 * If this is ever changed to a non-empty string, e.g. 'undefined',
     90 * you may have to modify |pattern| to take that into account -
     91 *
     92 */
     93 function examineThis(err, msg)
     94 {
     95  var pattern = err.name + '\\s*:?\\s*' + msg;
     96  return err.toString().search(RegExp(pattern));
     97 }
     98 
     99 
    100 function addThis()
    101 {
    102  statusitems[UBound] = status;
    103  actualvalues[UBound] = actual;
    104  expectedvalues[UBound] = expect;
    105  UBound++;
    106 }
    107 
    108 
    109 function test()
    110 {
    111  printBugNumber(BUGNUMBER);
    112  printStatus (summary);
    113 
    114  for (var i = 0; i < UBound; i++)
    115  {
    116    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    117  }
    118 }