js/src/tests/ecma_3/Function/regress-131964.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-131964.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,162 @@
     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:    19 Mar 2002
    1.12 + * SUMMARY: Function declarations in global or function scope are {DontDelete}.
    1.13 + *          Function declarations in eval scope are not {DontDelete}.
    1.14 + *
    1.15 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=131964
    1.16 + *
    1.17 + */
    1.18 +//-----------------------------------------------------------------------------
    1.19 +var UBound = 0;
    1.20 +var BUGNUMBER =   131964;
    1.21 +var summary = 'Functions defined in global or function scope are {DontDelete}';
    1.22 +var status = '';
    1.23 +var statusitems = [];
    1.24 +var actual = '';
    1.25 +var actualvalues = [];
    1.26 +var expect= '';
    1.27 +var expectedvalues = [];
    1.28 +
    1.29 +
    1.30 +status = inSection(1);
    1.31 +function f()
    1.32 +{
    1.33 +  return 'f lives!';
    1.34 +}
    1.35 +delete f;
    1.36 +
    1.37 +try
    1.38 +{
    1.39 +  actual = f();
    1.40 +}
    1.41 +catch(e)
    1.42 +{
    1.43 +  actual = 'f was deleted';
    1.44 +}
    1.45 +
    1.46 +expect = 'f lives!';
    1.47 +addThis();
    1.48 +
    1.49 +
    1.50 +
    1.51 +/*
    1.52 + * Try the same test in function scope -
    1.53 + */
    1.54 +status = inSection(2);
    1.55 +function g()
    1.56 +{
    1.57 +  function f()
    1.58 +  {
    1.59 +    return 'f lives!';
    1.60 +  }
    1.61 +  delete f;
    1.62 +
    1.63 +  try
    1.64 +  {
    1.65 +    actual = f();
    1.66 +  }
    1.67 +  catch(e)
    1.68 +  {
    1.69 +    actual = 'f was deleted';
    1.70 +  }
    1.71 +
    1.72 +  expect = 'f lives!';
    1.73 +  addThis();
    1.74 +}
    1.75 +g();
    1.76 +
    1.77 +
    1.78 +
    1.79 +/*
    1.80 + * Try the same test in eval scope - here we EXPECT the function to be deleted (?)
    1.81 + */
    1.82 +status = inSection(3);
    1.83 +var s = '';
    1.84 +s += 'function h()';
    1.85 +s += '{ ';
    1.86 +s += '  return "h lives!";';
    1.87 +s += '}';
    1.88 +s += 'delete h;';
    1.89 +
    1.90 +s += 'try';
    1.91 +s += '{';
    1.92 +s += '  actual = h();';
    1.93 +s += '}';
    1.94 +s += 'catch(e)';
    1.95 +s += '{';
    1.96 +s += '  actual = "h was deleted";';
    1.97 +s += '}';
    1.98 +
    1.99 +s += 'expect = "h was deleted";';
   1.100 +s += 'addThis();';
   1.101 +eval(s);
   1.102 +
   1.103 +
   1.104 +/*
   1.105 + * Define the function in eval scope, but delete it in global scope -
   1.106 + */
   1.107 +status = inSection(4);
   1.108 +s = '';
   1.109 +s += 'function k()';
   1.110 +s += '{ ';
   1.111 +s += '  return "k lives!";';
   1.112 +s += '}';
   1.113 +eval(s);
   1.114 +
   1.115 +delete k;
   1.116 +
   1.117 +try
   1.118 +{
   1.119 +  actual = k();
   1.120 +}
   1.121 +catch(e)
   1.122 +{
   1.123 +  actual = 'k was deleted';
   1.124 +}
   1.125 +
   1.126 +expect = 'k was deleted';
   1.127 +addThis();
   1.128 +
   1.129 +
   1.130 +
   1.131 +
   1.132 +//-----------------------------------------------------------------------------
   1.133 +test();
   1.134 +//-----------------------------------------------------------------------------
   1.135 +
   1.136 +
   1.137 +
   1.138 +function wasDeleted(functionName)
   1.139 +{
   1.140 +  return functionName + ' was deleted...';
   1.141 +}
   1.142 +
   1.143 +
   1.144 +function addThis()
   1.145 +{
   1.146 +  statusitems[UBound] = status;
   1.147 +  actualvalues[UBound] = actual;
   1.148 +  expectedvalues[UBound] = expect;
   1.149 +  UBound++;
   1.150 +}
   1.151 +
   1.152 +
   1.153 +function test()
   1.154 +{
   1.155 +  enterFunc('test');
   1.156 +  printBugNumber(BUGNUMBER);
   1.157 +  printStatus(summary);
   1.158 +
   1.159 +  for (var i=0; i<UBound; i++)
   1.160 +  {
   1.161 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.162 +  }
   1.163 +
   1.164 +  exitFunc ('test');
   1.165 +}

mercurial