OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/property.h" | 5 #include "src/property.h" |
6 | 6 |
7 #include "src/field-type.h" | 7 #include "src/field-type.h" |
8 #include "src/handles-inl.h" | 8 #include "src/handles-inl.h" |
9 #include "src/objects-inl.h" | 9 #include "src/objects-inl.h" |
10 #include "src/ostreams.h" | 10 #include "src/ostreams.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 return os; | 22 return os; |
23 } | 23 } |
24 | 24 |
25 Descriptor Descriptor::DataField(Handle<Name> key, int field_index, | 25 Descriptor Descriptor::DataField(Handle<Name> key, int field_index, |
26 PropertyAttributes attributes, | 26 PropertyAttributes attributes, |
27 Representation representation) { | 27 Representation representation) { |
28 return Descriptor(key, FieldType::Any(key->GetIsolate()), attributes, DATA, | 28 return Descriptor(key, FieldType::Any(key->GetIsolate()), attributes, DATA, |
29 representation, field_index); | 29 representation, field_index); |
30 } | 30 } |
31 | 31 |
32 struct FastPropertyDetails { | |
33 explicit FastPropertyDetails(const PropertyDetails& v) : details(v) {} | |
34 const PropertyDetails details; | |
35 }; | |
36 | |
37 | |
38 // Outputs PropertyDetails as a dictionary details. | 32 // Outputs PropertyDetails as a dictionary details. |
39 std::ostream& operator<<(std::ostream& os, const PropertyDetails& details) { | 33 void PropertyDetails::PrintAsSlowTo(std::ostream& os) { |
40 os << "("; | 34 os << "("; |
41 if (details.location() == kDescriptor) { | 35 os << (kind() == kData ? "data" : "accessor"); |
42 os << "immutable "; | 36 os << ", dictionary_index: " << dictionary_index(); |
43 } | 37 os << ", attrs: " << attributes() << ")"; |
44 os << (details.kind() == kData ? "data" : "accessor"); | |
45 return os << ", dictionary_index: " << details.dictionary_index() | |
46 << ", attrs: " << details.attributes() << ")"; | |
47 } | 38 } |
48 | 39 |
49 | |
50 // Outputs PropertyDetails as a descriptor array details. | 40 // Outputs PropertyDetails as a descriptor array details. |
51 std::ostream& operator<<(std::ostream& os, | 41 void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) { |
52 const FastPropertyDetails& details_fast) { | |
53 const PropertyDetails& details = details_fast.details; | |
54 os << "("; | 42 os << "("; |
55 if (details.location() == kDescriptor) { | 43 os << (kind() == kData ? "data" : "accessor"); |
56 os << "immutable "; | 44 if (location() == kField) { |
45 os << " field"; | |
46 if (mode & kPrintFieldIndex) { | |
47 os << " " << field_index(); | |
48 } | |
49 if (mode & kPrintRepresentation) { | |
50 os << ":" << representation().Mnemonic(); | |
Jakob Kummerow
2017/01/12 15:53:20
nit: might want a space after ':'
Igor Sheludko
2017/01/12 15:56:00
It looks better without a space.
| |
51 } | |
52 } else { | |
53 os << " descriptor"; | |
57 } | 54 } |
58 os << (details.kind() == kData ? "data" : "accessor"); | 55 if (mode & kPrintPointer) { |
59 os << ": " << details.representation().Mnemonic(); | 56 os << ", p: " << pointer(); |
60 if (details.location() == kField) { | |
61 os << ", field_index: " << details.field_index(); | |
62 } | 57 } |
63 return os << ", p: " << details.pointer() | 58 if (mode & kPrintAttributes) { |
64 << ", attrs: " << details.attributes() << ")"; | 59 os << ", attrs: " << attributes(); |
60 } | |
61 os << ")"; | |
65 } | 62 } |
66 | 63 |
67 | |
68 #ifdef OBJECT_PRINT | 64 #ifdef OBJECT_PRINT |
69 void PropertyDetails::Print(bool dictionary_mode) { | 65 void PropertyDetails::Print(bool dictionary_mode) { |
70 OFStream os(stdout); | 66 OFStream os(stdout); |
71 if (dictionary_mode) { | 67 if (dictionary_mode) { |
72 os << *this; | 68 PrintAsSlowTo(os); |
73 } else { | 69 } else { |
74 os << FastPropertyDetails(*this); | 70 PrintAsFastTo(os, PrintMode::kPrintFull); |
75 } | 71 } |
76 os << "\n" << std::flush; | 72 os << "\n" << std::flush; |
77 } | 73 } |
78 #endif | 74 #endif |
79 | 75 |
80 | |
81 std::ostream& operator<<(std::ostream& os, const Descriptor& d) { | |
82 Object* value = *d.GetValue(); | |
83 os << "Descriptor " << Brief(*d.GetKey()) << " @ " << Brief(value) << " "; | |
84 if (value->IsAccessorPair()) { | |
85 AccessorPair* pair = AccessorPair::cast(value); | |
86 os << "(get: " << Brief(pair->getter()) | |
87 << ", set: " << Brief(pair->setter()) << ") "; | |
88 } | |
89 os << FastPropertyDetails(d.GetDetails()); | |
90 return os; | |
91 } | |
92 | |
93 } // namespace internal | 76 } // namespace internal |
94 } // namespace v8 | 77 } // namespace v8 |
OLD | NEW |