OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --allow-natives-syntax | |
29 | |
30 // Check that message and name are not enumerable on Error objects. | 28 // Check that message and name are not enumerable on Error objects. |
31 var desc = Object.getOwnPropertyDescriptor(Error.prototype, 'name'); | 29 var desc = Object.getOwnPropertyDescriptor(Error.prototype, 'name'); |
32 assertFalse(desc['enumerable']); | 30 assertFalse(desc['enumerable']); |
33 desc = Object.getOwnPropertyDescriptor(Error.prototype, 'message'); | 31 desc = Object.getOwnPropertyDescriptor(Error.prototype, 'message'); |
34 assertFalse(desc['enumerable']); | 32 assertFalse(desc['enumerable']); |
35 | 33 |
36 var e = new Error("foobar"); | 34 var e = new Error("foobar"); |
37 desc = Object.getOwnPropertyDescriptor(e, 'message'); | 35 desc = Object.getOwnPropertyDescriptor(e, 'message'); |
38 assertFalse(desc['enumerable']); | 36 assertFalse(desc['enumerable']); |
39 desc = Object.getOwnPropertyDescriptor(e, 'stack'); | 37 desc = Object.getOwnPropertyDescriptor(e, 'stack'); |
(...skipping 15 matching lines...) Expand all Loading... |
55 ReferenceError.prototype.__defineSetter__('message', fail); | 53 ReferenceError.prototype.__defineSetter__('message', fail); |
56 ReferenceError.prototype.__defineSetter__('stack', fail); | 54 ReferenceError.prototype.__defineSetter__('stack', fail); |
57 | 55 |
58 var e = new ReferenceError(); | 56 var e = new ReferenceError(); |
59 assertTrue(e.hasOwnProperty('stack')); | 57 assertTrue(e.hasOwnProperty('stack')); |
60 | 58 |
61 var e = new ReferenceError('123'); | 59 var e = new ReferenceError('123'); |
62 assertTrue(e.hasOwnProperty('message')); | 60 assertTrue(e.hasOwnProperty('message')); |
63 assertTrue(e.hasOwnProperty('stack')); | 61 assertTrue(e.hasOwnProperty('stack')); |
64 | 62 |
65 var e = %MakeReferenceError("my_test_error", [0, 1]); | 63 try { |
| 64 eval("var error = reference"); |
| 65 } catch (error) { |
| 66 e = error; |
| 67 } |
| 68 |
66 assertTrue(e.hasOwnProperty('stack')); | 69 assertTrue(e.hasOwnProperty('stack')); |
67 | 70 |
68 // Check that intercepting property access from toString is prevented for | 71 // Check that intercepting property access from toString is prevented for |
69 // compiler errors. This is not specified, but allowing interception | 72 // compiler errors. This is not specified, but allowing interception |
70 // through a getter can leak error objects from different | 73 // through a getter can leak error objects from different |
71 // script tags in the same context in a browser setting. | 74 // script tags in the same context in a browser setting. |
72 var errors = [SyntaxError, ReferenceError, TypeError, RangeError, URIError]; | 75 var errors = [SyntaxError, ReferenceError, TypeError, RangeError, URIError]; |
73 var error_triggers = ["syntax error", | 76 var error_triggers = ["syntax error", |
74 "var error = reference", | 77 "var error = reference", |
75 "undefined()", | 78 "undefined()", |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 var e = new errors[i]; | 125 var e = new errors[i]; |
123 assertEquals("my: moo", e.toString()); | 126 assertEquals("my: moo", e.toString()); |
124 } | 127 } |
125 | 128 |
126 | 129 |
127 Error.prototype.toString = Object.prototype.toString; | 130 Error.prototype.toString = Object.prototype.toString; |
128 assertEquals("[object Error]", Error.prototype.toString()); | 131 assertEquals("[object Error]", Error.prototype.toString()); |
129 assertEquals(Object.prototype, Error.prototype.__proto__); | 132 assertEquals(Object.prototype, Error.prototype.__proto__); |
130 var e = new Error("foo"); | 133 var e = new Error("foo"); |
131 assertEquals("[object Error]", e.toString()); | 134 assertEquals("[object Error]", e.toString()); |
OLD | NEW |