]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/Exceptions/binding-001.js
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an
8 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed
9 * or implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation.
17 * All Rights Reserved.
19 * Contributor(s): brendan@mozilla.org, pschwartau@netscape.com
22 * SUMMARY: Testing binding of function names
26 * "... the question is, does Rhino bind 'sum' in the global object
27 * for the following test? If it does, it's buggy.
29 * var f = function sum(){};
30 * print(sum); // should fail with 'sum is not defined' "
33 //-----------------------------------------------------------------------------
36 var summary
= 'Testing binding of function names';
37 var ERR_REF_YES
= 'ReferenceError';
38 var ERR_REF_NO
= 'did NOT generate a ReferenceError';
40 var actualvalues
= [];
41 var expectedvalues
= [];
43 var actual
= ERR_REF_NO
;
44 var expect
= ERR_REF_YES
;
49 var f
= function sum(){};
54 status
= 'Section 1 of test';
55 actual
= e
instanceof ReferenceError
;
61 * This test is more literal, and one day may not be valid.
62 * Searching for literal string "ReferenceError" in e.toString()
64 status
= 'Section 2 of test';
65 var match
= e
.toString().search(/ReferenceError/);
66 actual
= (match
> -1);
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
80 statusitems
[UBound
] = status
;
81 actualvalues
[UBound
] = isReferenceError(actual
);
82 expectedvalues
[UBound
] = isReferenceError(expect
);
91 printStatus (summary
);
93 for (var i
= 0; i
< UBound
; i
++)
95 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);
102 // converts a Boolean result into a textual result -
103 function isReferenceError(bResult
)
105 return bResult
? ERR_REF_YES : ERR_REF_NO
;