js/src/tests/ecma_3/Exceptions/15.11.1.1.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/15.11.1.1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     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:    27 Nov 2002
    1.12 + * SUMMARY: Ensuring normal function call of Error (ECMA-262 Ed.3 15.11.1.1).
    1.13 + */
    1.14 +//-----------------------------------------------------------------------------
    1.15 +var UBound = 0;
    1.16 +var BUGNUMBER = '';
    1.17 +var summary = 'Ensuring normal function call of Error (ECMA-262 Ed.3 15.11.1.1)';
    1.18 +var status = '';
    1.19 +var statusitems = [];
    1.20 +var actual = '';
    1.21 +var actualvalues = [];
    1.22 +var expect= '';
    1.23 +var expectedvalues = [];
    1.24 +var EMPTY_STRING = '';
    1.25 +var EXPECTED_FORMAT = 0;
    1.26 +
    1.27 +
    1.28 +function otherScope(msg)
    1.29 +{
    1.30 +  return Error(msg);
    1.31 +}
    1.32 +
    1.33 +
    1.34 +status = inSection(1);
    1.35 +var err1 = Error('msg1');
    1.36 +actual = examineThis(err1, 'msg1');
    1.37 +expect = EXPECTED_FORMAT;
    1.38 +addThis();
    1.39 +
    1.40 +status = inSection(2);
    1.41 +var err2 = otherScope('msg2');
    1.42 +actual = examineThis(err2, 'msg2');
    1.43 +expect = EXPECTED_FORMAT;
    1.44 +addThis();
    1.45 +
    1.46 +status = inSection(3);
    1.47 +var err3 = otherScope();
    1.48 +actual = examineThis(err3, EMPTY_STRING);
    1.49 +expect = EXPECTED_FORMAT;
    1.50 +addThis();
    1.51 +
    1.52 +status = inSection(4);
    1.53 +var err4 = eval("Error('msg4')");
    1.54 +actual = examineThis(err4, 'msg4');
    1.55 +expect = EXPECTED_FORMAT;
    1.56 +addThis();
    1.57 +
    1.58 +
    1.59 +
    1.60 +//-----------------------------------------------------------------------------
    1.61 +test();
    1.62 +//-----------------------------------------------------------------------------
    1.63 +
    1.64 +
    1.65 +
    1.66 +/*
    1.67 + * Searches err.toString() for err.name + ':' + err.message,
    1.68 + * with possible whitespace on each side of the colon sign.
    1.69 + *
    1.70 + * We allow for no colon in case err.message was not provided by the user.
    1.71 + * In such a case, SpiderMonkey and Rhino currently set err.message = '',
    1.72 + * as allowed for by ECMA 15.11.4.3. This makes |pattern| work in this case.
    1.73 + *
    1.74 + * If this is ever changed to a non-empty string, e.g. 'undefined',
    1.75 + * you may have to modify |pattern| to take that into account -
    1.76 + *
    1.77 + */
    1.78 +function examineThis(err, msg)
    1.79 +{
    1.80 +  var pattern = err.name + '\\s*:?\\s*' + msg;
    1.81 +  return err.toString().search(RegExp(pattern));
    1.82 +}
    1.83 +
    1.84 +
    1.85 +function addThis()
    1.86 +{
    1.87 +  statusitems[UBound] = status;
    1.88 +  actualvalues[UBound] = actual;
    1.89 +  expectedvalues[UBound] = expect;
    1.90 +  UBound++;
    1.91 +}
    1.92 +
    1.93 +
    1.94 +function test()
    1.95 +{
    1.96 +  enterFunc ('test');
    1.97 +  printBugNumber(BUGNUMBER);
    1.98 +  printStatus (summary);
    1.99 +
   1.100 +  for (var i = 0; i < UBound; i++)
   1.101 +  {
   1.102 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.103 +  }
   1.104 +
   1.105 +  exitFunc ('test');
   1.106 +}

mercurial