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

Side by Side Diff: test/mjsunit/object-seal.js

Issue 80623002: Array builtins proceed blithely on frozen arrays (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: a.unshift() needed special care. Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/object-freeze.js ('k') | test/mjsunit/regress/regress-2711.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 10 matching lines...) Expand all
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 // Tests the Object.seal and Object.isSealed methods - ES 15.2.3.9 and 28 // Tests the Object.seal and Object.isSealed methods - ES 15.2.3.9 and
29 // ES 15.2.3.12 29 // ES 15.2.3.12
30 30
31 // Flags: --allow-natives-syntax --noalways-opt
31 32
32 // Test that we throw an error if an object is not passed as argument. 33 // Test that we throw an error if an object is not passed as argument.
33 var non_objects = new Array(undefined, null, 1, -1, 0, 42.43); 34 var non_objects = new Array(undefined, null, 1, -1, 0, 42.43);
34 for (var key in non_objects) { 35 for (var key in non_objects) {
35 var exception = false; 36 var exception = false;
36 try { 37 try {
37 Object.seal(non_objects[key]); 38 Object.seal(non_objects[key]);
38 } catch(e) { 39 } catch(e) {
39 exception = true; 40 exception = true;
40 assertTrue(/Object.seal called on non-object/.test(e)); 41 assertTrue(/Object.seal called on non-object/.test(e));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 var obj4 = {}; 186 var obj4 = {};
186 Object.defineProperty(obj4, 'x', {configurable: true, writable: false}); 187 Object.defineProperty(obj4, 'x', {configurable: true, writable: false});
187 Object.defineProperty(obj4, 'y', {configurable: false, writable: false}); 188 Object.defineProperty(obj4, 'y', {configurable: false, writable: false});
188 Object.preventExtensions(obj4); 189 Object.preventExtensions(obj4);
189 190
190 assertFalse(Object.isSealed(obj4)); 191 assertFalse(Object.isSealed(obj4));
191 192
192 // Make sure that Object.seal returns the sealed object. 193 // Make sure that Object.seal returns the sealed object.
193 var obj4 = {}; 194 var obj4 = {};
194 assertTrue(obj4 === Object.seal(obj4)); 195 assertTrue(obj4 === Object.seal(obj4));
196
197 //
198 // Test that built-in array functions can't modify a sealed array.
199 //
200 obj = [1, 2, 3];
201 var objControl = [4, 5, 6];
202
203 // Allow these functions to set up monomorphic calls, using custom built-ins.
204 var push_call = function(a) { a.push(10); return a; }
205 var pop_call = function(a) { return a.pop(); }
206 for (var i = 0; i < 3; i++) {
207 push_call(obj);
208 pop_call(obj);
209 }
210
211 Object.seal(obj);
212 assertThrows(function() { push_call(obj); }, TypeError);
213 assertThrows(function() { pop_call(obj); }, TypeError);
214
215 // But the control object is fine at these sites.
216 assertDoesNotThrow(function() { push_call(objControl); });
217 assertDoesNotThrow(function() { pop_call(objControl); });
218
219 assertDoesNotThrow(function() { obj.push(); });
220 assertThrows(function() { obj.push(3); }, TypeError);
221 assertThrows(function() { obj.pop(); }, TypeError);
222 assertThrows(function() { obj.shift(3); }, TypeError);
223 assertDoesNotThrow(function() { obj.unshift(); });
224 assertThrows(function() { obj.unshift(1); }, TypeError);
225 assertThrows(function() { obj.splice(0, 0, 100, 101, 102); }, TypeError);
226 assertDoesNotThrow(function() { obj.splice(0,0); });
227
228 assertDoesNotThrow(function() { objControl.push(3); });
229 assertDoesNotThrow(function() { objControl.pop(); });
230 assertDoesNotThrow(function() { objControl.shift(3); });
231 assertDoesNotThrow(function() { objControl.unshift(); });
232 assertDoesNotThrow(function() { objControl.splice(0, 0, 100, 101, 102); });
233
234 // Verify that crankshaft still does the right thing.
235 obj = [1, 2, 3];
236
237 push_call = function(a) { a.push(1000); return a; }
238 // Include a call site that doesn't have a custom built-in.
239 var shift_call = function(a) { a.shift(1000); return a; }
240 for (var i = 0; i < 3; i++) {
241 push_call(obj);
242 shift_call(obj);
243 }
244
245 %OptimizeFunctionOnNextCall(push_call);
246 %OptimizeFunctionOnNextCall(shift_call);
247 push_call(obj);
248 shift_call(obj);
249 assertOptimized(push_call);
250 assertOptimized(shift_call);
251 Object.seal(obj);
252 assertThrows(function() { push_call(obj); }, TypeError);
253 assertThrows(function() { shift_call(obj); }, TypeError);
254 assertOptimized(push_call);
255 // shift() doesn't have a custom call generator, so deopt will occur.
256 assertUnoptimized(shift_call);
257 assertDoesNotThrow(function() { push_call(objControl); });
258 assertDoesNotThrow(function() { shift_call(objControl); });
259
260 // Verify special behavior of splice on sealed objects.
261 obj = [1,2,3];
262 Object.seal(obj);
263 assertDoesNotThrow(function() { obj.splice(0,1,100); });
264 assertEquals(100, obj[0]);
265 assertDoesNotThrow(function() { obj.splice(0,2,1,2); });
266 assertDoesNotThrow(function() { obj.splice(1,2,1,2); });
267 // Count of items to delete is clamped by length.
268 assertDoesNotThrow(function() { obj.splice(1,2000,1,2); });
269 assertThrows(function() { obj.splice(0,0,1); }, TypeError);
270 assertThrows(function() { obj.splice(1,2000,1,2,3); }, TypeError);
OLDNEW
« no previous file with comments | « test/mjsunit/object-freeze.js ('k') | test/mjsunit/regress/regress-2711.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698