js/src/tests/ecma_3/Function/regress-49286.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/Function/regress-49286.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 + * Date: 2001-07-10
    1.11 + *
    1.12 + * SUMMARY:  Invoking try...catch through Function.call
    1.13 + * See  http://bugzilla.mozilla.org/show_bug.cgi?id=49286
    1.14 + *
    1.15 + * 1) Define a function with a try...catch block in it
    1.16 + * 2) Invoke the function via the call method of Function
    1.17 + * 3) Pass bad syntax to the try...catch block
    1.18 + * 4) We should catch the error!
    1.19 + */
    1.20 +//-----------------------------------------------------------------------------
    1.21 +var UBound = 0;
    1.22 +var BUGNUMBER = 49286;
    1.23 +var summary = 'Invoking try...catch through Function.call';
    1.24 +var cnErrorCaught = 'Error caught';
    1.25 +var cnErrorNotCaught = 'Error NOT caught';
    1.26 +var cnGoodSyntax = '1==2';
    1.27 +var cnBadSyntax = '1=2';
    1.28 +var status = '';
    1.29 +var statusitems = [];
    1.30 +var actual = '';
    1.31 +var actualvalues = [];
    1.32 +var expect= '';
    1.33 +var expectedvalues = [];
    1.34 +
    1.35 +
    1.36 +var obj = new testObject();
    1.37 +
    1.38 +status = 'Section A of test: direct call of f';
    1.39 +actual = f.call(obj);
    1.40 +expect = cnErrorCaught;
    1.41 +addThis();
    1.42 +
    1.43 +status = 'Section B of test: indirect call of f';
    1.44 +actual = g.call(obj);
    1.45 +expect = cnErrorCaught;
    1.46 +addThis();
    1.47 +
    1.48 +
    1.49 +
    1.50 +//-----------------------------------------
    1.51 +test();
    1.52 +//-----------------------------------------
    1.53 +
    1.54 +
    1.55 +function test()
    1.56 +{
    1.57 +  enterFunc ('test');
    1.58 +  printBugNumber(BUGNUMBER);
    1.59 +  printStatus (summary);
    1.60 +
    1.61 +  for (var i=0; i<UBound; i++)
    1.62 +  {
    1.63 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    1.64 +  }
    1.65 +
    1.66 +  exitFunc ('test');
    1.67 +}
    1.68 +
    1.69 +
    1.70 +// An object storing bad syntax as a property -
    1.71 +function testObject()
    1.72 +{
    1.73 +  this.badSyntax = cnBadSyntax;
    1.74 +  this.goodSyntax = cnGoodSyntax;
    1.75 +}
    1.76 +
    1.77 +
    1.78 +// A function wrapping a try...catch block
    1.79 +function f()
    1.80 +{
    1.81 +  try
    1.82 +  {
    1.83 +    eval(this.badSyntax);
    1.84 +  }
    1.85 +  catch(e)
    1.86 +  {
    1.87 +    return cnErrorCaught;
    1.88 +  }
    1.89 +  return cnErrorNotCaught;
    1.90 +}
    1.91 +
    1.92 +
    1.93 +// A function wrapping a call to f -
    1.94 +function g()
    1.95 +{
    1.96 +  return f.call(this);
    1.97 +}
    1.98 +
    1.99 +
   1.100 +function addThis()
   1.101 +{
   1.102 +  statusitems[UBound] = status;
   1.103 +  actualvalues[UBound] = actual;
   1.104 +  expectedvalues[UBound] = expect;
   1.105 +  UBound++;
   1.106 +}

mercurial