OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 #include "cctest.h" | |
29 #include "types.h" | |
30 | |
31 using namespace v8::internal; | |
32 | |
33 // Testing auxiliaries (breaking the Type abstraction). | |
34 static bool IsBitset(Type* type) { return type->IsSmi(); } | |
35 static bool IsClass(Type* type) { return type->IsMap(); } | |
36 static bool IsUnion(Type* type) { return type->IsFixedArray(); } | |
37 static bool IsConstant(Type* type) { | |
38 return !(IsBitset(type) || IsClass(type) || IsUnion(type)); | |
39 } | |
40 | |
41 static int AsBitset(Type* type) { return Smi::cast(type)->value(); } | |
42 static Map* AsClass(Type* type) { return Map::cast(type); } | |
43 static HeapObject* AsConstant(Type* type) { return HeapObject::cast(type); } | |
44 static FixedArray* AsUnion(Type* type) { return FixedArray::cast(type); } | |
45 | |
46 class HandlifiedTypes { | |
47 public: | |
48 explicit HandlifiedTypes(Isolate* isolate) : | |
49 None(Type::None(), isolate), | |
50 Any(Type::Any(), isolate), | |
51 Oddball(Type::Oddball(), isolate), | |
52 Boolean(Type::Boolean(), isolate), | |
53 Null(Type::Null(), isolate), | |
54 Undefined(Type::Undefined(), isolate), | |
55 Number(Type::Number(), isolate), | |
56 Smi(Type::Smi(), isolate), | |
57 Double(Type::Double(), isolate), | |
58 Name(Type::Name(), isolate), | |
59 UniqueName(Type::UniqueName(), isolate), | |
60 String(Type::String(), isolate), | |
61 InternalizedString(Type::InternalizedString(), isolate), | |
62 Symbol(Type::Symbol(), isolate), | |
63 Receiver(Type::Receiver(), isolate), | |
64 Object(Type::Object(), isolate), | |
65 Array(Type::Array(), isolate), | |
66 Function(Type::Function(), isolate), | |
67 Proxy(Type::Proxy(), isolate), | |
68 object_map(isolate->factory()->NewMap(JS_OBJECT_TYPE, 3 * kPointerSize)), | |
69 array_map(isolate->factory()->NewMap(JS_ARRAY_TYPE, 4 * kPointerSize)), | |
70 isolate_(isolate) { | |
71 object1 = isolate->factory()->NewJSObjectFromMap(object_map); | |
72 object2 = isolate->factory()->NewJSObjectFromMap(object_map); | |
73 array = isolate->factory()->NewJSArray(20); | |
74 ObjectClass = handle(Type::Class(object_map), isolate); | |
75 ArrayClass = handle(Type::Class(array_map), isolate); | |
76 ObjectConstant1 = handle(Type::Constant(object1), isolate); | |
77 ObjectConstant2 = handle(Type::Constant(object2), isolate); | |
78 ArrayConstant = handle(Type::Constant(array), isolate); | |
79 } | |
80 | |
81 Handle<Type> None; | |
82 Handle<Type> Any; | |
83 Handle<Type> Oddball; | |
84 Handle<Type> Boolean; | |
85 Handle<Type> Null; | |
86 Handle<Type> Undefined; | |
87 Handle<Type> Number; | |
88 Handle<Type> Smi; | |
89 Handle<Type> Double; | |
90 Handle<Type> Name; | |
91 Handle<Type> UniqueName; | |
92 Handle<Type> String; | |
93 Handle<Type> InternalizedString; | |
94 Handle<Type> Symbol; | |
95 Handle<Type> Receiver; | |
96 Handle<Type> Object; | |
97 Handle<Type> Array; | |
98 Handle<Type> Function; | |
99 Handle<Type> Proxy; | |
100 | |
101 Handle<Type> ObjectClass; | |
102 Handle<Type> ArrayClass; | |
103 Handle<Type> ObjectConstant1; | |
104 Handle<Type> ObjectConstant2; | |
105 Handle<Type> ArrayConstant; | |
106 | |
107 Handle<Map> object_map; | |
108 Handle<Map> array_map; | |
109 | |
110 Handle<JSObject> object1; | |
111 Handle<JSObject> object2; | |
112 Handle<JSArray> array; | |
113 | |
114 Handle<Type> Union(Handle<Type> type1, Handle<Type> type2) { | |
115 return handle(Type::Union(type1, type2), isolate_); | |
116 } | |
117 | |
118 private: | |
119 Isolate* isolate_; | |
120 }; | |
121 | |
122 | |
123 TEST(Bitset) { | |
124 CcTest::InitializeVM(); | |
125 Isolate* isolate = Isolate::Current(); | |
126 HandleScope scope(isolate); | |
127 HandlifiedTypes T(isolate); | |
128 | |
129 CHECK(IsBitset(*T.None)); | |
130 CHECK(IsBitset(*T.Any)); | |
131 CHECK(IsBitset(*T.String)); | |
132 CHECK(IsBitset(*T.Object)); | |
133 | |
134 CHECK(IsBitset(Type::Union(T.String, T.Number))); | |
135 CHECK(IsBitset(Type::Union(T.String, T.Receiver))); | |
136 CHECK(IsBitset(Type::Optional(T.Object))); | |
137 | |
138 CHECK_EQ(0, AsBitset(*T.None)); | |
139 CHECK_EQ(AsBitset(*T.Number) | AsBitset(*T.String), | |
140 AsBitset(Type::Union(T.String, T.Number))); | |
141 CHECK_EQ(AsBitset(*T.Receiver), | |
142 AsBitset(Type::Union(T.Receiver, T.Object))); | |
143 CHECK_EQ(AsBitset(*T.String) | AsBitset(*T.Undefined), | |
144 AsBitset(Type::Optional(T.String))); | |
145 } | |
146 | |
147 | |
148 TEST(Class) { | |
149 CcTest::InitializeVM(); | |
150 Isolate* isolate = Isolate::Current(); | |
151 HandleScope scope(isolate); | |
152 HandlifiedTypes T(isolate); | |
153 | |
154 CHECK(IsClass(*T.ObjectClass)); | |
155 CHECK(IsClass(*T.ArrayClass)); | |
156 | |
157 CHECK(*T.object_map == AsClass(*T.ObjectClass)); | |
158 CHECK(*T.array_map == AsClass(*T.ArrayClass)); | |
159 } | |
160 | |
161 | |
162 TEST(Constant) { | |
163 CcTest::InitializeVM(); | |
164 Isolate* isolate = Isolate::Current(); | |
165 HandleScope scope(isolate); | |
166 HandlifiedTypes T(isolate); | |
167 | |
168 CHECK(IsConstant(*T.ObjectConstant1)); | |
169 CHECK(IsConstant(*T.ObjectConstant2)); | |
170 CHECK(IsConstant(*T.ArrayConstant)); | |
171 | |
172 CHECK(*T.object1 == AsConstant(*T.ObjectConstant1)); | |
173 CHECK(*T.object2 == AsConstant(*T.ObjectConstant2)); | |
174 CHECK(*T.object1 != AsConstant(*T.ObjectConstant2)); | |
175 CHECK(*T.array == AsConstant(*T.ArrayConstant)); | |
176 } | |
177 | |
178 | |
179 static void CheckSub(Handle<Type> type1, Handle<Type> type2) { | |
180 CHECK(type1->Is(type2)); | |
181 CHECK(!type2->Is(type1)); | |
182 if (IsBitset(*type1) && IsBitset(*type2)) | |
183 CHECK_NE(AsBitset(*type1), AsBitset(*type2)); | |
Jakob Kummerow
2013/06/05 14:53:24
nit: {}
rossberg
2013/06/05 15:37:02
Done.
| |
184 } | |
185 | |
186 static void CheckUnordered(Handle<Type> type1, Handle<Type> type2) { | |
187 CHECK(!type1->Is(type2)); | |
188 CHECK(!type2->Is(type1)); | |
189 if (IsBitset(*type1) && IsBitset(*type2)) | |
190 CHECK_NE(AsBitset(*type1), AsBitset(*type2)); | |
Jakob Kummerow
2013/06/05 14:53:24
nit: {}
rossberg
2013/06/05 15:37:02
Done.
| |
191 } | |
192 | |
193 TEST(Is) { | |
194 CcTest::InitializeVM(); | |
195 Isolate* isolate = Isolate::Current(); | |
196 HandleScope scope(isolate); | |
197 HandlifiedTypes T(isolate); | |
198 | |
199 // Reflexivity | |
200 CHECK(T.None->Is(T.None)); | |
201 CHECK(T.Any->Is(T.Any)); | |
202 CHECK(T.Object->Is(T.Object)); | |
203 | |
204 CHECK(T.ObjectClass->Is(T.ObjectClass)); | |
205 CHECK(T.ObjectConstant1->Is(T.ObjectConstant1)); | |
206 | |
207 // Symmetry and Transitivity | |
208 CheckSub(T.None, T.Number); | |
209 CheckSub(T.None, T.Any); | |
210 | |
211 CheckSub(T.Oddball, T.Any); | |
212 CheckSub(T.Boolean, T.Oddball); | |
213 CheckSub(T.Null, T.Oddball); | |
214 CheckSub(T.Undefined, T.Oddball); | |
215 CheckUnordered(T.Boolean, T.Null); | |
216 CheckUnordered(T.Undefined, T.Null); | |
217 CheckUnordered(T.Boolean, T.Undefined); | |
218 | |
219 CheckSub(T.Number, T.Any); | |
220 CheckSub(T.Smi, T.Number); | |
221 CheckSub(T.Double, T.Number); | |
222 CheckUnordered(T.Smi, T.Double); | |
223 | |
224 CheckSub(T.Name, T.Any); | |
225 CheckSub(T.UniqueName, T.Any); | |
226 CheckSub(T.UniqueName, T.Name); | |
227 CheckSub(T.String, T.Name); | |
228 CheckSub(T.InternalizedString, T.String); | |
229 CheckSub(T.InternalizedString, T.UniqueName); | |
230 CheckSub(T.InternalizedString, T.Name); | |
231 CheckSub(T.Symbol, T.UniqueName); | |
232 CheckSub(T.Symbol, T.Name); | |
233 CheckUnordered(T.String, T.UniqueName); | |
234 CheckUnordered(T.String, T.Symbol); | |
235 CheckUnordered(T.InternalizedString, T.Symbol); | |
236 | |
237 CheckSub(T.Receiver, T.Any); | |
238 CheckSub(T.Object, T.Any); | |
239 CheckSub(T.Object, T.Receiver); | |
240 CheckSub(T.Array, T.Object); | |
241 CheckSub(T.Function, T.Object); | |
242 CheckSub(T.Proxy, T.Receiver); | |
243 CheckUnordered(T.Object, T.Proxy); | |
244 CheckUnordered(T.Array, T.Function); | |
245 | |
246 // Structured subtyping | |
247 CheckSub(T.ObjectClass, T.Object); | |
248 CheckSub(T.ArrayClass, T.Object); | |
249 CheckUnordered(T.ObjectClass, T.ArrayClass); | |
250 | |
251 CheckSub(T.ObjectConstant1, T.Object); | |
252 CheckSub(T.ObjectConstant2, T.Object); | |
253 CheckSub(T.ArrayConstant, T.Object); | |
254 CheckSub(T.ArrayConstant, T.Array); | |
255 CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); | |
256 CheckUnordered(T.ObjectConstant1, T.ArrayConstant); | |
257 | |
258 CheckUnordered(T.ObjectConstant1, T.ObjectClass); | |
259 CheckUnordered(T.ObjectConstant2, T.ObjectClass); | |
260 CheckUnordered(T.ObjectConstant1, T.ArrayClass); | |
261 CheckUnordered(T.ObjectConstant2, T.ArrayClass); | |
262 CheckUnordered(T.ArrayConstant, T.ObjectClass); | |
263 } | |
264 | |
265 | |
266 static void CheckOverlap(Handle<Type> type1, Handle<Type> type2) { | |
267 CHECK(type1->Maybe(type2)); | |
268 CHECK(type2->Maybe(type1)); | |
269 if (IsBitset(*type1) && IsBitset(*type2)) | |
270 CHECK_NE(0, AsBitset(*type1) & AsBitset(*type2)); | |
Jakob Kummerow
2013/06/05 14:53:24
nit: {}
rossberg
2013/06/05 15:37:02
Done.
| |
271 } | |
272 | |
273 static void CheckDisjoint(Handle<Type> type1, Handle<Type> type2) { | |
274 CHECK(!type1->Is(type2)); | |
275 CHECK(!type2->Is(type1)); | |
276 CHECK(!type1->Maybe(type2)); | |
277 CHECK(!type2->Maybe(type1)); | |
278 if (IsBitset(*type1) && IsBitset(*type2)) | |
279 CHECK_EQ(0, AsBitset(*type1) & AsBitset(*type2)); | |
Jakob Kummerow
2013/06/05 14:53:24
nit: {}
rossberg
2013/06/05 15:37:02
Done.
| |
280 } | |
281 | |
282 TEST(Maybe) { | |
283 CcTest::InitializeVM(); | |
284 Isolate* isolate = Isolate::Current(); | |
285 HandleScope scope(isolate); | |
286 HandlifiedTypes T(isolate); | |
287 | |
288 CheckOverlap(T.Any, T.Any); | |
289 CheckOverlap(T.Object, T.Object); | |
290 | |
291 CheckOverlap(T.Oddball, T.Any); | |
292 CheckOverlap(T.Boolean, T.Oddball); | |
293 CheckOverlap(T.Null, T.Oddball); | |
294 CheckOverlap(T.Undefined, T.Oddball); | |
295 CheckDisjoint(T.Boolean, T.Null); | |
296 CheckDisjoint(T.Undefined, T.Null); | |
297 CheckDisjoint(T.Boolean, T.Undefined); | |
298 | |
299 CheckOverlap(T.Number, T.Any); | |
300 CheckOverlap(T.Smi, T.Number); | |
301 CheckOverlap(T.Double, T.Number); | |
302 CheckDisjoint(T.Smi, T.Double); | |
303 | |
304 CheckOverlap(T.Name, T.Any); | |
305 CheckOverlap(T.UniqueName, T.Any); | |
306 CheckOverlap(T.UniqueName, T.Name); | |
307 CheckOverlap(T.String, T.Name); | |
308 CheckOverlap(T.InternalizedString, T.String); | |
309 CheckOverlap(T.InternalizedString, T.UniqueName); | |
310 CheckOverlap(T.InternalizedString, T.Name); | |
311 CheckOverlap(T.Symbol, T.UniqueName); | |
312 CheckOverlap(T.Symbol, T.Name); | |
313 CheckOverlap(T.String, T.UniqueName); | |
314 CheckDisjoint(T.String, T.Symbol); | |
315 CheckDisjoint(T.InternalizedString, T.Symbol); | |
316 | |
317 CheckOverlap(T.Receiver, T.Any); | |
318 CheckOverlap(T.Object, T.Any); | |
319 CheckOverlap(T.Object, T.Receiver); | |
320 CheckOverlap(T.Array, T.Object); | |
321 CheckOverlap(T.Function, T.Object); | |
322 CheckOverlap(T.Proxy, T.Receiver); | |
323 CheckDisjoint(T.Object, T.Proxy); | |
324 CheckDisjoint(T.Array, T.Function); | |
325 | |
326 CheckOverlap(T.ObjectClass, T.Object); | |
327 CheckOverlap(T.ArrayClass, T.Object); | |
328 CheckOverlap(T.ObjectClass, T.ObjectClass); | |
329 CheckOverlap(T.ArrayClass, T.ArrayClass); | |
330 CheckDisjoint(T.ObjectClass, T.ArrayClass); | |
331 | |
332 CheckOverlap(T.ObjectConstant1, T.Object); | |
333 CheckOverlap(T.ObjectConstant2, T.Object); | |
334 CheckOverlap(T.ArrayConstant, T.Object); | |
335 CheckOverlap(T.ArrayConstant, T.Array); | |
336 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1); | |
337 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2); | |
338 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant); | |
339 | |
340 CheckDisjoint(T.ObjectConstant1, T.ObjectClass); | |
341 CheckDisjoint(T.ObjectConstant2, T.ObjectClass); | |
342 CheckDisjoint(T.ObjectConstant1, T.ArrayClass); | |
343 CheckDisjoint(T.ObjectConstant2, T.ArrayClass); | |
344 CheckDisjoint(T.ArrayConstant, T.ObjectClass); | |
345 } | |
346 | |
347 | |
348 static void CheckEqual(Handle<Type> type1, Handle<Type> type2) { | |
349 CHECK_EQ(IsBitset(*type1), IsBitset(*type2)); | |
350 CHECK_EQ(IsClass(*type1), IsClass(*type2)); | |
351 CHECK_EQ(IsConstant(*type1), IsConstant(*type2)); | |
352 CHECK_EQ(IsUnion(*type1), IsUnion(*type2)); | |
353 if (IsBitset(*type1)) | |
354 CHECK_EQ(AsBitset(*type1), AsBitset(*type2)); | |
Jakob Kummerow
2013/06/05 14:53:24
nit: {} (and again below)
rossberg
2013/06/05 15:37:02
Done.
| |
355 if (IsClass(*type1)) | |
356 CHECK_EQ(AsClass(*type1), AsClass(*type2)); | |
357 if (IsConstant(*type1)) | |
358 CHECK_EQ(AsConstant(*type1), AsConstant(*type2)); | |
359 if (IsUnion(*type1)) | |
360 CHECK_EQ(AsUnion(*type1)->length(), AsUnion(*type2)->length()); | |
361 CHECK(type1->Is(type2)); | |
362 CHECK(type2->Is(type1)); | |
363 } | |
364 | |
365 TEST(Union) { | |
366 CcTest::InitializeVM(); | |
367 Isolate* isolate = Isolate::Current(); | |
368 HandleScope scope(isolate); | |
369 HandlifiedTypes T(isolate); | |
370 | |
371 // Bitset-bitset | |
372 CHECK(IsBitset(Type::Union(T.Object, T.Number))); | |
373 CHECK(IsBitset(Type::Union(T.Object, T.Object))); | |
374 CHECK(IsBitset(Type::Union(T.Any, T.None))); | |
375 | |
376 CheckEqual(T.Union(T.None, T.Number), T.Number); | |
377 CheckEqual(T.Union(T.Object, T.Proxy), T.Receiver); | |
378 CheckEqual(T.Union(T.Number, T.String), T.Union(T.String, T.Number)); | |
379 CheckSub(T.Union(T.Number, T.String), T.Any); | |
380 | |
381 // Class-class | |
382 CHECK(IsClass(Type::Union(T.ObjectClass, T.ObjectClass))); | |
383 CHECK(IsUnion(Type::Union(T.ObjectClass, T.ArrayClass))); | |
384 | |
385 CheckEqual(T.Union(T.ObjectClass, T.ObjectClass), T.ObjectClass); | |
386 CheckSub(T.ObjectClass, T.Union(T.ObjectClass, T.ArrayClass)); | |
387 CheckSub(T.ArrayClass, T.Union(T.ObjectClass, T.ArrayClass)); | |
388 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object); | |
389 CheckUnordered(T.Union(T.ObjectClass, T.ArrayClass), T.Array); | |
390 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.Array); | |
391 CheckDisjoint(T.Union(T.ObjectClass, T.ArrayClass), T.Number); | |
392 | |
393 // Constant-constant | |
394 CHECK(IsConstant(Type::Union(T.ObjectConstant1, T.ObjectConstant1))); | |
395 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectConstant2))); | |
396 | |
397 CheckEqual(T.Union(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); | |
398 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)); | |
399 CheckSub(T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ObjectConstant2)); | |
400 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object); | |
401 CheckUnordered(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); | |
402 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array); | |
403 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array); | |
404 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Number); | |
405 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant), T.ObjectClass); | |
406 | |
407 // Bitset-class | |
408 CHECK(IsBitset(Type::Union(T.ObjectClass, T.Object))); | |
409 CHECK(IsUnion(Type::Union(T.ObjectClass, T.Number))); | |
410 | |
411 CheckEqual(T.Union(T.ObjectClass, T.Object), T.Object); | |
412 CheckSub(T.Union(T.ObjectClass, T.Number), T.Any); | |
413 CheckSub(T.Union(T.ObjectClass, T.Smi), T.Union(T.Object, T.Number)); | |
414 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); | |
415 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); | |
416 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); | |
417 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number); | |
418 | |
419 // Bitset-constant | |
420 CHECK(IsBitset(Type::Union(T.ObjectConstant1, T.Object))); | |
421 CHECK(IsUnion(Type::Union(T.ObjectConstant2, T.Number))); | |
422 | |
423 CheckEqual(T.Union(T.ObjectConstant1, T.Object), T.Object); | |
424 CheckSub(T.Union(T.ObjectConstant1, T.Number), T.Any); | |
425 CheckSub(T.Union(T.ObjectConstant1, T.Smi), T.Union(T.Object, T.Number)); | |
426 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object); | |
427 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array); | |
428 CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object); | |
429 CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number); | |
430 | |
431 // Class-constant | |
432 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectClass))); | |
433 CHECK(IsUnion(Type::Union(T.ArrayClass, T.ObjectConstant2))); | |
434 | |
435 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Object); | |
436 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ArrayClass)); | |
437 CheckSub(T.ArrayClass, T.Union(T.ObjectConstant1, T.ArrayClass)); | |
438 CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass)); | |
439 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), | |
440 T.Union(T.Array, T.Object)); | |
441 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant); | |
442 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2); | |
443 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectClass); | |
444 | |
445 // Bitset-union | |
446 CHECK(IsBitset(Type::Union(T.Object, | |
447 T.Union(T.ObjectConstant1, T.ObjectClass)))); | |
448 CHECK(IsUnion(Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), | |
449 T.Number))); | |
450 | |
451 CheckEqual(T.Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), | |
452 T.Object); | |
453 CheckEqual(T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), | |
454 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); | |
455 CheckSub(T.Double, | |
456 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number)); | |
457 CheckSub(T.ObjectConstant1, | |
458 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double)); | |
459 CheckSub(T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double), | |
460 T.Any); | |
461 CheckSub(T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double), | |
462 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); | |
463 | |
464 // Class-union | |
465 CHECK(IsUnion(Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), | |
466 T.ArrayClass))); | |
467 CHECK(IsUnion(Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), | |
468 T.ObjectClass))); | |
469 | |
470 CheckEqual(T.Union(T.ObjectClass, | |
471 T.Union(T.ObjectConstant1, T.ObjectClass)), | |
472 T.Union(T.ObjectClass, T.ObjectConstant1)); | |
473 CheckSub(T.Union(T.ObjectClass, | |
474 T.Union(T.ObjectConstant1, T.ObjectClass)), | |
475 T.Object); | |
476 CheckEqual(T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass), | |
477 T.Union(T.ArrayClass, T.ObjectConstant2)); | |
478 | |
479 // Constant-union | |
480 CHECK(IsUnion(Type::Union(T.ObjectConstant1, | |
481 T.Union(T.ObjectConstant1, T.ObjectConstant2)))); | |
482 CHECK(IsUnion(Type::Union(T.Union(T.ArrayConstant, T.ObjectClass), | |
483 T.ObjectConstant1))); | |
484 CHECK(IsUnion(Type::Union(T.Union(T.ArrayConstant, T.ObjectConstant2), | |
485 T.ObjectConstant1))); | |
486 | |
487 CheckEqual(T.Union(T.ObjectConstant1, | |
488 T.Union(T.ObjectConstant1, T.ObjectConstant2)), | |
489 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | |
490 CheckEqual(T.Union(T.Union(T.ArrayConstant, T.ObjectConstant2), | |
491 T.ObjectConstant1), | |
492 T.Union(T.ObjectConstant2, | |
493 T.Union(T.ArrayConstant, T.ObjectConstant1))); | |
494 | |
495 // Union-union | |
496 CHECK(IsBitset(Type::Union(T.Union(T.Number, T.ArrayClass), | |
497 T.Union(T.Smi, T.Array)))); | |
498 | |
499 CheckEqual(T.Union(T.Union(T.ObjectConstant2, T.ObjectConstant1), | |
500 T.Union(T.ObjectConstant1, T.ObjectConstant2)), | |
501 T.Union(T.ObjectConstant2, T.ObjectConstant1)); | |
502 CheckEqual(T.Union(T.Union(T.ObjectConstant2, T.ArrayConstant), | |
503 T.Union(T.ObjectConstant1, T.ArrayConstant)), | |
504 T.Union(T.Union(T.ObjectConstant1, T.ObjectConstant2), | |
505 T.ArrayConstant)); | |
506 CheckEqual(T.Union(T.Union(T.Number, T.ArrayClass), | |
507 T.Union(T.Smi, T.Array)), | |
508 T.Union(T.Number, T.Array)); | |
509 } | |
OLD | NEW |