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 var setter_value = 0; | 28 var setter_value = 0; |
29 | 29 |
30 __proto__.__defineSetter__("a", function(v) { setter_value = v; }); | 30 this.__defineSetter__("a", function(v) { setter_value = v; }); |
31 eval("var a = 1"); | 31 eval("var a = 1"); |
32 assertEquals(1, setter_value); | 32 assertEquals(1, setter_value); |
33 assertFalse(this.hasOwnProperty("a")); | 33 assertFalse("value" in Object.getOwnPropertyDescriptor(this, "a")); |
34 | 34 |
35 eval("with({}) { eval('var a = 2') }"); | 35 eval("with({}) { eval('var a = 2') }"); |
36 assertEquals(2, setter_value); | 36 assertEquals(2, setter_value); |
37 assertFalse(this.hasOwnProperty("a")); | 37 assertFalse("value" in Object.getOwnPropertyDescriptor(this, "a")); |
38 | 38 |
39 // Function declarations are treated specially to match Safari. We do | 39 // Function declarations are treated specially to match Safari. We do |
40 // not call setters for them. | 40 // not call setters for them. |
| 41 this.__defineSetter__("a", function(v) { assertUnreachable(); }); |
41 eval("function a() {}"); | 42 eval("function a() {}"); |
42 assertTrue(this.hasOwnProperty("a")); | 43 assertTrue("value" in Object.getOwnPropertyDescriptor(this, "a")); |
43 | 44 |
44 __proto__.__defineSetter__("b", function(v) { assertUnreachable(); }); | 45 this.__defineSetter__("b", function(v) { setter_value = v; }); |
45 var exception = false; | |
46 try { | 46 try { |
47 eval("const b = 23"); | 47 eval("const b = 3"); |
48 } catch(e) { | 48 } catch(e) { |
49 exception = true; | 49 assertUnreachable(); |
50 assertTrue(/TypeError/.test(e)); | |
51 } | 50 } |
52 assertFalse(exception); | 51 assertEquals(3, setter_value); |
53 | 52 |
54 exception = false; | |
55 try { | 53 try { |
56 eval("with({}) { eval('const b = 23') }"); | 54 eval("with({}) { eval('const b = 23') }"); |
57 } catch(e) { | 55 } catch(e) { |
58 exception = true; | 56 assertInstanceof(e, TypeError); |
59 assertTrue(/TypeError/.test(e)); | |
60 } | 57 } |
61 assertTrue(exception); | |
62 | 58 |
63 __proto__.__defineSetter__("c", function(v) { throw 42; }); | 59 this.__defineSetter__("c", function(v) { throw 42; }); |
64 exception = false; | |
65 try { | 60 try { |
66 eval("var c = 1"); | 61 eval("var c = 1"); |
| 62 assertUnreachable(); |
67 } catch(e) { | 63 } catch(e) { |
68 exception = true; | |
69 assertEquals(42, e); | 64 assertEquals(42, e); |
70 assertFalse(this.hasOwnProperty("c")); | 65 assertFalse("value" in Object.getOwnPropertyDescriptor(this, "c")); |
71 } | 66 } |
72 assertTrue(exception); | 67 |
| 68 |
| 69 |
| 70 |
| 71 __proto__.__defineSetter__("aa", function(v) { assertUnreachable(); }); |
| 72 eval("var aa = 1"); |
| 73 assertTrue(this.hasOwnProperty("aa")); |
| 74 |
| 75 __proto__.__defineSetter__("bb", function(v) { assertUnreachable(); }); |
| 76 eval("with({}) { eval('var bb = 2') }"); |
| 77 assertTrue(this.hasOwnProperty("bb")); |
| 78 |
| 79 // Function declarations are treated specially to match Safari. We do |
| 80 // not call setters for them. |
| 81 __proto__.__defineSetter__("cc", function(v) { assertUnreachable(); }); |
| 82 eval("function cc() {}"); |
| 83 assertTrue(this.hasOwnProperty("cc")); |
| 84 |
| 85 __proto__.__defineSetter__("dd", function(v) { assertUnreachable(); }); |
| 86 try { |
| 87 eval("const dd = 23"); |
| 88 } catch(e) { |
| 89 assertUnreachable(); |
| 90 } |
| 91 |
| 92 try { |
| 93 eval("with({}) { eval('const dd = 23') }"); |
| 94 } catch(e) { |
| 95 assertInstanceof(e, TypeError); |
| 96 } |
OLD | NEW |