|
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 UBound = 0; |
|
23 var BUGNUMBER = '(none)'; |
|
24 var summary = 'Testing binding of function names'; |
|
25 var ERR_REF_YES = 'ReferenceError'; |
|
26 var ERR_REF_NO = 'did NOT generate a ReferenceError'; |
|
27 var statusitems = []; |
|
28 var actualvalues = []; |
|
29 var expectedvalues = []; |
|
30 var status = summary; |
|
31 var actual = ERR_REF_NO; |
|
32 var expect= ERR_REF_YES; |
|
33 |
|
34 |
|
35 try |
|
36 { |
|
37 var f = function sum(){}; |
|
38 print(sum); |
|
39 } |
|
40 catch (e) |
|
41 { |
|
42 status = 'Section 1 of test'; |
|
43 actual = e instanceof ReferenceError; |
|
44 expect = true; |
|
45 addThis(); |
|
46 |
|
47 |
|
48 /* |
|
49 * This test is more literal, and one day may not be valid. |
|
50 * Searching for literal string "ReferenceError" in e.toString() |
|
51 */ |
|
52 status = 'Section 2 of test'; |
|
53 var match = e.toString().search(/ReferenceError/); |
|
54 actual = (match > -1); |
|
55 expect = true; |
|
56 addThis(); |
|
57 } |
|
58 |
|
59 |
|
60 |
|
61 //----------------------------------------------------------------------------- |
|
62 test(); |
|
63 //----------------------------------------------------------------------------- |
|
64 |
|
65 |
|
66 function addThis() |
|
67 { |
|
68 statusitems[UBound] = status; |
|
69 actualvalues[UBound] = isReferenceError(actual); |
|
70 expectedvalues[UBound] = isReferenceError(expect); |
|
71 UBound++; |
|
72 } |
|
73 |
|
74 |
|
75 function test() |
|
76 { |
|
77 enterFunc ('test'); |
|
78 printBugNumber(BUGNUMBER); |
|
79 printStatus (summary); |
|
80 |
|
81 for (var i = 0; i < UBound; i++) |
|
82 { |
|
83 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
|
84 } |
|
85 |
|
86 exitFunc ('test'); |
|
87 } |
|
88 |
|
89 |
|
90 // converts a Boolean result into a textual result - |
|
91 function isReferenceError(bResult) |
|
92 { |
|
93 return bResult? ERR_REF_YES : ERR_REF_NO; |
|
94 } |