Line data Source code
1 : // Copyright 2014 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/property.h"
6 :
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"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 42955 : std::ostream& operator<<(std::ostream& os,
18 : const PropertyAttributes& attributes) {
19 42955 : os << "[";
20 42955 : os << (((attributes & READ_ONLY) == 0) ? "W" : "_"); // writable
21 42955 : os << (((attributes & DONT_ENUM) == 0) ? "E" : "_"); // enumerable
22 42955 : os << (((attributes & DONT_DELETE) == 0) ? "C" : "_"); // configurable
23 42955 : os << "]";
24 42955 : return os;
25 : }
26 :
27 4188334 : Descriptor::Descriptor() : details_(Smi::zero()) {}
28 :
29 0 : Descriptor::Descriptor(Handle<Name> key, const MaybeObjectHandle& value,
30 : PropertyKind kind, PropertyAttributes attributes,
31 : PropertyLocation location, PropertyConstness constness,
32 : Representation representation, int field_index)
33 : : key_(key),
34 : value_(value),
35 : details_(kind, attributes, location, constness, representation,
36 2145396 : field_index) {
37 : DCHECK(key->IsUniqueName());
38 : DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
39 0 : }
40 :
41 1039 : Descriptor::Descriptor(Handle<Name> key, const MaybeObjectHandle& value,
42 : PropertyDetails details)
43 18676155 : : key_(key), value_(value), details_(details) {
44 : DCHECK(key->IsUniqueName());
45 : DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
46 1039 : }
47 :
48 13496 : 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 26992 : representation, MaybeObjectHandle(FieldType::Any(isolate)));
53 : }
54 :
55 18661620 : 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,
62 : field_index);
63 18661620 : return Descriptor(key, wrapped_field_type, details);
64 : }
65 :
66 330670 : 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 661340 : value->OptimalRepresentation(), 0);
71 : }
72 :
73 0 : 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 0 : MaybeObjectHandle any_type(FieldType::Any(), isolate);
78 : return DataField(key, field_index, attributes, PropertyConstness::kConst,
79 : Representation::Tagged(), any_type);
80 :
81 : } else {
82 : return Descriptor(key, MaybeObjectHandle(value), kData, attributes,
83 : kDescriptor, PropertyConstness::kConst,
84 : value->OptimalRepresentation(), field_index);
85 : }
86 : }
87 :
88 1814726 : 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 1814726 : Representation::Tagged(), 0);
94 : }
95 :
96 : // Outputs PropertyDetails as a dictionary details.
97 0 : void PropertyDetails::PrintAsSlowTo(std::ostream& os) {
98 0 : os << "(";
99 0 : if (constness() == PropertyConstness::kConst) os << "const ";
100 0 : os << (kind() == kData ? "data" : "accessor");
101 0 : os << ", dict_index: " << dictionary_index();
102 0 : os << ", attrs: " << attributes() << ")";
103 0 : }
104 :
105 : // Outputs PropertyDetails as a descriptor array details.
106 42955 : void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) {
107 42955 : os << "(";
108 42955 : if (constness() == PropertyConstness::kConst) os << "const ";
109 42955 : os << (kind() == kData ? "data" : "accessor");
110 42955 : if (location() == kField) {
111 32105 : os << " field";
112 32105 : if (mode & kPrintFieldIndex) {
113 32105 : os << " " << field_index();
114 : }
115 32105 : if (mode & kPrintRepresentation) {
116 64210 : os << ":" << representation().Mnemonic();
117 : }
118 : } else {
119 10850 : os << " descriptor";
120 : }
121 42955 : if (mode & kPrintPointer) {
122 42955 : os << ", p: " << pointer();
123 : }
124 42955 : if (mode & kPrintAttributes) {
125 85910 : os << ", attrs: " << attributes();
126 : }
127 42955 : os << ")";
128 42955 : }
129 :
130 : #ifdef OBJECT_PRINT
131 : void PropertyDetails::Print(bool dictionary_mode) {
132 : StdoutStream os;
133 : if (dictionary_mode) {
134 : PrintAsSlowTo(os);
135 : } else {
136 : PrintAsFastTo(os, PrintMode::kPrintFull);
137 : }
138 : os << "\n" << std::flush;
139 : }
140 : #endif
141 :
142 : } // namespace internal
143 122036 : } // namespace v8
|