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)); |
| 184 } |
| 185 } |
| 186 |
| 187 static void CheckUnordered(Handle<Type> type1, Handle<Type> type2) { |
| 188 CHECK(!type1->Is(type2)); |
| 189 CHECK(!type2->Is(type1)); |
| 190 if (IsBitset(*type1) && IsBitset(*type2)) { |
| 191 CHECK_NE(AsBitset(*type1), AsBitset(*type2)); |
| 192 } |
| 193 } |
| 194 |
| 195 TEST(Is) { |
| 196 CcTest::InitializeVM(); |
| 197 Isolate* isolate = Isolate::Current(); |
| 198 HandleScope scope(isolate); |
| 199 HandlifiedTypes T(isolate); |
| 200 |
| 201 // Reflexivity |
| 202 CHECK(T.None->Is(T.None)); |
| 203 CHECK(T.Any->Is(T.Any)); |
| 204 CHECK(T.Object->Is(T.Object)); |
| 205 |
| 206 CHECK(T.ObjectClass->Is(T.ObjectClass)); |
| 207 CHECK(T.ObjectConstant1->Is(T.ObjectConstant1)); |
| 208 |
| 209 // Symmetry and Transitivity |
| 210 CheckSub(T.None, T.Number); |
| 211 CheckSub(T.None, T.Any); |
| 212 |
| 213 CheckSub(T.Oddball, T.Any); |
| 214 CheckSub(T.Boolean, T.Oddball); |
| 215 CheckSub(T.Null, T.Oddball); |
| 216 CheckSub(T.Undefined, T.Oddball); |
| 217 CheckUnordered(T.Boolean, T.Null); |
| 218 CheckUnordered(T.Undefined, T.Null); |
| 219 CheckUnordered(T.Boolean, T.Undefined); |
| 220 |
| 221 CheckSub(T.Number, T.Any); |
| 222 CheckSub(T.Smi, T.Number); |
| 223 CheckSub(T.Double, T.Number); |
| 224 CheckUnordered(T.Smi, T.Double); |
| 225 |
| 226 CheckSub(T.Name, T.Any); |
| 227 CheckSub(T.UniqueName, T.Any); |
| 228 CheckSub(T.UniqueName, T.Name); |
| 229 CheckSub(T.String, T.Name); |
| 230 CheckSub(T.InternalizedString, T.String); |
| 231 CheckSub(T.InternalizedString, T.UniqueName); |
| 232 CheckSub(T.InternalizedString, T.Name); |
| 233 CheckSub(T.Symbol, T.UniqueName); |
| 234 CheckSub(T.Symbol, T.Name); |
| 235 CheckUnordered(T.String, T.UniqueName); |
| 236 CheckUnordered(T.String, T.Symbol); |
| 237 CheckUnordered(T.InternalizedString, T.Symbol); |
| 238 |
| 239 CheckSub(T.Receiver, T.Any); |
| 240 CheckSub(T.Object, T.Any); |
| 241 CheckSub(T.Object, T.Receiver); |
| 242 CheckSub(T.Array, T.Object); |
| 243 CheckSub(T.Function, T.Object); |
| 244 CheckSub(T.Proxy, T.Receiver); |
| 245 CheckUnordered(T.Object, T.Proxy); |
| 246 CheckUnordered(T.Array, T.Function); |
| 247 |
| 248 // Structured subtyping |
| 249 CheckSub(T.ObjectClass, T.Object); |
| 250 CheckSub(T.ArrayClass, T.Object); |
| 251 CheckUnordered(T.ObjectClass, T.ArrayClass); |
| 252 |
| 253 CheckSub(T.ObjectConstant1, T.Object); |
| 254 CheckSub(T.ObjectConstant2, T.Object); |
| 255 CheckSub(T.ArrayConstant, T.Object); |
| 256 CheckSub(T.ArrayConstant, T.Array); |
| 257 CheckUnordered(T.ObjectConstant1, T.ObjectConstant2); |
| 258 CheckUnordered(T.ObjectConstant1, T.ArrayConstant); |
| 259 |
| 260 CheckUnordered(T.ObjectConstant1, T.ObjectClass); |
| 261 CheckUnordered(T.ObjectConstant2, T.ObjectClass); |
| 262 CheckUnordered(T.ObjectConstant1, T.ArrayClass); |
| 263 CheckUnordered(T.ObjectConstant2, T.ArrayClass); |
| 264 CheckUnordered(T.ArrayConstant, T.ObjectClass); |
| 265 } |
| 266 |
| 267 |
| 268 static void CheckOverlap(Handle<Type> type1, Handle<Type> type2) { |
| 269 CHECK(type1->Maybe(type2)); |
| 270 CHECK(type2->Maybe(type1)); |
| 271 if (IsBitset(*type1) && IsBitset(*type2)) { |
| 272 CHECK_NE(0, AsBitset(*type1) & AsBitset(*type2)); |
| 273 } |
| 274 } |
| 275 |
| 276 static void CheckDisjoint(Handle<Type> type1, Handle<Type> type2) { |
| 277 CHECK(!type1->Is(type2)); |
| 278 CHECK(!type2->Is(type1)); |
| 279 CHECK(!type1->Maybe(type2)); |
| 280 CHECK(!type2->Maybe(type1)); |
| 281 if (IsBitset(*type1) && IsBitset(*type2)) { |
| 282 CHECK_EQ(0, AsBitset(*type1) & AsBitset(*type2)); |
| 283 } |
| 284 } |
| 285 |
| 286 TEST(Maybe) { |
| 287 CcTest::InitializeVM(); |
| 288 Isolate* isolate = Isolate::Current(); |
| 289 HandleScope scope(isolate); |
| 290 HandlifiedTypes T(isolate); |
| 291 |
| 292 CheckOverlap(T.Any, T.Any); |
| 293 CheckOverlap(T.Object, T.Object); |
| 294 |
| 295 CheckOverlap(T.Oddball, T.Any); |
| 296 CheckOverlap(T.Boolean, T.Oddball); |
| 297 CheckOverlap(T.Null, T.Oddball); |
| 298 CheckOverlap(T.Undefined, T.Oddball); |
| 299 CheckDisjoint(T.Boolean, T.Null); |
| 300 CheckDisjoint(T.Undefined, T.Null); |
| 301 CheckDisjoint(T.Boolean, T.Undefined); |
| 302 |
| 303 CheckOverlap(T.Number, T.Any); |
| 304 CheckOverlap(T.Smi, T.Number); |
| 305 CheckOverlap(T.Double, T.Number); |
| 306 CheckDisjoint(T.Smi, T.Double); |
| 307 |
| 308 CheckOverlap(T.Name, T.Any); |
| 309 CheckOverlap(T.UniqueName, T.Any); |
| 310 CheckOverlap(T.UniqueName, T.Name); |
| 311 CheckOverlap(T.String, T.Name); |
| 312 CheckOverlap(T.InternalizedString, T.String); |
| 313 CheckOverlap(T.InternalizedString, T.UniqueName); |
| 314 CheckOverlap(T.InternalizedString, T.Name); |
| 315 CheckOverlap(T.Symbol, T.UniqueName); |
| 316 CheckOverlap(T.Symbol, T.Name); |
| 317 CheckOverlap(T.String, T.UniqueName); |
| 318 CheckDisjoint(T.String, T.Symbol); |
| 319 CheckDisjoint(T.InternalizedString, T.Symbol); |
| 320 |
| 321 CheckOverlap(T.Receiver, T.Any); |
| 322 CheckOverlap(T.Object, T.Any); |
| 323 CheckOverlap(T.Object, T.Receiver); |
| 324 CheckOverlap(T.Array, T.Object); |
| 325 CheckOverlap(T.Function, T.Object); |
| 326 CheckOverlap(T.Proxy, T.Receiver); |
| 327 CheckDisjoint(T.Object, T.Proxy); |
| 328 CheckDisjoint(T.Array, T.Function); |
| 329 |
| 330 CheckOverlap(T.ObjectClass, T.Object); |
| 331 CheckOverlap(T.ArrayClass, T.Object); |
| 332 CheckOverlap(T.ObjectClass, T.ObjectClass); |
| 333 CheckOverlap(T.ArrayClass, T.ArrayClass); |
| 334 CheckDisjoint(T.ObjectClass, T.ArrayClass); |
| 335 |
| 336 CheckOverlap(T.ObjectConstant1, T.Object); |
| 337 CheckOverlap(T.ObjectConstant2, T.Object); |
| 338 CheckOverlap(T.ArrayConstant, T.Object); |
| 339 CheckOverlap(T.ArrayConstant, T.Array); |
| 340 CheckOverlap(T.ObjectConstant1, T.ObjectConstant1); |
| 341 CheckDisjoint(T.ObjectConstant1, T.ObjectConstant2); |
| 342 CheckDisjoint(T.ObjectConstant1, T.ArrayConstant); |
| 343 |
| 344 CheckDisjoint(T.ObjectConstant1, T.ObjectClass); |
| 345 CheckDisjoint(T.ObjectConstant2, T.ObjectClass); |
| 346 CheckDisjoint(T.ObjectConstant1, T.ArrayClass); |
| 347 CheckDisjoint(T.ObjectConstant2, T.ArrayClass); |
| 348 CheckDisjoint(T.ArrayConstant, T.ObjectClass); |
| 349 } |
| 350 |
| 351 |
| 352 static void CheckEqual(Handle<Type> type1, Handle<Type> type2) { |
| 353 CHECK_EQ(IsBitset(*type1), IsBitset(*type2)); |
| 354 CHECK_EQ(IsClass(*type1), IsClass(*type2)); |
| 355 CHECK_EQ(IsConstant(*type1), IsConstant(*type2)); |
| 356 CHECK_EQ(IsUnion(*type1), IsUnion(*type2)); |
| 357 if (IsBitset(*type1)) { |
| 358 CHECK_EQ(AsBitset(*type1), AsBitset(*type2)); |
| 359 } else if (IsClass(*type1)) { |
| 360 CHECK_EQ(AsClass(*type1), AsClass(*type2)); |
| 361 } else if (IsConstant(*type1)) { |
| 362 CHECK_EQ(AsConstant(*type1), AsConstant(*type2)); |
| 363 } else if (IsUnion(*type1)) { |
| 364 CHECK_EQ(AsUnion(*type1)->length(), AsUnion(*type2)->length()); |
| 365 } |
| 366 CHECK(type1->Is(type2)); |
| 367 CHECK(type2->Is(type1)); |
| 368 } |
| 369 |
| 370 TEST(Union) { |
| 371 CcTest::InitializeVM(); |
| 372 Isolate* isolate = Isolate::Current(); |
| 373 HandleScope scope(isolate); |
| 374 HandlifiedTypes T(isolate); |
| 375 |
| 376 // Bitset-bitset |
| 377 CHECK(IsBitset(Type::Union(T.Object, T.Number))); |
| 378 CHECK(IsBitset(Type::Union(T.Object, T.Object))); |
| 379 CHECK(IsBitset(Type::Union(T.Any, T.None))); |
| 380 |
| 381 CheckEqual(T.Union(T.None, T.Number), T.Number); |
| 382 CheckEqual(T.Union(T.Object, T.Proxy), T.Receiver); |
| 383 CheckEqual(T.Union(T.Number, T.String), T.Union(T.String, T.Number)); |
| 384 CheckSub(T.Union(T.Number, T.String), T.Any); |
| 385 |
| 386 // Class-class |
| 387 CHECK(IsClass(Type::Union(T.ObjectClass, T.ObjectClass))); |
| 388 CHECK(IsUnion(Type::Union(T.ObjectClass, T.ArrayClass))); |
| 389 |
| 390 CheckEqual(T.Union(T.ObjectClass, T.ObjectClass), T.ObjectClass); |
| 391 CheckSub(T.ObjectClass, T.Union(T.ObjectClass, T.ArrayClass)); |
| 392 CheckSub(T.ArrayClass, T.Union(T.ObjectClass, T.ArrayClass)); |
| 393 CheckSub(T.Union(T.ObjectClass, T.ArrayClass), T.Object); |
| 394 CheckUnordered(T.Union(T.ObjectClass, T.ArrayClass), T.Array); |
| 395 CheckOverlap(T.Union(T.ObjectClass, T.ArrayClass), T.Array); |
| 396 CheckDisjoint(T.Union(T.ObjectClass, T.ArrayClass), T.Number); |
| 397 |
| 398 // Constant-constant |
| 399 CHECK(IsConstant(Type::Union(T.ObjectConstant1, T.ObjectConstant1))); |
| 400 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectConstant2))); |
| 401 |
| 402 CheckEqual(T.Union(T.ObjectConstant1, T.ObjectConstant1), T.ObjectConstant1); |
| 403 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)); |
| 404 CheckSub(T.ObjectConstant2, T.Union(T.ObjectConstant1, T.ObjectConstant2)); |
| 405 CheckSub(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.Object); |
| 406 CheckUnordered(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ObjectClass); |
| 407 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array); |
| 408 CheckOverlap(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Array); |
| 409 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant), T.Number); |
| 410 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayConstant), T.ObjectClass); |
| 411 |
| 412 // Bitset-class |
| 413 CHECK(IsBitset(Type::Union(T.ObjectClass, T.Object))); |
| 414 CHECK(IsUnion(Type::Union(T.ObjectClass, T.Number))); |
| 415 |
| 416 CheckEqual(T.Union(T.ObjectClass, T.Object), T.Object); |
| 417 CheckSub(T.Union(T.ObjectClass, T.Number), T.Any); |
| 418 CheckSub(T.Union(T.ObjectClass, T.Smi), T.Union(T.Object, T.Number)); |
| 419 CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); |
| 420 CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); |
| 421 CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); |
| 422 CheckDisjoint(T.Union(T.ObjectClass, T.String), T.Number); |
| 423 |
| 424 // Bitset-constant |
| 425 CHECK(IsBitset(Type::Union(T.ObjectConstant1, T.Object))); |
| 426 CHECK(IsUnion(Type::Union(T.ObjectConstant2, T.Number))); |
| 427 |
| 428 CheckEqual(T.Union(T.ObjectConstant1, T.Object), T.Object); |
| 429 CheckSub(T.Union(T.ObjectConstant1, T.Number), T.Any); |
| 430 CheckSub(T.Union(T.ObjectConstant1, T.Smi), T.Union(T.Object, T.Number)); |
| 431 CheckSub(T.Union(T.ObjectConstant1, T.Array), T.Object); |
| 432 CheckUnordered(T.Union(T.ObjectConstant1, T.String), T.Array); |
| 433 CheckOverlap(T.Union(T.ObjectConstant1, T.String), T.Object); |
| 434 CheckDisjoint(T.Union(T.ObjectConstant1, T.String), T.Number); |
| 435 |
| 436 // Class-constant |
| 437 CHECK(IsUnion(Type::Union(T.ObjectConstant1, T.ObjectClass))); |
| 438 CHECK(IsUnion(Type::Union(T.ArrayClass, T.ObjectConstant2))); |
| 439 |
| 440 CheckSub(T.Union(T.ObjectConstant1, T.ArrayClass), T.Object); |
| 441 CheckSub(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ArrayClass)); |
| 442 CheckSub(T.ArrayClass, T.Union(T.ObjectConstant1, T.ArrayClass)); |
| 443 CheckUnordered(T.ObjectClass, T.Union(T.ObjectConstant1, T.ArrayClass)); |
| 444 CheckSub( |
| 445 T.Union(T.ObjectConstant1, T.ArrayClass), T.Union(T.Array, T.Object)); |
| 446 CheckUnordered(T.Union(T.ObjectConstant1, T.ArrayClass), T.ArrayConstant); |
| 447 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectConstant2); |
| 448 CheckDisjoint(T.Union(T.ObjectConstant1, T.ArrayClass), T.ObjectClass); |
| 449 |
| 450 // Bitset-union |
| 451 CHECK(IsBitset( |
| 452 Type::Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)))); |
| 453 CHECK(IsUnion( |
| 454 Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.Number))); |
| 455 |
| 456 CheckEqual( |
| 457 T.Union(T.Object, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 458 T.Object); |
| 459 CheckEqual( |
| 460 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number), |
| 461 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); |
| 462 CheckSub( |
| 463 T.Double, |
| 464 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Number)); |
| 465 CheckSub( |
| 466 T.ObjectConstant1, |
| 467 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double)); |
| 468 CheckSub( |
| 469 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double), |
| 470 T.Any); |
| 471 CheckSub( |
| 472 T.Union(T.Union(T.ArrayClass, T.ObjectConstant1), T.Double), |
| 473 T.Union(T.ObjectConstant1, T.Union(T.Number, T.ArrayClass))); |
| 474 |
| 475 // Class-union |
| 476 CHECK(IsUnion( |
| 477 Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass))); |
| 478 CHECK(IsUnion( |
| 479 Type::Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ObjectClass))); |
| 480 |
| 481 CheckEqual( |
| 482 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 483 T.Union(T.ObjectClass, T.ObjectConstant1)); |
| 484 CheckSub( |
| 485 T.Union(T.ObjectClass, T.Union(T.ObjectConstant1, T.ObjectClass)), |
| 486 T.Object); |
| 487 CheckEqual( |
| 488 T.Union(T.Union(T.ArrayClass, T.ObjectConstant2), T.ArrayClass), |
| 489 T.Union(T.ArrayClass, T.ObjectConstant2)); |
| 490 |
| 491 // Constant-union |
| 492 CHECK(IsUnion(Type::Union( |
| 493 T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)))); |
| 494 CHECK(IsUnion(Type::Union( |
| 495 T.Union(T.ArrayConstant, T.ObjectClass), T.ObjectConstant1))); |
| 496 CHECK(IsUnion(Type::Union( |
| 497 T.Union(T.ArrayConstant, T.ObjectConstant2), T.ObjectConstant1))); |
| 498 |
| 499 CheckEqual( |
| 500 T.Union(T.ObjectConstant1, T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 501 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 502 CheckEqual( |
| 503 T.Union(T.Union(T.ArrayConstant, T.ObjectConstant2), T.ObjectConstant1), |
| 504 T.Union(T.ObjectConstant2, T.Union(T.ArrayConstant, T.ObjectConstant1))); |
| 505 |
| 506 // Union-union |
| 507 CHECK(IsBitset( |
| 508 Type::Union(T.Union(T.Number, T.ArrayClass), T.Union(T.Smi, T.Array)))); |
| 509 |
| 510 CheckEqual( |
| 511 T.Union(T.Union(T.ObjectConstant2, T.ObjectConstant1), |
| 512 T.Union(T.ObjectConstant1, T.ObjectConstant2)), |
| 513 T.Union(T.ObjectConstant2, T.ObjectConstant1)); |
| 514 CheckEqual( |
| 515 T.Union(T.Union(T.ObjectConstant2, T.ArrayConstant), |
| 516 T.Union(T.ObjectConstant1, T.ArrayConstant)), |
| 517 T.Union(T.Union(T.ObjectConstant1, T.ObjectConstant2), T.ArrayConstant)); |
| 518 CheckEqual( |
| 519 T.Union(T.Union(T.Number, T.ArrayClass), T.Union(T.Smi, T.Array)), |
| 520 T.Union(T.Number, T.Array)); |
| 521 } |
OLD | NEW |