Debian Codegraph @

rhino/testsrc/tests/ecma_3/Exceptions/binding-001.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-08-27
8 *
9 * SUMMARY: Testing binding of function names
10 *
11 * Brendan:
12 *
13 * "... the question is, does Rhino bind 'sum' in the global object
14 * for the following test? If it does, it's buggy.
15 *
16 * var f = function sum(){};
17 * print(sum); // should fail with 'sum is not defined' "
18 *
19 */
20
21 //-----------------------------------------------------------------------------
22 var gTestfile = 'binding-001.js';
23 var UBound = 0;
24 var BUGNUMBER = '(none)';
25 var summary = 'Testing binding of function names';
26 var ERR_REF_YES = 'ReferenceError';
27 var ERR_REF_NO = 'did NOT generate a ReferenceError';
28 var statusitems = [];
29 var actualvalues = [];
30 var expectedvalues = [];
31 var status = summary;
32 var actual = ERR_REF_NO;
33 var expect= ERR_REF_YES;
34
35
36 try
37 {
38 var f = function sum(){};
39 print(sum);
40 }
41 catch (e)
42 {
43 status = 'Section 1 of test';
44 actual = e instanceof ReferenceError;
45 expect = true;
46 addThis();
47
48
49 /*
50 * This test is more literal, and one day may not be valid.
51 * Searching for literal string "ReferenceError" in e.toString()
52 */
53 status = 'Section 2 of test';
54 var match = e.toString().search(/ReferenceError/);
55 actual = (match > -1);
56 expect = true;
57 addThis();
58 }
59
60
61
62 //-----------------------------------------------------------------------------
63 test();
64 //-----------------------------------------------------------------------------
65
66
67 function addThis()
68 {
69 statusitems[UBound] = status;
70 actualvalues[UBound] = isReferenceError(actual);
71 expectedvalues[UBound] = isReferenceError(expect);
72 UBound++;
73 }
74
75
76 function test()
77 {
78 enterFunc ('test');
79 printBugNumber(BUGNUMBER);
80 printStatus (summary);
81
82 for (var i = 0; i < UBound; i++)
83 {
84 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
85 }
86
87 exitFunc ('test');
88 }
89
90
91 // converts a Boolean result into a textual result -
92 function isReferenceError(bResult)
93 {
94 return bResult? ERR_REF_YES : ERR_REF_NO;
95 }