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

Side by Side Diff: test/mjsunit/object-prevent-extensions.js

Issue 776143005: Optimize Object.seal and Object.preventExtensions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add nonextensible and sealed as special transitions Created 6 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
« no previous file with comments | « test/mjsunit/object-freeze-global.js ('k') | test/mjsunit/object-seal.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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
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.preventExtensions method - ES 15.2.3.10 28 // Tests the Object.preventExtensions method - ES 15.2.3.10
29 29
30 // Flags: --allow-natives-syntax
31
30 32
31 var obj1 = {}; 33 var obj1 = {};
32 // Extensible defaults to true. 34 // Extensible defaults to true.
33 assertTrue(Object.isExtensible(obj1)); 35 assertTrue(Object.isExtensible(obj1));
34 Object.preventExtensions(obj1); 36 Object.preventExtensions(obj1);
35 37
36 // Make sure the is_extensible flag is set. 38 // Make sure the is_extensible flag is set.
37 assertFalse(Object.isExtensible(obj1)); 39 assertFalse(Object.isExtensible(obj1));
38 obj1.x = 42; 40 obj1.x = 42;
39 assertEquals(undefined, obj1.x); 41 assertEquals(undefined, obj1.x);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // assignment should return right hand side value 121 // assignment should return right hand side value
120 var o = Object.preventExtensions({}); 122 var o = Object.preventExtensions({});
121 var v = o.v = 50; 123 var v = o.v = 50;
122 assertEquals(undefined, o.v); 124 assertEquals(undefined, o.v);
123 assertEquals(50, v); 125 assertEquals(50, v);
124 126
125 // test same behavior as above, but for integer properties 127 // test same behavior as above, but for integer properties
126 var n = o[0] = 100; 128 var n = o[0] = 100;
127 assertEquals(undefined, o[0]); 129 assertEquals(undefined, o[0]);
128 assertEquals(100, n); 130 assertEquals(100, n);
131
132 // Fast properties should remain fast
133 obj = { x: 42, y: 'foo' };
134 assertTrue(%HasFastProperties(obj));
135 Object.preventExtensions(obj);
136 assertFalse(Object.isExtensible(obj));
137 assertFalse(Object.isSealed(obj));
138 assertTrue(%HasFastProperties(obj));
139
140 // Non-extensible objects should share maps where possible
141 obj = { prop1: 1, prop2: 2 };
142 obj2 = { prop1: 3, prop2: 4 };
143 assertTrue(%HaveSameMap(obj, obj2));
144 Object.preventExtensions(obj);
145 Object.preventExtensions(obj2);
146 assertFalse(Object.isExtensible(obj));
147 assertFalse(Object.isExtensible(obj2));
148 assertFalse(Object.isSealed(obj));
149 assertFalse(Object.isSealed(obj2));
150 assertTrue(%HaveSameMap(obj, obj2));
151
152 // Non-extensible objects should share maps even when they have elements
153 obj = { prop1: 1, prop2: 2, 75: 'foo' };
154 obj2 = { prop1: 3, prop2: 4, 150: 'bar' };
155 assertTrue(%HaveSameMap(obj, obj2));
156 Object.preventExtensions(obj);
157 Object.preventExtensions(obj2);
158 assertFalse(Object.isExtensible(obj));
159 assertFalse(Object.isExtensible(obj2));
160 assertFalse(Object.isSealed(obj));
161 assertFalse(Object.isSealed(obj2));
162 assertTrue(%HaveSameMap(obj, obj2));
OLDNEW
« no previous file with comments | « test/mjsunit/object-freeze-global.js ('k') | test/mjsunit/object-seal.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698