js/src/tests/ecma_3/Function/regress-49286.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  * Date: 2001-07-10
     8  *
     9  * SUMMARY:  Invoking try...catch through Function.call
    10  * See  http://bugzilla.mozilla.org/show_bug.cgi?id=49286
    11  *
    12  * 1) Define a function with a try...catch block in it
    13  * 2) Invoke the function via the call method of Function
    14  * 3) Pass bad syntax to the try...catch block
    15  * 4) We should catch the error!
    16  */
    17 //-----------------------------------------------------------------------------
    18 var UBound = 0;
    19 var BUGNUMBER = 49286;
    20 var summary = 'Invoking try...catch through Function.call';
    21 var cnErrorCaught = 'Error caught';
    22 var cnErrorNotCaught = 'Error NOT caught';
    23 var cnGoodSyntax = '1==2';
    24 var cnBadSyntax = '1=2';
    25 var status = '';
    26 var statusitems = [];
    27 var actual = '';
    28 var actualvalues = [];
    29 var expect= '';
    30 var expectedvalues = [];
    33 var obj = new testObject();
    35 status = 'Section A of test: direct call of f';
    36 actual = f.call(obj);
    37 expect = cnErrorCaught;
    38 addThis();
    40 status = 'Section B of test: indirect call of f';
    41 actual = g.call(obj);
    42 expect = cnErrorCaught;
    43 addThis();
    47 //-----------------------------------------
    48 test();
    49 //-----------------------------------------
    52 function test()
    53 {
    54   enterFunc ('test');
    55   printBugNumber(BUGNUMBER);
    56   printStatus (summary);
    58   for (var i=0; i<UBound; i++)
    59   {
    60     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    61   }
    63   exitFunc ('test');
    64 }
    67 // An object storing bad syntax as a property -
    68 function testObject()
    69 {
    70   this.badSyntax = cnBadSyntax;
    71   this.goodSyntax = cnGoodSyntax;
    72 }
    75 // A function wrapping a try...catch block
    76 function f()
    77 {
    78   try
    79   {
    80     eval(this.badSyntax);
    81   }
    82   catch(e)
    83   {
    84     return cnErrorCaught;
    85   }
    86   return cnErrorNotCaught;
    87 }
    90 // A function wrapping a call to f -
    91 function g()
    92 {
    93   return f.call(this);
    94 }
    97 function addThis()
    98 {
    99   statusitems[UBound] = status;
   100   actualvalues[UBound] = actual;
   101   expectedvalues[UBound] = expect;
   102   UBound++;
   103 }

mercurial