5 #include "src/field-type.h" 7 #include "src/handles-inl.h" 8 #include "src/objects-inl.h" 9 #include "src/objects/smi.h" 10 #include "src/ostreams.h" 16 FieldType FieldType::None() {
return FieldType(Smi::FromInt(2).ptr()); }
19 FieldType FieldType::Any() {
return FieldType(Smi::FromInt(1).ptr()); }
22 Handle<FieldType> FieldType::None(Isolate* isolate) {
23 return handle(None(), isolate);
27 Handle<FieldType> FieldType::Any(Isolate* isolate) {
28 return handle(Any(), isolate);
32 FieldType FieldType::Class(Map map) {
return FieldType::cast(map); }
35 Handle<FieldType> FieldType::Class(Handle<Map> map, Isolate* isolate) {
36 return handle(Class(*map), isolate);
40 FieldType FieldType::cast(Object*
object) {
41 DCHECK(
object == None() ||
object == Any() || object->IsMap());
42 return FieldType(object->ptr());
45 bool FieldType::IsClass()
const {
return this->IsMap(); }
47 Map FieldType::AsClass()
const {
49 return Map::cast(*
this);
52 bool FieldType::NowStable()
const {
53 return !this->IsClass() || AsClass()->is_stable();
56 bool FieldType::NowIs(FieldType other)
const {
57 if (other->IsAny())
return true;
58 if (IsNone())
return true;
59 if (other->IsNone())
return false;
60 if (IsAny())
return false;
62 DCHECK(other->IsClass());
63 return *
this == other;
66 bool FieldType::NowIs(Handle<FieldType> other)
const {
return NowIs(*other); }
68 void FieldType::PrintTo(std::ostream& os)
const {
71 }
else if (IsNone()) {
75 os <<
"Class(" <<
static_cast<void*
>(AsClass()) <<
")";
79 bool FieldType::NowContains(Object* value)
const {
80 if (*
this == Any())
return true;
81 if (*
this == None())
return false;
82 if (!value->IsHeapObject())
return false;
83 return HeapObject::cast(value)->map() == Map::cast(*
this);