5 #include "src/property.h" 7 #include "src/field-type.h" 8 #include "src/handles-inl.h" 9 #include "src/objects-inl.h" 10 #include "src/objects/name-inl.h" 11 #include "src/objects/smi.h" 12 #include "src/ostreams.h" 17 std::ostream& operator<<(std::ostream& os,
18 const PropertyAttributes& attributes) {
20 os << (((attributes & READ_ONLY) == 0) ?
"W" :
"_");
21 os << (((attributes & DONT_ENUM) == 0) ?
"E" :
"_");
22 os << (((attributes & DONT_DELETE) == 0) ?
"C" :
"_");
27 Descriptor::Descriptor() : details_(Smi::zero()) {}
29 Descriptor::Descriptor(Handle<Name> key,
const MaybeObjectHandle& value,
30 PropertyKind kind, PropertyAttributes attributes,
31 PropertyLocation location, PropertyConstness constness,
32 Representation representation,
int field_index)
35 details_(kind, attributes, location, constness, representation,
37 DCHECK(key->IsUniqueName());
38 DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
41 Descriptor::Descriptor(Handle<Name> key,
const MaybeObjectHandle& value,
42 PropertyDetails details)
43 : key_(key), value_(value), details_(details) {
44 DCHECK(key->IsUniqueName());
45 DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
48 Descriptor Descriptor::DataField(Isolate* isolate, Handle<Name> key,
49 int field_index, PropertyAttributes attributes,
50 Representation representation) {
51 return DataField(key, field_index, attributes, PropertyConstness::kMutable,
52 representation, MaybeObjectHandle(FieldType::Any(isolate)));
55 Descriptor Descriptor::DataField(Handle<Name> key,
int field_index,
56 PropertyAttributes attributes,
57 PropertyConstness constness,
58 Representation representation,
59 const MaybeObjectHandle& wrapped_field_type) {
60 DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeak());
61 PropertyDetails details(kData, attributes, kField, constness, representation,
63 return Descriptor(key, wrapped_field_type, details);
66 Descriptor Descriptor::DataConstant(Handle<Name> key, Handle<Object> value,
67 PropertyAttributes attributes) {
68 return Descriptor(key, MaybeObjectHandle(value), kData, attributes,
69 kDescriptor, PropertyConstness::kConst,
70 value->OptimalRepresentation(), 0);
73 Descriptor Descriptor::DataConstant(Isolate* isolate, Handle<Name> key,
74 int field_index, Handle<Object> value,
75 PropertyAttributes attributes) {
76 if (FLAG_track_constant_fields) {
77 MaybeObjectHandle any_type(FieldType::Any(), isolate);
78 return DataField(key, field_index, attributes, PropertyConstness::kConst,
79 Representation::Tagged(), any_type);
82 return Descriptor(key, MaybeObjectHandle(value), kData, attributes,
83 kDescriptor, PropertyConstness::kConst,
84 value->OptimalRepresentation(), field_index);
88 Descriptor Descriptor::AccessorConstant(Handle<Name> key,
89 Handle<Object> foreign,
90 PropertyAttributes attributes) {
91 return Descriptor(key, MaybeObjectHandle(foreign), kAccessor, attributes,
92 kDescriptor, PropertyConstness::kConst,
93 Representation::Tagged(), 0);
97 void PropertyDetails::PrintAsSlowTo(std::ostream& os) {
99 if (constness() == PropertyConstness::kConst) os <<
"const ";
100 os << (kind() == kData ?
"data" :
"accessor");
101 os <<
", dict_index: " << dictionary_index();
102 os <<
", attrs: " << attributes() <<
")";
106 void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) {
108 if (constness() == PropertyConstness::kConst) os <<
"const ";
109 os << (kind() == kData ?
"data" :
"accessor");
110 if (location() == kField) {
112 if (mode & kPrintFieldIndex) {
113 os <<
" " << field_index();
115 if (mode & kPrintRepresentation) {
116 os <<
":" << representation().Mnemonic();
121 if (mode & kPrintPointer) {
122 os <<
", p: " << pointer();
124 if (mode & kPrintAttributes) {
125 os <<
", attrs: " << attributes();
131 void PropertyDetails::Print(
bool dictionary_mode) {
133 if (dictionary_mode) {
136 PrintAsFastTo(os, PrintMode::kPrintFull);
138 os <<
"\n" << std::flush;