|
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 var BUGNUMBER = 465377; |
|
8 var summary = 'instanceof relations between Error objects'; |
|
9 var actual = ''; |
|
10 var expect = ''; |
|
11 |
|
12 |
|
13 //----------------------------------------------------------------------------- |
|
14 test(); |
|
15 //----------------------------------------------------------------------------- |
|
16 |
|
17 function test() |
|
18 { |
|
19 enterFunc ('test'); |
|
20 printBugNumber(BUGNUMBER); |
|
21 printStatus (summary); |
|
22 |
|
23 expect = actual = 'No Exception'; |
|
24 |
|
25 try |
|
26 { |
|
27 var list = [ |
|
28 "Error", |
|
29 "InternalError", |
|
30 "EvalError", |
|
31 "RangeError", |
|
32 "ReferenceError", |
|
33 "SyntaxError", |
|
34 "TypeError", |
|
35 "URIError" |
|
36 ]; |
|
37 var instances = []; |
|
38 |
|
39 for (var i = 0; i != list.length; ++i) { |
|
40 var name = list[i]; |
|
41 var constructor = this[name]; |
|
42 var tmp = constructor.name; |
|
43 if (tmp !== name) |
|
44 throw "Bad value for "+name+".name: "+uneval(tmp); |
|
45 instances[i] = new constructor(); |
|
46 } |
|
47 |
|
48 for (var i = 0; i != instances.length; ++i) { |
|
49 var instance = instances[i]; |
|
50 var name = instance.name; |
|
51 var constructor = instance.constructor; |
|
52 if (constructor !== this[name]) |
|
53 throw "Bad value of (new "+name+").constructor: "+uneval(tmp); |
|
54 var tmp = constructor.name; |
|
55 if (tmp !== name) |
|
56 throw "Bad value for constructor.name: "+uneval(tmp); |
|
57 if (!(instance instanceof Object)) |
|
58 throw "Bad instanceof Object for "+name; |
|
59 if (!(instance instanceof Error)) |
|
60 throw "Bad instanceof Error for "+name; |
|
61 if (!(instance instanceof constructor)) |
|
62 throw "Bad instanceof constructor for "+name; |
|
63 if (instance instanceof Function) |
|
64 throw "Bad instanceof Function for "+name; |
|
65 for (var j = 1; j != instances.length; ++j) { |
|
66 if (i != j && instance instanceof instances[j].constructor) { |
|
67 throw "Unexpected (new "+name+") instanceof "+ instances[j].name; |
|
68 } |
|
69 } |
|
70 } |
|
71 |
|
72 print("OK"); |
|
73 } |
|
74 catch(ex) |
|
75 { |
|
76 actual = ex + ''; |
|
77 } |
|
78 reportCompare(expect, actual, summary); |
|
79 |
|
80 exitFunc ('test'); |
|
81 } |