OLD | NEW |
(Empty) | |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 |
| 28 // Regression test for Chromium issue 70066. Delete should work properly |
| 29 // from inside 'with' scopes. |
| 30 // http://code.google.com/p/chromium/issues/detail?id=70066 |
| 31 |
| 32 x = 0; |
| 33 |
| 34 // Delete on a slot from a function's own context. |
| 35 function test1() { |
| 36 var value = 1; |
| 37 var status; |
| 38 with ({}) { status = delete value; } |
| 39 return value + ":" + status; |
| 40 } |
| 41 |
| 42 assertEquals("1:false", test1(), "test1"); |
| 43 assertEquals(0, x, "test1"); // Global x is undisturbed. |
| 44 |
| 45 |
| 46 // Delete on a slot from an outer context. |
| 47 function test2() { |
| 48 function f() { |
| 49 with ({}) { return delete value; } |
| 50 } |
| 51 var value = 2; |
| 52 var status = f(); |
| 53 return value + ":" + status; |
| 54 } |
| 55 |
| 56 assertEquals("2:false", test2(), "test2"); |
| 57 assertEquals(0, x, "test2"); // Global x is undisturbed. |
| 58 |
| 59 |
| 60 // Delete on an argument (should be the same code paths as test1 and test2). |
| 61 function test3(value) { |
| 62 var status; |
| 63 with ({}) { status = delete value; } |
| 64 return value + ":" + status; |
| 65 } |
| 66 |
| 67 assertEquals("3:false", test3(3), "test3"); |
| 68 assertEquals(0, x, "test3"); // Global x is undisturbed. |
| 69 |
| 70 function test4(value) { |
| 71 function f() { |
| 72 with ({}) { return delete value; } |
| 73 } |
| 74 var status = f(); |
| 75 return value + ":" + status; |
| 76 } |
| 77 |
| 78 assertEquals("4:false", test4(4), "test4"); |
| 79 assertEquals(0, x, "test4"); // Global x is undisturbed. |
| 80 |
| 81 |
| 82 // Delete on an argument found in the arguments object. Such properties are |
| 83 // normally DONT_DELETE in JavaScript but deletion is allowed by V8. |
| 84 function test5(value) { |
| 85 var status; |
| 86 with ({}) { status = delete value; } |
| 87 return arguments[0] + ":" + status; |
| 88 } |
| 89 |
| 90 assertEquals("undefined:true", test5(5), "test5"); |
| 91 assertEquals(0, x, "test5"); // Global x is undisturbed. |
| 92 |
| 93 function test6(value) { |
| 94 function f() { |
| 95 with ({}) { return delete value; } |
| 96 } |
| 97 var status = f(); |
| 98 return arguments[0] + ":" + status; |
| 99 } |
| 100 |
| 101 assertEquals("undefined:true", test6(6), "test6"); |
| 102 assertEquals(0, x, "test6"); // Global x is undisturbed. |
| 103 |
| 104 |
| 105 // Delete on a property found on 'with' object. |
| 106 function test7(object) { |
| 107 with (object) { return delete value; } |
| 108 } |
| 109 |
| 110 var o = {value: 7}; |
| 111 assertEquals(true, test7(o), "test7"); |
| 112 assertEquals(void 0, o.value, "test7"); |
| 113 assertEquals(0, x, "test7"); // Global x is undisturbed. |
| 114 |
| 115 |
| 116 // Delete on a global property. |
| 117 function test8() { |
| 118 with ({}) { return delete x; } |
| 119 } |
| 120 |
| 121 assertEquals(true, test8(), "test8"); |
| 122 assertThrows("x", "test8"); // Global x should be deleted. |
| 123 |
| 124 |
| 125 // Delete on a property that is not found anywhere. |
| 126 function test9() { |
| 127 with ({}) { return delete x; } |
| 128 } |
| 129 |
| 130 assertThrows("x", "test9"); // Make sure it's not there. |
| 131 assertEquals(true, test9(), "test9"); |
| 132 |
| 133 |
| 134 // Delete on a DONT_DELETE property of the global object. |
| 135 var y = 10; |
| 136 function test10() { |
| 137 with ({}) { return delete y; } |
| 138 } |
| 139 |
| 140 assertEquals(false, test10(), "test10"); |
| 141 assertEquals(10, y, "test10"); |
OLD | NEW |