1 // Copyright 2021 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 #include "src/objects/object-type.h" 6 7 #include "src/objects/objects-inl.h" 8 #include "src/objects/smi.h" 9 #include "src/objects/string-inl.h" 10 11 namespace v8 { 12 namespace internal { 13 CheckObjectType(Address raw_value,Address raw_type,Address raw_location)14Address CheckObjectType(Address raw_value, Address raw_type, 15 Address raw_location) { 16 #ifdef DEBUG 17 Object value(raw_value); 18 Smi type(raw_type); 19 String location = String::cast(Object(raw_location)); 20 const char* expected; 21 switch (static_cast<ObjectType>(type.value())) { 22 #define TYPE_CASE(Name) \ 23 case ObjectType::k##Name: \ 24 if (value.Is##Name()) return Smi::FromInt(0).ptr(); \ 25 expected = #Name; \ 26 break; 27 #define TYPE_STRUCT_CASE(NAME, Name, name) \ 28 case ObjectType::k##Name: \ 29 if (value.Is##Name()) return Smi::FromInt(0).ptr(); \ 30 expected = #Name; \ 31 break; 32 33 TYPE_CASE(Object) 34 TYPE_CASE(Smi) 35 TYPE_CASE(TaggedIndex) 36 TYPE_CASE(HeapObject) 37 OBJECT_TYPE_LIST(TYPE_CASE) 38 HEAP_OBJECT_TYPE_LIST(TYPE_CASE) 39 STRUCT_LIST(TYPE_STRUCT_CASE) 40 #undef TYPE_CASE 41 #undef TYPE_STRUCT_CASE 42 } 43 std::stringstream value_description; 44 value.Print(value_description); 45 FATAL( 46 "Type cast failed in %s\n" 47 " Expected %s but found %s", 48 location.ToAsciiArray(), expected, value_description.str().c_str()); 49 #else 50 UNREACHABLE(); 51 #endif 52 } 53 54 } // namespace internal 55 } // namespace v8 56