Debian Codegraph @

rhino/testsrc/tests/ecma_3/Function/regress-49286.js

raw symbols SCIP
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/. */
5
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 gTestfile = 'regress-49286.js';
19 var UBound = 0;
20 var BUGNUMBER = 49286;
21 var summary = 'Invoking try...catch through Function.call';
22 var cnErrorCaught = 'Error caught';
23 var cnErrorNotCaught = 'Error NOT caught';
24 var cnGoodSyntax = '1==2';
25 var cnBadSyntax = '1=2';
26 var status = '';
27 var statusitems = [];
28 var actual = '';
29 var actualvalues = [];
30 var expect= '';
31 var expectedvalues = [];
32
33
34 var obj = new testObject();
35
36 status = 'Section A of test: direct call of f';
37 actual = f.call(obj);
38 expect = cnErrorCaught;
39 addThis();
40
41 status = 'Section B of test: indirect call of f';
42 actual = g.call(obj);
43 expect = cnErrorCaught;
44 addThis();
45
46
47
48 //-----------------------------------------
49 test();
50 //-----------------------------------------
51
52
53 function test()
54 {
55 enterFunc ('test');
56 printBugNumber(BUGNUMBER);
57 printStatus (summary);
58
59 for (var i=0; i<UBound; i++)
60 {
61 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
62 }
63
64 exitFunc ('test');
65 }
66
67
68 // An object storing bad syntax as a property -
69 function testObject()
70 {
71 this.badSyntax = cnBadSyntax;
72 this.goodSyntax = cnGoodSyntax;
73 }
74
75
76 // A function wrapping a try...catch block
77 function f()
78 {
79 try
80 {
81 eval(this.badSyntax);
82 }
83 catch(e)
84 {
85 return cnErrorCaught;
86 }
87 return cnErrorNotCaught;
88 }
89
90
91 // A function wrapping a call to f -
92 function g()
93 {
94 return f.call(this);
95 }
96
97
98 function addThis()
99 {
100 statusitems[UBound] = status;
101 actualvalues[UBound] = actual;
102 expectedvalues[UBound] = expect;
103 UBound++;
104 }