tor-browser

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

regress-181914.js (3333B)


      1 /* -*- 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:    25 Nov 2002
      9 * SUMMARY: Calling a user-defined superconstructor
     10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=181914, esp. Comment 10.
     11 *
     12 */
     13 //-----------------------------------------------------------------------------
     14 var UBound = 0;
     15 var BUGNUMBER = '181914';
     16 var summary = 'Calling a user-defined superconstructor';
     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 // make a user-defined version of the Error constructor
     28 function _Error(msg)
     29 {
     30  this.message = msg;
     31 }
     32 _Error.prototype = new Error();
     33 _Error.prototype.name = '_Error';
     34 
     35 
     36 // derive MyApplyError from _Error
     37 function MyApplyError(msg)
     38 {
     39  if(this instanceof MyApplyError)
     40    _Error.apply(this, arguments);
     41  else
     42    return new MyApplyError(msg);
     43 }
     44 MyApplyError.prototype = new _Error();
     45 MyApplyError.prototype.name = "MyApplyError";
     46 
     47 
     48 // derive MyCallError from _Error
     49 function MyCallError(msg)
     50 {
     51  if(this instanceof MyCallError)
     52    _Error.call(this, msg);
     53  else
     54    return new MyCallError(msg);
     55 }
     56 MyCallError.prototype = new _Error();
     57 MyCallError.prototype.name = "MyCallError";
     58 
     59 
     60 function otherScope(msg)
     61 {
     62  return MyApplyError(msg);
     63 }
     64 
     65 
     66 status = inSection(1);
     67 var err1 = new MyApplyError('msg1');
     68 actual = examineThis(err1, 'msg1');
     69 expect = EXPECTED_FORMAT;
     70 addThis();
     71 
     72 status = inSection(2);
     73 var err2 = new MyCallError('msg2');
     74 actual = examineThis(err2, 'msg2');
     75 expect = EXPECTED_FORMAT;
     76 addThis();
     77 
     78 status = inSection(3);
     79 var err3 = MyApplyError('msg3');
     80 actual = examineThis(err3, 'msg3');
     81 expect = EXPECTED_FORMAT;
     82 addThis();
     83 
     84 status = inSection(4);
     85 var err4 = MyCallError('msg4');
     86 actual = examineThis(err4, 'msg4');
     87 expect = EXPECTED_FORMAT;
     88 addThis();
     89 
     90 status = inSection(5);
     91 var err5 = otherScope('msg5');
     92 actual = examineThis(err5, 'msg5');
     93 expect = EXPECTED_FORMAT;
     94 addThis();
     95 
     96 status = inSection(6);
     97 var err6 = otherScope();
     98 actual = examineThis(err6, EMPTY_STRING);
     99 expect = EXPECTED_FORMAT;
    100 addThis();
    101 
    102 status = inSection(7);
    103 var err7 = eval("MyApplyError('msg7')");
    104 actual = examineThis(err7, 'msg7');
    105 expect = EXPECTED_FORMAT;
    106 addThis();
    107 
    108 status = inSection(8);
    109 var err8;
    110 try
    111 {
    112  throw MyApplyError('msg8');
    113 }
    114 catch(e)
    115 {
    116  if(e instanceof Error)
    117    err8 = e;
    118 }
    119 actual = examineThis(err8, 'msg8');
    120 expect = EXPECTED_FORMAT;
    121 addThis();
    122 
    123 
    124 
    125 //-----------------------------------------------------------------------------
    126 test();
    127 //-----------------------------------------------------------------------------
    128 
    129 
    130 
    131 // Searches |err.toString()| for |err.name + ':' + err.message|
    132 function examineThis(err, msg)
    133 {
    134  var pattern = err.name + '\\s*:?\\s*' + msg;
    135  return err.toString().search(RegExp(pattern));
    136 }
    137 
    138 
    139 function addThis()
    140 {
    141  statusitems[UBound] = status;
    142  actualvalues[UBound] = actual;
    143  expectedvalues[UBound] = expect;
    144  UBound++;
    145 }
    146 
    147 
    148 function test()
    149 {
    150  printBugNumber(BUGNUMBER);
    151  printStatus (summary);
    152 
    153  for (var i = 0; i < UBound; i++)
    154  {
    155    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    156  }
    157 }