OLD | NEW |
| (Empty) |
1 // Copyright 2013 the V8 project authors. All rights reserved. | |
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | |
3 // | |
4 // Redistribution and use in source and binary forms, with or without | |
5 // modification, are permitted provided that the following conditions | |
6 // are met: | |
7 // 1. Redistributions of source code must retain the above copyright | |
8 // notice, this list of conditions and the following disclaimer. | |
9 // 2. Redistributions in binary form must reproduce the above copyright | |
10 // notice, this list of conditions and the following disclaimer in the | |
11 // documentation and/or other materials provided with the distribution. | |
12 // | |
13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | |
14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | |
17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | |
20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
23 | |
24 description("KDE JS Test"); | |
25 function kdeShouldBe(a, b, c) | |
26 { | |
27 if ( a == b ) | |
28 debug(c+" .......... Passed"); | |
29 else | |
30 debug(c+" .......... Failed"); | |
31 } | |
32 | |
33 function testThrow() | |
34 { | |
35 var caught = false; | |
36 try { | |
37 throw 99; | |
38 } catch (e) { | |
39 caught = true; | |
40 } | |
41 kdeShouldBe(caught, true, "testing throw()"); | |
42 } | |
43 | |
44 // same as above but lacking a semicolon after throw | |
45 function testThrow2() | |
46 { | |
47 var caught = false; | |
48 try { | |
49 throw 99 | |
50 } catch (e) { | |
51 caught = true; | |
52 } | |
53 kdeShouldBe(caught, true, "testing throw()"); | |
54 } | |
55 | |
56 function testReferenceError() | |
57 { | |
58 var err = "noerror"; | |
59 var caught = false; | |
60 try { | |
61 var dummy = nonexistant; // throws reference error | |
62 } catch (e) { | |
63 caught = true; | |
64 err = e.name; | |
65 } | |
66 // test err | |
67 kdeShouldBe(caught, true, "ReferenceError"); | |
68 } | |
69 | |
70 function testFunctionErrorHelper() | |
71 { | |
72 var a = b; // throws reference error | |
73 } | |
74 | |
75 function testFunctionError() | |
76 { | |
77 var caught = false; | |
78 try { | |
79 testFunctionErrorHelper(); | |
80 } catch (e) { | |
81 caught = true; | |
82 } | |
83 kdeShouldBe(caught, true, "error propagation in functions"); | |
84 } | |
85 | |
86 function testMathFunctionError() | |
87 { | |
88 var caught = false; | |
89 try { | |
90 Math(); | |
91 } catch (e) { | |
92 debug("catch"); | |
93 caught = true; | |
94 } finally { | |
95 debug("finally"); | |
96 } | |
97 kdeShouldBe(caught, true, "Math() error"); | |
98 } | |
99 | |
100 function testWhileAbortion() | |
101 { | |
102 var caught = 0; | |
103 try { | |
104 while (a=b, 1) { // "endless error" in condition | |
105 ; | |
106 } | |
107 } catch (e) { | |
108 caught++; | |
109 } | |
110 | |
111 try { | |
112 while (1) { | |
113 var a = b; // error in body | |
114 } | |
115 } catch (e) { | |
116 caught++; | |
117 } | |
118 kdeShouldBe(caught, 2, "Abort while() on error"); | |
119 } | |
120 | |
121 debug("Except a lot of errors. They should all be caught and lead to PASS"); | |
122 testThrow(); | |
123 testThrow2(); | |
124 testReferenceError(); | |
125 testFunctionError(); | |
126 testMathFunctionError(); | |
127 testWhileAbortion(); | |
OLD | NEW |