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 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 var value = 2; | 51 var value = 2; |
52 var status = f(); | 52 var status = f(); |
53 return value + ":" + status; | 53 return value + ":" + status; |
54 } | 54 } |
55 | 55 |
56 assertEquals("2:false", test2(), "test2"); | 56 assertEquals("2:false", test2(), "test2"); |
57 assertEquals(0, x, "test2"); // Global x is undisturbed. | 57 assertEquals(0, x, "test2"); // Global x is undisturbed. |
58 | 58 |
59 | 59 |
60 // Delete on a parameter. | 60 // Delete on an argument. This hits the same code paths as test5 because |
| 61 // 'with' forces all parameters to be indirected through the arguments |
| 62 // object. |
61 function test3(value) { | 63 function test3(value) { |
62 var status; | 64 var status; |
63 with ({}) { status = delete value; } | 65 with ({}) { status = delete value; } |
64 return value + ":" + status; | 66 return value + ":" + status; |
65 } | 67 } |
66 | 68 |
67 assertEquals("3:false", test3(3), "test3"); | 69 assertEquals("undefined:true", test3(3), "test3"); |
68 assertEquals(0, x, "test3"); // Global x is undisturbed. | 70 assertEquals(0, x, "test3"); // Global x is undisturbed. |
69 | 71 |
70 | 72 |
71 // Delete on a parameter found in an outer context. | 73 // Delete on an argument from an outer context. This hits the same code |
| 74 // path as test2. |
72 function test4(value) { | 75 function test4(value) { |
73 function f() { | 76 function f() { |
74 with ({}) { return delete value; } | 77 with ({}) { return delete value; } |
75 } | 78 } |
76 var status = f(); | 79 var status = f(); |
77 return value + ":" + status; | 80 return value + ":" + status; |
78 } | 81 } |
79 | 82 |
80 assertEquals("4:false", test4(4), "test4"); | 83 assertEquals("4:false", test4(4), "test4"); |
81 assertEquals(0, x, "test4"); // Global x is undisturbed. | 84 assertEquals(0, x, "test4"); // Global x is undisturbed. |
82 | 85 |
83 | 86 |
84 // Delete on a parameter, arguments object should be unaffected. | 87 // Delete on an argument found in the arguments object. Such properties are |
| 88 // normally DONT_DELETE in JavaScript but deletion is allowed by V8. |
85 function test5(value) { | 89 function test5(value) { |
86 var status; | 90 var status; |
87 with ({}) { status = delete value; } | 91 with ({}) { status = delete value; } |
88 return arguments[0] + ":" + status; | 92 return arguments[0] + ":" + status; |
89 } | 93 } |
90 | 94 |
91 assertEquals("5:false", test5(5), "test5"); | 95 assertEquals("undefined:true", test5(5), "test5"); |
92 assertEquals(0, x, "test5"); // Global x is undisturbed. | 96 assertEquals(0, x, "test5"); // Global x is undisturbed. |
93 | 97 |
94 function test6(value) { | 98 function test6(value) { |
95 function f() { | 99 function f() { |
96 with ({}) { return delete value; } | 100 with ({}) { return delete value; } |
97 } | 101 } |
98 var status = f(); | 102 var status = f(); |
99 return arguments[0] + ":" + status; | 103 return arguments[0] + ":" + status; |
100 } | 104 } |
101 | 105 |
102 assertEquals("6:false", test6(6), "test6"); | 106 assertEquals("undefined:true", test6(6), "test6"); |
103 assertEquals(0, x, "test6"); // Global x is undisturbed. | 107 assertEquals(0, x, "test6"); // Global x is undisturbed. |
104 | 108 |
105 | 109 |
106 // Delete on a property found on 'with' object. | 110 // Delete on a property found on 'with' object. |
107 function test7(object) { | 111 function test7(object) { |
108 with (object) { return delete value; } | 112 with (object) { return delete value; } |
109 } | 113 } |
110 | 114 |
111 var o = {value: 7}; | 115 var o = {value: 7}; |
112 assertEquals(true, test7(o), "test7"); | 116 assertEquals(true, test7(o), "test7"); |
(...skipping 20 matching lines...) Expand all Loading... |
133 | 137 |
134 | 138 |
135 // Delete on a DONT_DELETE property of the global object. | 139 // Delete on a DONT_DELETE property of the global object. |
136 var y = 10; | 140 var y = 10; |
137 function test10() { | 141 function test10() { |
138 with ({}) { return delete y; } | 142 with ({}) { return delete y; } |
139 } | 143 } |
140 | 144 |
141 assertEquals(false, test10(), "test10"); | 145 assertEquals(false, test10(), "test10"); |
142 assertEquals(10, y, "test10"); | 146 assertEquals(10, y, "test10"); |
OLD | NEW |