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
32x = 0;
33
34// Delete on a slot from a function's own context.
35function test1() {
36  var value = 1;
37  var status;
38  with ({}) { status = delete value; }
39  return value + ":" + status;
40}
41
42assertEquals("1:false", test1(), "test1");
43assertEquals(0, x, "test1");  // Global x is undisturbed.
44
45
46// Delete on a slot from an outer context.
47function test2() {
48  function f() {
49    with ({}) { return delete value; }
50  }
51  var value = 2;
52  var status = f();
53  return value + ":" + status;
54}
55
56assertEquals("2:false", test2(), "test2");
57assertEquals(0, x, "test2");  // Global x is undisturbed.
58
59
60// Delete on a parameter.
61function test3(value) {
62  var status;
63  with ({}) { status = delete value; }
64  return value + ":" + status;
65}
66
67assertEquals("3:false", test3(3), "test3");
68assertEquals(0, x, "test3");  // Global x is undisturbed.
69
70
71// Delete on a parameter found in an outer context.
72function test4(value) {
73  function f() {
74    with ({}) { return delete value; }
75  }
76  var status = f();
77  return value + ":" + status;
78}
79
80assertEquals("4:false", test4(4), "test4");
81assertEquals(0, x, "test4");  // Global x is undisturbed.
82
83
84// Delete on a parameter, arguments object should be unaffected.
85function test5(value) {
86  var status;
87  with ({}) { status = delete value; }
88  return arguments[0] + ":" + status;
89}
90
91assertEquals("5:false", test5(5), "test5");
92assertEquals(0, x, "test5");  // Global x is undisturbed.
93
94function test6(value) {
95  function f() {
96    with ({}) { return delete value; }
97  }
98  var status = f();
99  return arguments[0] + ":" + status;
100}
101
102assertEquals("6:false", test6(6), "test6");
103assertEquals(0, x, "test6");  // Global x is undisturbed.
104
105
106// Delete on a property found on 'with' object.
107function test7(object) {
108  with (object) { return delete value; }
109}
110
111var o = {value: 7};
112assertEquals(true, test7(o), "test7");
113assertEquals(void 0, o.value, "test7");
114assertEquals(0, x, "test7");  // Global x is undisturbed.
115
116
117// Delete on a global property.
118function test8() {
119  with ({}) { return delete x; }
120}
121
122assertEquals(true, test8(), "test8");
123assertThrows("x", "test8");  // Global x should be deleted.
124
125
126// Delete on a property that is not found anywhere.
127function test9() {
128  with ({}) { return delete x; }
129}
130
131assertThrows("x", "test9");  // Make sure it's not there.
132assertEquals(true, test9(), "test9");
133
134
135// Delete on a DONT_DELETE property of the global object.
136var y = 10;
137function test10() {
138  with ({}) { return delete y; }
139}
140
141assertEquals(false, test10(), "test10");
142assertEquals(10, y, "test10");
143