tor-browser

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

regress-96284-001.js (3570B)


      1 // |reftest| skip-if(!Error.prototype.toSource)
      2 
      3 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      4 /* This Source Code Form is subject to the terms of the Mozilla Public
      5 * License, v. 2.0. If a copy of the MPL was not distributed with this
      6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      7 
      8 /*
      9 * Date: 03 September 2001
     10 *
     11 * SUMMARY: Double quotes should be escaped in Error.prototype.toSource()
     12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=96284
     13 *
     14 * The real point here is this: we should be able to reconstruct an object
     15 * from its toSource() property. We'll test this on various types of objects.
     16 *
     17 * Method: define obj2 = eval(obj1.toSource()) and verify that
     18 * obj2.toSource() == obj1.toSource().
     19 */
     20 //-----------------------------------------------------------------------------
     21 var UBound = 0;
     22 var BUGNUMBER = 96284;
     23 var summary = 'Double quotes should be escaped in Error.prototype.toSource()';
     24 var status = '';
     25 var statusitems = [];
     26 var actual = '';
     27 var actualvalues = [];
     28 var expect= '';
     29 var expectedvalues = [];
     30 var obj1 = {};
     31 var obj2 = {};
     32 var cnTestString = '"This is a \" STUPID \" test string!!!"\\';
     33 
     34 
     35 // various NativeError objects -
     36 status = inSection(1);
     37 obj1 = Error(cnTestString);
     38 obj2 = eval(obj1.toSource());
     39 actual = obj2.toSource();
     40 expect = obj1.toSource();
     41 addThis();
     42 
     43 status = inSection(2);
     44 obj1 = EvalError(cnTestString);
     45 obj2 = eval(obj1.toSource());
     46 actual = obj2.toSource();
     47 expect = obj1.toSource();
     48 addThis();
     49 
     50 status = inSection(3);
     51 obj1 = RangeError(cnTestString);
     52 obj2 = eval(obj1.toSource());
     53 actual = obj2.toSource();
     54 expect = obj1.toSource();
     55 addThis();
     56 
     57 status = inSection(4);
     58 obj1 = ReferenceError(cnTestString);
     59 obj2 = eval(obj1.toSource());
     60 actual = obj2.toSource();
     61 expect = obj1.toSource();
     62 addThis();
     63 
     64 status = inSection(5);
     65 obj1 = SyntaxError(cnTestString);
     66 obj2 = eval(obj1.toSource());
     67 actual = obj2.toSource();
     68 expect = obj1.toSource();
     69 addThis();
     70 
     71 status = inSection(6);
     72 obj1 = TypeError(cnTestString);
     73 obj2 = eval(obj1.toSource());
     74 actual = obj2.toSource();
     75 expect = obj1.toSource();
     76 addThis();
     77 
     78 status = inSection(7);
     79 obj1 = URIError(cnTestString);
     80 obj2 = eval(obj1.toSource());
     81 actual = obj2.toSource();
     82 expect = obj1.toSource();
     83 addThis();
     84 
     85 
     86 // other types of objects -
     87 status = inSection(8);
     88 obj1 = new String(cnTestString);
     89 obj2 = eval(obj1.toSource());
     90 actual = obj2.toSource();
     91 expect = obj1.toSource();
     92 addThis();
     93 
     94 status = inSection(9);
     95 obj1 = {color:'red', texture:cnTestString, hasOwnProperty:42};
     96 obj2 = eval(obj1.toSource());
     97 actual = obj2.toSource();
     98 expect = obj1.toSource();
     99 addThis();
    100 
    101 status = inSection(10);
    102 obj1 = function(x) {function g(y){return y+1;} return g(x);};
    103 obj2 = eval(obj1.toSource());
    104 actual = obj2.toSource();
    105 expect = obj1.toSource();
    106 addThis();
    107 
    108 status = inSection(11);
    109 obj1 = new Number(eval('6'));
    110 obj2 = eval(obj1.toSource());
    111 actual = obj2.toSource();
    112 expect = obj1.toSource();
    113 addThis();
    114 
    115 status = inSection(12);
    116 obj1 = /ad;(lf)kj(2309\/\/)\/\//;
    117 obj2 = eval(obj1.toSource());
    118 actual = obj2.toSource();
    119 expect = obj1.toSource();
    120 addThis();
    121 
    122 
    123 
    124 //-----------------------------------------------------------------------------
    125 test();
    126 //-----------------------------------------------------------------------------
    127 
    128 
    129 function addThis()
    130 {
    131  statusitems[UBound] = status;
    132  actualvalues[UBound] = actual;
    133  expectedvalues[UBound] = expect;
    134  UBound++;
    135 }
    136 
    137 
    138 function test()
    139 {
    140  printBugNumber(BUGNUMBER);
    141  printStatus (summary);
    142 
    143  for (var i = 0; i < UBound; i++)
    144  {
    145    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    146  }
    147 }