js/src/tests/ecma_3/Exceptions/regress-181914.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/Exceptions/regress-181914.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,160 @@
     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 + *
    1.11 + * Date:    25 Nov 2002
    1.12 + * SUMMARY: Calling a user-defined superconstructor
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=181914, esp. Comment 10.
    1.14 + *
    1.15 + */
    1.16 +//-----------------------------------------------------------------------------
    1.17 +var UBound = 0;
    1.18 +var BUGNUMBER = '181914';
    1.19 +var summary = 'Calling a user-defined superconstructor';
    1.20 +var status = '';
    1.21 +var statusitems = [];
    1.22 +var actual = '';
    1.23 +var actualvalues = [];
    1.24 +var expect= '';
    1.25 +var expectedvalues = [];
    1.26 +var EMPTY_STRING = '';
    1.27 +var EXPECTED_FORMAT = 0;
    1.28 +
    1.29 +
    1.30 +// make a user-defined version of the Error constructor
    1.31 +function _Error(msg)
    1.32 +{
    1.33 +  this.message = msg;
    1.34 +}
    1.35 +_Error.prototype = new Error();
    1.36 +_Error.prototype.name = '_Error';
    1.37 +
    1.38 +
    1.39 +// derive MyApplyError from _Error
    1.40 +function MyApplyError(msg)
    1.41 +{
    1.42 +  if(this instanceof MyApplyError)
    1.43 +    _Error.apply(this, arguments);
    1.44 +  else
    1.45 +    return new MyApplyError(msg);
    1.46 +}
    1.47 +MyApplyError.prototype = new _Error();
    1.48 +MyApplyError.prototype.name = "MyApplyError";
    1.49 +
    1.50 +
    1.51 +// derive MyCallError from _Error
    1.52 +function MyCallError(msg)
    1.53 +{
    1.54 +  if(this instanceof MyCallError)
    1.55 +    _Error.call(this, msg);
    1.56 +  else
    1.57 +    return new MyCallError(msg);
    1.58 +}
    1.59 +MyCallError.prototype = new _Error();
    1.60 +MyCallError.prototype.name = "MyCallError";
    1.61 +
    1.62 +
    1.63 +function otherScope(msg)
    1.64 +{
    1.65 +  return MyApplyError(msg);
    1.66 +}
    1.67 +
    1.68 +
    1.69 +status = inSection(1);
    1.70 +var err1 = new MyApplyError('msg1');
    1.71 +actual = examineThis(err1, 'msg1');
    1.72 +expect = EXPECTED_FORMAT;
    1.73 +addThis();
    1.74 +
    1.75 +status = inSection(2);
    1.76 +var err2 = new MyCallError('msg2');
    1.77 +actual = examineThis(err2, 'msg2');
    1.78 +expect = EXPECTED_FORMAT;
    1.79 +addThis();
    1.80 +
    1.81 +status = inSection(3);
    1.82 +var err3 = MyApplyError('msg3');
    1.83 +actual = examineThis(err3, 'msg3');
    1.84 +expect = EXPECTED_FORMAT;
    1.85 +addThis();
    1.86 +
    1.87 +status = inSection(4);
    1.88 +var err4 = MyCallError('msg4');
    1.89 +actual = examineThis(err4, 'msg4');
    1.90 +expect = EXPECTED_FORMAT;
    1.91 +addThis();
    1.92 +
    1.93 +status = inSection(5);
    1.94 +var err5 = otherScope('msg5');
    1.95 +actual = examineThis(err5, 'msg5');
    1.96 +expect = EXPECTED_FORMAT;
    1.97 +addThis();
    1.98 +
    1.99 +status = inSection(6);
   1.100 +var err6 = otherScope();
   1.101 +actual = examineThis(err6, EMPTY_STRING);
   1.102 +expect = EXPECTED_FORMAT;
   1.103 +addThis();
   1.104 +
   1.105 +status = inSection(7);
   1.106 +var err7 = eval("MyApplyError('msg7')");
   1.107 +actual = examineThis(err7, 'msg7');
   1.108 +expect = EXPECTED_FORMAT;
   1.109 +addThis();
   1.110 +
   1.111 +status = inSection(8);
   1.112 +var err8;
   1.113 +try
   1.114 +{
   1.115 +  throw MyApplyError('msg8');
   1.116 +}
   1.117 +catch(e)
   1.118 +{
   1.119 +  if(e instanceof Error)
   1.120 +    err8 = e;
   1.121 +}
   1.122 +actual = examineThis(err8, 'msg8');
   1.123 +expect = EXPECTED_FORMAT;
   1.124 +addThis();
   1.125 +
   1.126 +
   1.127 +
   1.128 +//-----------------------------------------------------------------------------
   1.129 +test();
   1.130 +//-----------------------------------------------------------------------------
   1.131 +
   1.132 +
   1.133 +
   1.134 +// Searches |err.toString()| for |err.name + ':' + err.message|
   1.135 +function examineThis(err, msg)
   1.136 +{
   1.137 +  var pattern = err.name + '\\s*:?\\s*' + msg;
   1.138 +  return err.toString().search(RegExp(pattern));
   1.139 +}
   1.140 +
   1.141 +
   1.142 +function addThis()
   1.143 +{
   1.144 +  statusitems[UBound] = status;
   1.145 +  actualvalues[UBound] = actual;
   1.146 +  expectedvalues[UBound] = expect;
   1.147 +  UBound++;
   1.148 +}
   1.149 +
   1.150 +
   1.151 +function test()
   1.152 +{
   1.153 +  enterFunc ('test');
   1.154 +  printBugNumber(BUGNUMBER);
   1.155 +  printStatus (summary);
   1.156 +
   1.157 +  for (var i = 0; i < UBound; i++)
   1.158 +  {
   1.159 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.160 +  }
   1.161 +
   1.162 +  exitFunc ('test');
   1.163 +}

mercurial