js/src/tests/js1_5/Regress/regress-146596.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:    18 Jun 2002
     9  * SUMMARY: Shouldn't crash when catch parameter is "hidden" by varX
    10  * See http://bugzilla.mozilla.org/show_bug.cgi?id=146596
    11  *
    12  */
    13 //-----------------------------------------------------------------------------
    14 var UBound = 0;
    15 var BUGNUMBER = 146596;
    16 var summary = "Shouldn't crash when catch parameter is 'hidden' by varX";
    17 var status = '';
    18 var statusitems = [];
    19 var actual = '';
    20 var actualvalues = [];
    21 var expect= '';
    22 var expectedvalues = [];
    25 /*
    26  * Just seeing we don't crash when executing this function -
    27  * This example provided by jim-patterson@ncf.ca
    28  *
    29  * Brendan: "Jim, thanks for the testcase. But note that |var|
    30  * in a JS function makes a function-scoped variable --  JS lacks
    31  * block scope apart from for catch variables within catch blocks.
    32  *
    33  * Therefore the catch variable hides the function-local variable."
    34  */
    35 function F()
    36 {
    37   try
    38   {
    39     return "A simple exception";
    40   }
    41   catch(e)
    42   {
    43     var e = "Another exception";
    44   }
    46   return 'XYZ';
    47 }
    49 status = inSection(1);
    50 actual = F();
    51 expect = "A simple exception";
    52 addThis();
    56 /*
    57  * Sanity check by Brendan: "This should output
    58  *
    59  *             24
    60  *             42
    61  *          undefined
    62  *
    63  * and throw no uncaught exception."
    64  *
    65  */
    66 function f(obj)
    67 {
    68   var res = [];
    70   try
    71   {
    72     throw 42;
    73   }
    74   catch(e)
    75   {
    76     with(obj)
    77     {
    78       var e;
    79       res[0] = e; // |with| binds tighter than |catch|; s/b |obj.e|
    80     }
    82     res[1] = e;   // |catch| binds tighter than function scope; s/b 42
    83   }
    85   res[2] = e;     // |var e| has function scope; s/b visible but contain |undefined|
    86   return res;
    87 }
    89 status = inSection(2);
    90 actual = f({e:24});
    91 expect = [24, 42, undefined];
    92 addThis();
    97 //-----------------------------------------------------------------------------
    98 test();
    99 //-----------------------------------------------------------------------------
   103 function addThis()
   104 {
   105   statusitems[UBound] = status;
   106   actualvalues[UBound] = actual.toString();
   107   expectedvalues[UBound] = expect.toString();
   108   UBound++;
   109 }
   112 function test()
   113 {
   114   enterFunc('test');
   115   printBugNumber(BUGNUMBER);
   116   printStatus(summary);
   118   for (var i=0; i<UBound; i++)
   119   {
   120     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   121   }
   123   exitFunc ('test');
   124 }

mercurial