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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /*
     7  *
     8  * Date:    19 Mar 2002
     9  * SUMMARY: Function declarations in global or function scope are {DontDelete}.
    10  *          Function declarations in eval scope are not {DontDelete}.
    11  *
    12  * See http://bugzilla.mozilla.org/show_bug.cgi?id=131964
    13  *
    14  */
    15 //-----------------------------------------------------------------------------
    16 var UBound = 0;
    17 var BUGNUMBER =   131964;
    18 var summary = 'Functions defined in global or function scope are {DontDelete}';
    19 var status = '';
    20 var statusitems = [];
    21 var actual = '';
    22 var actualvalues = [];
    23 var expect= '';
    24 var expectedvalues = [];
    27 status = inSection(1);
    28 function f()
    29 {
    30   return 'f lives!';
    31 }
    32 delete f;
    34 try
    35 {
    36   actual = f();
    37 }
    38 catch(e)
    39 {
    40   actual = 'f was deleted';
    41 }
    43 expect = 'f lives!';
    44 addThis();
    48 /*
    49  * Try the same test in function scope -
    50  */
    51 status = inSection(2);
    52 function g()
    53 {
    54   function f()
    55   {
    56     return 'f lives!';
    57   }
    58   delete f;
    60   try
    61   {
    62     actual = f();
    63   }
    64   catch(e)
    65   {
    66     actual = 'f was deleted';
    67   }
    69   expect = 'f lives!';
    70   addThis();
    71 }
    72 g();
    76 /*
    77  * Try the same test in eval scope - here we EXPECT the function to be deleted (?)
    78  */
    79 status = inSection(3);
    80 var s = '';
    81 s += 'function h()';
    82 s += '{ ';
    83 s += '  return "h lives!";';
    84 s += '}';
    85 s += 'delete h;';
    87 s += 'try';
    88 s += '{';
    89 s += '  actual = h();';
    90 s += '}';
    91 s += 'catch(e)';
    92 s += '{';
    93 s += '  actual = "h was deleted";';
    94 s += '}';
    96 s += 'expect = "h was deleted";';
    97 s += 'addThis();';
    98 eval(s);
   101 /*
   102  * Define the function in eval scope, but delete it in global scope -
   103  */
   104 status = inSection(4);
   105 s = '';
   106 s += 'function k()';
   107 s += '{ ';
   108 s += '  return "k lives!";';
   109 s += '}';
   110 eval(s);
   112 delete k;
   114 try
   115 {
   116   actual = k();
   117 }
   118 catch(e)
   119 {
   120   actual = 'k was deleted';
   121 }
   123 expect = 'k was deleted';
   124 addThis();
   129 //-----------------------------------------------------------------------------
   130 test();
   131 //-----------------------------------------------------------------------------
   135 function wasDeleted(functionName)
   136 {
   137   return functionName + ' was deleted...';
   138 }
   141 function addThis()
   142 {
   143   statusitems[UBound] = status;
   144   actualvalues[UBound] = actual;
   145   expectedvalues[UBound] = expect;
   146   UBound++;
   147 }
   150 function test()
   151 {
   152   enterFunc('test');
   153   printBugNumber(BUGNUMBER);
   154   printStatus(summary);
   156   for (var i=0; i<UBound; i++)
   157   {
   158     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   159   }
   161   exitFunc ('test');
   162 }

mercurial