js/src/tests/js1_5/extensions/regress-96284-001.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/extensions/regress-96284-001.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,148 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Date: 03 September 2001
    1.11 + *
    1.12 + * SUMMARY: Double quotes should be escaped in Error.prototype.toSource()
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=96284
    1.14 + *
    1.15 + * The real point here is this: we should be able to reconstruct an object
    1.16 + * from its toSource() property. We'll test this on various types of objects.
    1.17 + *
    1.18 + * Method: define obj2 = eval(obj1.toSource()) and verify that
    1.19 + * obj2.toSource() == obj1.toSource().
    1.20 + */
    1.21 +//-----------------------------------------------------------------------------
    1.22 +var UBound = 0;
    1.23 +var BUGNUMBER = 96284;
    1.24 +var summary = 'Double quotes should be escaped in Error.prototype.toSource()';
    1.25 +var status = '';
    1.26 +var statusitems = [];
    1.27 +var actual = '';
    1.28 +var actualvalues = [];
    1.29 +var expect= '';
    1.30 +var expectedvalues = [];
    1.31 +var obj1 = {};
    1.32 +var obj2 = {};
    1.33 +var cnTestString = '"This is a \" STUPID \" test string!!!"\\';
    1.34 +
    1.35 +
    1.36 +// various NativeError objects -
    1.37 +status = inSection(1);
    1.38 +obj1 = Error(cnTestString);
    1.39 +obj2 = eval(obj1.toSource());
    1.40 +actual = obj2.toSource();
    1.41 +expect = obj1.toSource();
    1.42 +addThis();
    1.43 +
    1.44 +status = inSection(2);
    1.45 +obj1 = EvalError(cnTestString);
    1.46 +obj2 = eval(obj1.toSource());
    1.47 +actual = obj2.toSource();
    1.48 +expect = obj1.toSource();
    1.49 +addThis();
    1.50 +
    1.51 +status = inSection(3);
    1.52 +obj1 = RangeError(cnTestString);
    1.53 +obj2 = eval(obj1.toSource());
    1.54 +actual = obj2.toSource();
    1.55 +expect = obj1.toSource();
    1.56 +addThis();
    1.57 +
    1.58 +status = inSection(4);
    1.59 +obj1 = ReferenceError(cnTestString);
    1.60 +obj2 = eval(obj1.toSource());
    1.61 +actual = obj2.toSource();
    1.62 +expect = obj1.toSource();
    1.63 +addThis();
    1.64 +
    1.65 +status = inSection(5);
    1.66 +obj1 = SyntaxError(cnTestString);
    1.67 +obj2 = eval(obj1.toSource());
    1.68 +actual = obj2.toSource();
    1.69 +expect = obj1.toSource();
    1.70 +addThis();
    1.71 +
    1.72 +status = inSection(6);
    1.73 +obj1 = TypeError(cnTestString);
    1.74 +obj2 = eval(obj1.toSource());
    1.75 +actual = obj2.toSource();
    1.76 +expect = obj1.toSource();
    1.77 +addThis();
    1.78 +
    1.79 +status = inSection(7);
    1.80 +obj1 = URIError(cnTestString);
    1.81 +obj2 = eval(obj1.toSource());
    1.82 +actual = obj2.toSource();
    1.83 +expect = obj1.toSource();
    1.84 +addThis();
    1.85 +
    1.86 +
    1.87 +// other types of objects -
    1.88 +status = inSection(8);
    1.89 +obj1 = new String(cnTestString);
    1.90 +obj2 = eval(obj1.toSource());
    1.91 +actual = obj2.toSource();
    1.92 +expect = obj1.toSource();
    1.93 +addThis();
    1.94 +
    1.95 +status = inSection(9);
    1.96 +obj1 = {color:'red', texture:cnTestString, hasOwnProperty:42};
    1.97 +obj2 = eval(obj1.toSource());
    1.98 +actual = obj2.toSource();
    1.99 +expect = obj1.toSource();
   1.100 +addThis();
   1.101 +
   1.102 +status = inSection(10);
   1.103 +obj1 = function(x) {function g(y){return y+1;} return g(x);};
   1.104 +obj2 = eval(obj1.toSource());
   1.105 +actual = obj2.toSource();
   1.106 +expect = obj1.toSource();
   1.107 +addThis();
   1.108 +
   1.109 +status = inSection(11);
   1.110 +obj1 = new Number(eval('6'));
   1.111 +obj2 = eval(obj1.toSource());
   1.112 +actual = obj2.toSource();
   1.113 +expect = obj1.toSource();
   1.114 +addThis();
   1.115 +
   1.116 +status = inSection(12);
   1.117 +obj1 = /ad;(lf)kj(2309\/\/)\/\//;
   1.118 +obj2 = eval(obj1.toSource());
   1.119 +actual = obj2.toSource();
   1.120 +expect = obj1.toSource();
   1.121 +addThis();
   1.122 +
   1.123 +
   1.124 +
   1.125 +//-----------------------------------------------------------------------------
   1.126 +test();
   1.127 +//-----------------------------------------------------------------------------
   1.128 +
   1.129 +
   1.130 +function addThis()
   1.131 +{
   1.132 +  statusitems[UBound] = status;
   1.133 +  actualvalues[UBound] = actual;
   1.134 +  expectedvalues[UBound] = expect;
   1.135 +  UBound++;
   1.136 +}
   1.137 +
   1.138 +
   1.139 +function test()
   1.140 +{
   1.141 +  enterFunc ('test');
   1.142 +  printBugNumber(BUGNUMBER);
   1.143 +  printStatus (summary);
   1.144 +
   1.145 +  for (var i = 0; i < UBound; i++)
   1.146 +  {
   1.147 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.148 +  }
   1.149 +
   1.150 +  exitFunc ('test');
   1.151 +}

mercurial