tor-browser

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

regress-465377.js (2322B)


      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 var BUGNUMBER = 465377;
      8 var summary = 'instanceof relations between Error objects';
      9 var actual = '';
     10 var expect = '';
     11 
     12 
     13 //-----------------------------------------------------------------------------
     14 test();
     15 //-----------------------------------------------------------------------------
     16 
     17 function test()
     18 {
     19  printBugNumber(BUGNUMBER);
     20  printStatus (summary);
     21 
     22  expect = actual = 'No Exception';
     23 
     24  try
     25  {
     26    var list = [
     27      "Error",
     28      "InternalError",
     29      "EvalError",
     30      "RangeError",
     31      "ReferenceError",
     32      "SyntaxError",
     33      "TypeError",
     34      "URIError"
     35      ];
     36    var instances = [];
     37 
     38    for (var i = 0; i != list.length; ++i) {
     39      var name = list[i];
     40      var constructor = this[name];
     41      var tmp = constructor.name;
     42      if (tmp !== name)
     43        throw "Bad value for "+name+".name: "+String(tmp);
     44      instances[i] = new constructor();
     45    }
     46 
     47    for (var i = 0; i != instances.length; ++i) {
     48      var instance = instances[i];
     49      var name = instance.name;
     50      var constructor = instance.constructor;
     51      var tmp = constructor.name;
     52      if (constructor !== this[name])
     53        throw "Bad value of (new "+name+").constructor: "+String(tmp);
     54      if (tmp !== name)
     55        throw "Bad value for constructor.name: "+String(tmp);
     56      if (!(instance instanceof Object))
     57        throw "Bad instanceof Object for "+name;
     58      if (!(instance instanceof Error))
     59        throw "Bad instanceof Error for "+name;
     60      if (!(instance instanceof constructor))
     61        throw "Bad instanceof constructor for "+name;
     62      if (instance instanceof Function)
     63        throw "Bad instanceof Function for "+name;
     64      for (var j = 1; j != instances.length; ++j) {
     65        if (i != j && instance instanceof instances[j].constructor) {
     66          throw "Unexpected (new "+name+") instanceof "+ instances[j].name;
     67        }
     68      }
     69    }
     70 
     71    print("OK");
     72  }
     73  catch(ex)
     74  {
     75    actual = ex + '';
     76  }
     77  reportCompare(expect, actual, summary);
     78 }