OLD | NEW |
---|---|
(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 | |
rossberg
2015/06/10 08:28:08
Currently, the semantics does not rely on that, do
conradw
2015/06/10 12:03:23
Err, this was just a mindless copy and paste mista
| |
8 // tests. | |
9 | |
10 function getObjects() { | |
rossberg
2015/06/10 08:28:08
Other interesting cases to add:
- arguments (both
conradw
2015/06/10 12:03:23
Done, the plan right now is to do proxies in a fol
rossberg
2015/06/11 09:36:34
Can you also add
- a typed array instance
- Objec
conradw
2015/06/11 13:48:31
Done, strings are handled in the "literals" list o
| |
11 "use strict"; | |
12 return [ | |
13 {}, | |
14 [], | |
15 (function(){}), | |
16 (class Foo {}) | |
17 ]; | |
18 } | |
19 | |
20 function readFromObjectElementSloppy(o) { | |
21 return o[0]; | |
22 } | |
23 | |
24 function readFromObjectElementSparseSloppy(o) { | |
25 return o[100000]; | |
26 } | |
27 | |
28 function readFromObjectElementNonSmiSloppy(o) { | |
29 return o[3000000000]; | |
30 } | |
31 | |
32 function readFromObjectNonIndexSloppy(o) { | |
33 return o[5000000000]; | |
34 } | |
35 | |
36 function readFromObjectElementVarSloppy(o) { | |
37 var a = 0; | |
38 return o[a]; | |
39 } | |
40 | |
41 function readFromObjectElementSparseVarSloppy(o) { | |
42 var a = 100000; | |
43 return o[a]; | |
44 } | |
45 | |
46 function readFromObjectElementNonSmiVarSloppy(o) { | |
47 var a = 3000000000; | |
48 return o[a]; | |
49 } | |
50 | |
51 function readFromObjectNonIndexVarSloppy(o) { | |
52 var a = 5000000000; | |
53 return o[a]; | |
54 } | |
55 | |
56 function readFromObjectElementStrong(o) { | |
57 "use strong"; | |
58 return o[0]; | |
59 } | |
60 | |
61 function readFromObjectElementSparseStrong(o) { | |
62 "use strong"; | |
63 return o[100000]; | |
64 } | |
65 | |
66 function readFromObjectElementNonSmiStrong(o) { | |
67 "use strong"; | |
68 return o[3000000000]; | |
69 } | |
70 | |
71 function readFromObjectNonIndexStrong(o) { | |
72 "use strong"; | |
73 return o[5000000000]; | |
74 } | |
75 | |
76 function readFromObjectElementLetStrong(o) { | |
77 "use strong"; | |
78 let a = 0; | |
79 return o[a]; | |
80 } | |
81 | |
82 function readFromObjectElementSparseLetStrong(o) { | |
83 "use strong"; | |
84 let a = 100000; | |
85 return o[a]; | |
86 } | |
87 | |
88 function readFromObjectElementNonSmiLetStrong(o) { | |
89 "use strong"; | |
90 let a = 3000000000; | |
91 return o[a]; | |
92 } | |
93 | |
94 function readFromObjectNonIndexLetStrong(o) { | |
95 "use strong"; | |
96 let a = 5000000000; | |
97 return o[a]; | |
98 } | |
99 | |
100 function getDescs(x) { | |
101 return [ | |
102 {value: x}, | |
103 {configurable: true, value: x}, | |
104 {configurable: true, enumerable: true, writable: true, value: x}, | |
105 {configurable: true, enumerable: true, get: (function() {return x}) }, | |
106 ]; | |
107 } | |
108 | |
109 function assertStrongSemantics(func, object) { | |
110 %DeoptimizeFunction(func); | |
111 %ClearFunctionTypeFeedback(func); | |
112 assertThrows(function(){func(object)}, TypeError); | |
113 assertThrows(function(){func(object)}, TypeError); | |
114 assertThrows(function(){func(object)}, TypeError); | |
115 %OptimizeFunctionOnNextCall(func); | |
116 assertThrows(function(){func(object)}, TypeError); | |
117 %DeoptimizeFunction(func); | |
118 assertThrows(function(){func(object)}, TypeError); | |
119 } | |
120 | |
121 function assertSloppySemantics(func, object) { | |
122 %DeoptimizeFunction(func); | |
123 %ClearFunctionTypeFeedback(func); | |
124 assertDoesNotThrow(function(){func(object)}); | |
125 assertDoesNotThrow(function(){func(object)}); | |
126 assertDoesNotThrow(function(){func(object)}); | |
127 %OptimizeFunctionOnNextCall(func); | |
128 assertDoesNotThrow(function(){func(object)}); | |
129 %DeoptimizeFunction(func); | |
130 assertDoesNotThrow(function(){func(object)}); | |
131 } | |
132 | |
133 (function () { | |
134 "use strict"; | |
135 | |
136 let goodKeys = [ | |
137 "0", | |
138 "100000", | |
139 "3000000000", | |
140 "5000000000" | |
141 ] | |
142 | |
143 let badKeys = [ | |
144 "bar", | |
145 "1", | |
146 "100001", | |
147 "3000000001", | |
148 "5000000001" | |
149 ]; | |
150 | |
151 let values = [ | |
152 "string", | |
153 1, | |
154 100001, | |
155 30000000001, | |
156 50000000001, | |
157 NaN, | |
158 {}, | |
159 undefined | |
160 ]; | |
161 | |
162 let badAccessorDescs = [ | |
163 { set: (function(){}) }, | |
164 { configurable: true, set: (function(){}) }, | |
165 { configurable: true, enumerable: true, set: (function(){}) } | |
166 ]; | |
167 | |
168 let readSloppy = [ | |
169 readFromObjectElementSloppy, | |
170 readFromObjectElementSparseSloppy, | |
171 readFromObjectElementNonSmiSloppy, | |
172 readFromObjectNonIndexSloppy, | |
173 readFromObjectElementVarSloppy, | |
174 readFromObjectElementSparseVarSloppy, | |
175 readFromObjectElementNonSmiVarSloppy, | |
176 readFromObjectNonIndexVarSloppy | |
177 ]; | |
178 | |
179 let readStrong = [ | |
180 readFromObjectElementStrong, | |
181 readFromObjectElementSparseStrong, | |
182 readFromObjectElementNonSmiStrong, | |
183 readFromObjectNonIndexStrong, | |
184 readFromObjectElementLetStrong, | |
185 readFromObjectElementSparseLetStrong, | |
186 readFromObjectElementNonSmiLetStrong, | |
187 readFromObjectNonIndexLetStrong | |
188 ]; | |
189 | |
190 let dummyProto = {}; | |
191 for (let key of goodKeys) { | |
192 Object.defineProperty(dummyProto, key, { value: undefined }); | |
193 } | |
194 | |
195 let dummyAccessorProto = {}; | |
196 for (let key of goodKeys) { | |
197 Object.defineProperty(dummyAccessorProto, key, { set: (function(){}) }) | |
198 } | |
199 | |
200 // Attempting to access a property on an objects with no defined properties | |
rossberg
2015/06/10 08:28:08
Nit: typo
conradw
2015/06/10 12:03:23
Done.
| |
201 // should throw. | |
202 for (let object of getObjects()) { | |
203 for (let func of readStrong) { | |
204 assertStrongSemantics(func, object); | |
205 } | |
206 for (let func of readSloppy) { | |
207 assertSloppySemantics(func, object); | |
208 } | |
209 // Accessing a property which is on the prototype chain of the object should | |
210 // not throw. | |
211 object.__proto__ = dummyProto; | |
212 for (let key of goodKeys) { | |
213 for (let func of readStrong.concat(readSloppy)) { | |
214 assertSloppySemantics(func, object); | |
215 } | |
216 } | |
217 } | |
218 // Properties with accessor descriptors missing 'get' should throw on access. | |
219 for (let desc of badAccessorDescs) { | |
220 for (let key of goodKeys) { | |
221 for (let object of getObjects()) { | |
222 Object.defineProperty(object, key, desc); | |
223 for (let func of readStrong) { | |
224 assertStrongSemantics(func, object); | |
225 } | |
226 for (let func of readSloppy) { | |
227 assertSloppySemantics(func, object); | |
228 } | |
229 } | |
230 } | |
231 } | |
232 // The same behaviour should be expected for bad accessor properties on the | |
233 // prototype chain. | |
234 for (let object of getObjects()) { | |
235 object.__proto__ = dummyAccessorProto; | |
236 for (let func of readStrong) { | |
237 assertStrongSemantics(func, object); | |
238 } | |
239 for (let func of readSloppy) { | |
240 assertSloppySemantics(func, object); | |
241 } | |
242 } | |
243 })(); | |
OLD | NEW |