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.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 * Date: 2001-07-10
michael@0 8 *
michael@0 9 * SUMMARY: Invoking try...catch through Function.call
michael@0 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=49286
michael@0 11 *
michael@0 12 * 1) Define a function with a try...catch block in it
michael@0 13 * 2) Invoke the function via the call method of Function
michael@0 14 * 3) Pass bad syntax to the try...catch block
michael@0 15 * 4) We should catch the error!
michael@0 16 */
michael@0 17 //-----------------------------------------------------------------------------
michael@0 18 var UBound = 0;
michael@0 19 var BUGNUMBER = 49286;
michael@0 20 var summary = 'Invoking try...catch through Function.call';
michael@0 21 var cnErrorCaught = 'Error caught';
michael@0 22 var cnErrorNotCaught = 'Error NOT caught';
michael@0 23 var cnGoodSyntax = '1==2';
michael@0 24 var cnBadSyntax = '1=2';
michael@0 25 var status = '';
michael@0 26 var statusitems = [];
michael@0 27 var actual = '';
michael@0 28 var actualvalues = [];
michael@0 29 var expect= '';
michael@0 30 var expectedvalues = [];
michael@0 31
michael@0 32
michael@0 33 var obj = new testObject();
michael@0 34
michael@0 35 status = 'Section A of test: direct call of f';
michael@0 36 actual = f.call(obj);
michael@0 37 expect = cnErrorCaught;
michael@0 38 addThis();
michael@0 39
michael@0 40 status = 'Section B of test: indirect call of f';
michael@0 41 actual = g.call(obj);
michael@0 42 expect = cnErrorCaught;
michael@0 43 addThis();
michael@0 44
michael@0 45
michael@0 46
michael@0 47 //-----------------------------------------
michael@0 48 test();
michael@0 49 //-----------------------------------------
michael@0 50
michael@0 51
michael@0 52 function test()
michael@0 53 {
michael@0 54 enterFunc ('test');
michael@0 55 printBugNumber(BUGNUMBER);
michael@0 56 printStatus (summary);
michael@0 57
michael@0 58 for (var i=0; i<UBound; i++)
michael@0 59 {
michael@0 60 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
michael@0 61 }
michael@0 62
michael@0 63 exitFunc ('test');
michael@0 64 }
michael@0 65
michael@0 66
michael@0 67 // An object storing bad syntax as a property -
michael@0 68 function testObject()
michael@0 69 {
michael@0 70 this.badSyntax = cnBadSyntax;
michael@0 71 this.goodSyntax = cnGoodSyntax;
michael@0 72 }
michael@0 73
michael@0 74
michael@0 75 // A function wrapping a try...catch block
michael@0 76 function f()
michael@0 77 {
michael@0 78 try
michael@0 79 {
michael@0 80 eval(this.badSyntax);
michael@0 81 }
michael@0 82 catch(e)
michael@0 83 {
michael@0 84 return cnErrorCaught;
michael@0 85 }
michael@0 86 return cnErrorNotCaught;
michael@0 87 }
michael@0 88
michael@0 89
michael@0 90 // A function wrapping a call to f -
michael@0 91 function g()
michael@0 92 {
michael@0 93 return f.call(this);
michael@0 94 }
michael@0 95
michael@0 96
michael@0 97 function addThis()
michael@0 98 {
michael@0 99 statusitems[UBound] = status;
michael@0 100 actualvalues[UBound] = actual;
michael@0 101 expectedvalues[UBound] = expect;
michael@0 102 UBound++;
michael@0 103 }

mercurial