Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: test/mjsunit/strong/object-delete.js

Issue 1156573002: [strong] Implement per-object restrictions behaviour of delete operator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: move redundant delete Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/elements.cc ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --strong-mode --allow-natives-syntax
6
7 // TODO(conradw): Track implementation of strong bit for other objects, add
8 // tests.
9
10 function getSloppyObjects() {
11 return [(function(){}), ({})];
12 }
13
14 function getStrictObjects() {
15 "use strict";
16 return [(function(){}), ({})];
17 }
18
19 function getWeakObjects() {
20 return getSloppyObjects().concat(getStrictObjects());
21 }
22
23 function getStrongObjects() {
24 "use strong";
25 // Strong functions can't have properties added to them, and will be tested as a
26 // special case.
27 return [({})];
28 }
29
30 function strongFunction() {
31 "use strong";
32 }
33
34 function deleteFromObjectSloppy(o) {
35 return delete o.foo;
36 }
37
38 function deleteFromObjectKeyedSloppy(o) {
39 return delete o["foo"];
40 }
41
42 function deleteFromObjectKeyedVarSloppy(o) {
43 var a = "foo";
44 return delete o[a];
45 }
46
47 function deleteFromObjectKeyedComputedSloppy(o) {
48 var a = "o";
49 return delete o["fo" + a];
50 }
51
52 function deleteFromObjectWith(o) {
53 with(o) {
arv (Not doing code reviews) 2015/05/28 15:46:17 with (
conradw 2015/05/28 16:36:44 Done.
54 return delete foo;
55 }
56 }
57
58 function deleteFromObjectElementSloppy(o) {
59 return delete o[0];
60 }
61
62 function deleteFromObjectElementVarSloppy(o) {
63 var a = 0;
64 return delete o[a];
65 }
66
67 function deleteFromObjectElementSparseSloppy(o) {
68 return delete o[100000];
69 }
70
71 function deleteFromObjectElementVarSloppy(o) {
72 var a = 0;
73 return delete o[a];
74 }
75
76 function deleteFromObjectElementSparseVarSloppy(o) {
77 var a = 100000;
78 return delete o[a];
79 }
80
81 function deleteFromObjectStrict(o) {
82 "use strict";
83 return delete o.foo;
84 }
85
86 function deleteFromObjectKeyedStrict(o) {
87 "use strict";
88 return delete o["foo"];
89 }
90
91 function deleteFromObjectKeyedVarStrict(o) {
92 "use strict";
93 var a = "foo";
94 return delete o[a];
95 }
96
97 function deleteFromObjectKeyedComputedStrict(o) {
98 "use strict";
99 var a = "o";
100 return delete o["fo" + a];
101 }
102
103 function deleteFromObjectElementStrict(o) {
104 "use strict";
105 return delete o[0];
106 }
107
108 function deleteFromObjectElementSparseStrict(o) {
109 "use strict";
110 return delete o[100000];
111 }
112
113 function deleteFromObjectElementVarStrict(o) {
114 "use strict";
115 var a = 0;
116 return delete o[a];
117 }
118
119 function deleteFromObjectElementSparseVarStrict(o) {
120 "use strict";
121 var a = 100000;
122 return delete o[a];
123 }
124
125 function testStrongObjectDelete() {
126 "use strict";
127
128 let deletePropertyFuncsSloppy = [deleteFromObjectSloppy,
arv (Not doing code reviews) 2015/05/28 15:46:17 let deletePropertyFuncsSloppy = [ deleteFromObje
conradw 2015/05/28 16:36:44 Done.
129 deleteFromObjectKeyedSloppy,
130 deleteFromObjectKeyedVarSloppy,
131 deleteFromObjectKeyedComputedSloppy,
132 deleteFromObjectWith,
133 ];
134 let deletePropertyFuncsStrict = [deleteFromObjectStrict,
135 deleteFromObjectKeyedStrict,
136 deleteFromObjectKeyedVarStrict,
137 deleteFromObjectKeyedComputedStrict,
138 ];
139 let deleteElementFuncsSloppy = [deleteFromObjectElementSloppy,
140 deleteFromObjectElementVarSloppy
141 ];
142 let deleteElementSparseFuncsSloppy = [deleteFromObjectElementSparseSloppy,
143 deleteFromObjectElementSparseVarSloppy
144 ];
145 let deleteElementFuncsStrict = [deleteFromObjectElementStrict,
146 deleteFromObjectElementVarStrict
147 ];
148 let deleteElementSparseFuncsStrict = [deleteFromObjectElementSparseStrict,
149 deleteFromObjectElementSparseVarStrict
150 ];
151 let deleteFuncs = deletePropertyFuncsSloppy.concat(
152 deletePropertyFuncsStrict, deleteElementFuncsSloppy,
153 deleteElementSparseFuncsSloppy, deleteElementFuncsStrict,
154 deleteElementSparseFuncsStrict);
155
156 for (let deleteFunc of deleteFuncs) {
157 assertTrue(deleteFunc(strongFunction));
158 }
159
160 let testCasesSloppy = [[deletePropertyFuncsSloppy, "foo"],
161 [deleteElementFuncsSloppy, "0"],
162 [deleteElementSparseFuncsSloppy, "100000"]
163 ];
164
165 let testCasesStrict = [[deletePropertyFuncsStrict, "foo"],
166 [deleteElementFuncsStrict, "0"],
167 [deleteElementSparseFuncsStrict, "100000"]
168 ];
169
170 let propDescs =
171 [{configurable:true, value:"bar"},
arv (Not doing code reviews) 2015/05/28 15:46:17 {configurable: true, value: "bar"},
conradw 2015/05/28 16:36:44 Done.
172 {configurable:true, value:1},
173 {configurable:true, enumerable:true, writable:true, value:"bar"},
174 {configurable:true, enumerable:true, writable:true, value:1},
175 {configurable:true, get:(function(){return 0}), set:(function(x){})}
176 ];
177
178 for (let propDesc of propDescs) {
179 for (let testCase of testCasesSloppy) {
180 let name = testCase[1];
181 for (let deleteFunc of testCase[0]) {
182 for (let o of getWeakObjects()) {
183 Object.defineProperty(o, name, propDesc);
184 assertTrue(delete o["bar"]);
185 assertTrue(deleteFunc(o));
186 assertFalse(o.hasOwnProperty(name));
187 %OptimizeFunctionOnNextCall(deleteFunc);
188 Object.defineProperty(o, name, propDesc);
189 assertTrue(deleteFunc(o));
190 assertFalse(o.hasOwnProperty(name));
191 %DeoptimizeFunction(deleteFunc);
192 Object.defineProperty(o, name, propDesc);
193 assertTrue(deleteFunc(o));
194 assertFalse(o.hasOwnProperty(name));
195 }
196 for (let o of getStrongObjects()) {
197 Object.defineProperty(o, name, propDesc);
198 assertTrue(delete o["bar"]);
199 assertFalse(deleteFunc(o));
200 assertTrue(o.hasOwnProperty(name));
201 %OptimizeFunctionOnNextCall(deleteFunc);
202 assertFalse(deleteFunc(o));
203 assertTrue(o.hasOwnProperty(name));
204 %DeoptimizeFunction(deleteFunc);
205 assertFalse(deleteFunc(o));
206 assertTrue(o.hasOwnProperty(name));
207 }
208 }
209 }
210 for (let testCase of testCasesStrict) {
211 let name = testCase[1];
212 for (let deleteFunc of testCase[0]) {
213 for (let o of getWeakObjects()) {
214 Object.defineProperty(o, name, propDesc);
215 assertTrue(delete o["bar"]);
216 assertTrue(deleteFunc(o));
217 assertFalse(o.hasOwnProperty(name));
218 %OptimizeFunctionOnNextCall(deleteFunc);
219 Object.defineProperty(o, name, propDesc);
220 assertTrue(deleteFunc(o));
221 assertFalse(o.hasOwnProperty(name));
222 %DeoptimizeFunction(deleteFunc);
223 Object.defineProperty(o, name, propDesc);
224 assertTrue(deleteFunc(o));
225 assertFalse(o.hasOwnProperty(name));
226 }
227 for (let o of getStrongObjects()) {
228 Object.defineProperty(o, name, propDesc);
229 assertTrue(delete o["bar"]);
230 assertThrows(function(){deleteFunc(o)}, TypeError);
231 assertTrue(o.hasOwnProperty(name));
232 %OptimizeFunctionOnNextCall(deleteFunc);
233 assertThrows(function(){deleteFunc(o)}, TypeError);
234 assertTrue(o.hasOwnProperty(name));
235 %DeoptimizeFunction(deleteFunc);
236 assertThrows(function(){deleteFunc(o)}, TypeError);
237 assertTrue(o.hasOwnProperty(name));
238 }
239 }
240 }
241 }
242 }
243 testStrongObjectDelete();
OLDNEW
« src/elements.cc ('K') | « test/cctest/test-api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698