16147
|
1 |
/*
|
16151
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
16147
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/**
|
|
25 |
* Basic checks for Error constructors.
|
|
26 |
*
|
|
27 |
* @test
|
|
28 |
* @run
|
|
29 |
*/
|
|
30 |
|
|
31 |
print(Error.name + " is a " + typeof(Error));
|
|
32 |
print(EvalError.name + " is a " + typeof(EvalError));
|
|
33 |
print(RangeError.name + " is a " + typeof(RangeError));
|
|
34 |
print(ReferenceError.name + " is a " + typeof(ReferenceError));
|
|
35 |
print(SyntaxError.name + " is a " + typeof(SyntaxError));
|
|
36 |
print(TypeError.name + " is a " + typeof(TypeError));
|
|
37 |
print(URIError.name + " is a " + typeof(URIError));
|
|
38 |
|
|
39 |
print("Error.arity " + Error.length);
|
|
40 |
print("EvalError.arity " + EvalError.length);
|
|
41 |
print("RangeError.arity " + RangeError.length);
|
|
42 |
print("ReferenceError.arity " + ReferenceError.length);
|
|
43 |
print("SyntaxError.arity " + SyntaxError.length);
|
|
44 |
print("TypeError.arity " + TypeError.length);
|
|
45 |
print("URIError.arity " + URIError.length);
|
|
46 |
|
|
47 |
var err = new Error("my error");
|
|
48 |
try {
|
|
49 |
throw err;
|
|
50 |
} catch (e) {
|
|
51 |
print(e instanceof Error);
|
|
52 |
print(e.message);
|
|
53 |
print(e.name);
|
|
54 |
var ne = e.nashornException;
|
|
55 |
if (ne != undefined) {
|
|
56 |
if (ne.fileName !== __FILE__) {
|
|
57 |
fail("incorrect filename in error");
|
|
58 |
}
|
|
59 |
print("thrown @ " + ne.lineNumber);
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
|
63 |
// try to print undefined global var..
|
|
64 |
try {
|
|
65 |
print(foo);
|
|
66 |
} catch (e) {
|
|
67 |
print(e instanceof ReferenceError);
|
|
68 |
print(e.name);
|
|
69 |
print(e.message);
|
|
70 |
}
|
|
71 |
|
|
72 |
// try to call something that is undefined
|
|
73 |
try {
|
|
74 |
Object.foo_method();
|
|
75 |
} catch (e) {
|
|
76 |
print(e instanceof TypeError);
|
|
77 |
print(e.name);
|
|
78 |
print(e.message);
|
|
79 |
}
|
|
80 |
|
|
81 |
// prototypes of Error constructors are not writable
|
|
82 |
Error.prototype = {};
|
|
83 |
print(Error.prototype.name);
|
|
84 |
EvalError.prototype = {};
|
|
85 |
print(EvalError.prototype.name);
|
|
86 |
RangeError.prototype = {};
|
|
87 |
print(RangeError.prototype.name);
|
|
88 |
ReferenceError.prototype = {};
|
|
89 |
print(ReferenceError.prototype.name);
|
|
90 |
SyntaxError.prototype = {};
|
|
91 |
print(SyntaxError.prototype.name);
|
|
92 |
TypeError.prototype = {};
|
|
93 |
print(TypeError.prototype.name);
|
|
94 |
URIError.prototype = {};
|
|
95 |
print(URIError.prototype.name);
|