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/ostreams.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 0 : std::ostream& operator<<(std::ostream& os,
16 : const PropertyAttributes& attributes) {
17 0 : os << "[";
18 0 : os << (((attributes & READ_ONLY) == 0) ? "W" : "_"); // writable
19 0 : os << (((attributes & DONT_ENUM) == 0) ? "E" : "_"); // enumerable
20 0 : os << (((attributes & DONT_DELETE) == 0) ? "C" : "_"); // configurable
21 0 : os << "]";
22 0 : return os;
23 : }
24 :
25 1960330 : Descriptor Descriptor::DataField(Handle<Name> key, int field_index,
26 : PropertyAttributes attributes,
27 : Representation representation) {
28 : return DataField(key, field_index, attributes, kMutable, representation,
29 3920662 : FieldType::Any(key->GetIsolate()));
30 : }
31 :
32 10613539 : Descriptor Descriptor::DataField(Handle<Name> key, int field_index,
33 : PropertyAttributes attributes,
34 : PropertyConstness constness,
35 : Representation representation,
36 : Handle<Object> wrapped_field_type) {
37 : DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell());
38 : PropertyDetails details(kData, attributes, kField, constness, representation,
39 : field_index);
40 10613539 : return Descriptor(key, wrapped_field_type, details);
41 : }
42 :
43 6722400 : Descriptor Descriptor::DataConstant(Handle<Name> key, int field_index,
44 : Handle<Object> value,
45 : PropertyAttributes attributes) {
46 : if (FLAG_track_constant_fields) {
47 : Handle<Object> any_type(FieldType::Any(), key->GetIsolate());
48 : return DataField(key, field_index, attributes, kConst,
49 : Representation::Tagged(), any_type);
50 :
51 : } else {
52 : return Descriptor(key, value, kData, attributes, kDescriptor, kConst,
53 6722400 : value->OptimalRepresentation(), field_index);
54 : }
55 : }
56 :
57 : // Outputs PropertyDetails as a dictionary details.
58 0 : void PropertyDetails::PrintAsSlowTo(std::ostream& os) {
59 0 : os << "(";
60 0 : if (constness() == kConst) os << "const ";
61 0 : os << (kind() == kData ? "data" : "accessor");
62 0 : os << ", dict_index: " << dictionary_index();
63 0 : os << ", attrs: " << attributes() << ")";
64 0 : }
65 :
66 : // Outputs PropertyDetails as a descriptor array details.
67 0 : void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) {
68 0 : os << "(";
69 0 : if (constness() == kConst) os << "const ";
70 0 : os << (kind() == kData ? "data" : "accessor");
71 0 : if (location() == kField) {
72 0 : os << " field";
73 0 : if (mode & kPrintFieldIndex) {
74 0 : os << " " << field_index();
75 : }
76 0 : if (mode & kPrintRepresentation) {
77 0 : os << ":" << representation().Mnemonic();
78 : }
79 : } else {
80 0 : os << " descriptor";
81 : }
82 0 : if (mode & kPrintPointer) {
83 0 : os << ", p: " << pointer();
84 : }
85 0 : if (mode & kPrintAttributes) {
86 0 : os << ", attrs: " << attributes();
87 : }
88 0 : os << ")";
89 0 : }
90 :
91 : #ifdef OBJECT_PRINT
92 : void PropertyDetails::Print(bool dictionary_mode) {
93 : OFStream os(stdout);
94 : if (dictionary_mode) {
95 : PrintAsSlowTo(os);
96 : } else {
97 : PrintAsFastTo(os, PrintMode::kPrintFull);
98 : }
99 : os << "\n" << std::flush;
100 : }
101 : #endif
102 :
103 : } // namespace internal
104 : } // namespace v8
|