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/handles-inl.h"
8 #include "src/ostreams.h"
9
10 namespace v8 {
11 namespace internal {
12
operator <<(std::ostream & os,const PropertyAttributes & attributes)13 std::ostream& operator<<(std::ostream& os,
14 const PropertyAttributes& attributes) {
15 os << "[";
16 os << (((attributes & READ_ONLY) == 0) ? "W" : "_"); // writable
17 os << (((attributes & DONT_ENUM) == 0) ? "E" : "_"); // enumerable
18 os << (((attributes & DONT_DELETE) == 0) ? "C" : "_"); // configurable
19 os << "]";
20 return os;
21 }
22
23
24 struct FastPropertyDetails {
FastPropertyDetailsv8::internal::FastPropertyDetails25 explicit FastPropertyDetails(const PropertyDetails& v) : details(v) {}
26 const PropertyDetails details;
27 };
28
29
30 // Outputs PropertyDetails as a dictionary details.
operator <<(std::ostream & os,const PropertyDetails & details)31 std::ostream& operator<<(std::ostream& os, const PropertyDetails& details) {
32 os << "(";
33 if (details.location() == kDescriptor) {
34 os << "immutable ";
35 }
36 os << (details.kind() == kData ? "data" : "accessor");
37 return os << ", dictionary_index: " << details.dictionary_index()
38 << ", attrs: " << details.attributes() << ")";
39 }
40
41
42 // Outputs PropertyDetails as a descriptor array details.
operator <<(std::ostream & os,const FastPropertyDetails & details_fast)43 std::ostream& operator<<(std::ostream& os,
44 const FastPropertyDetails& details_fast) {
45 const PropertyDetails& details = details_fast.details;
46 os << "(";
47 if (details.location() == kDescriptor) {
48 os << "immutable ";
49 }
50 os << (details.kind() == kData ? "data" : "accessor");
51 os << ": " << details.representation().Mnemonic();
52 if (details.location() == kField) {
53 os << ", field_index: " << details.field_index();
54 }
55 return os << ", p: " << details.pointer()
56 << ", attrs: " << details.attributes() << ")";
57 }
58
59
60 #ifdef OBJECT_PRINT
Print(bool dictionary_mode)61 void PropertyDetails::Print(bool dictionary_mode) {
62 OFStream os(stdout);
63 if (dictionary_mode) {
64 os << *this;
65 } else {
66 os << FastPropertyDetails(*this);
67 }
68 os << "\n" << std::flush;
69 }
70 #endif
71
72
operator <<(std::ostream & os,const Descriptor & d)73 std::ostream& operator<<(std::ostream& os, const Descriptor& d) {
74 Object* value = *d.GetValue();
75 os << "Descriptor " << Brief(*d.GetKey()) << " @ " << Brief(value) << " ";
76 if (value->IsAccessorPair()) {
77 AccessorPair* pair = AccessorPair::cast(value);
78 os << "(get: " << Brief(pair->getter())
79 << ", set: " << Brief(pair->setter()) << ") ";
80 }
81 os << FastPropertyDetails(d.GetDetails());
82 return os;
83 }
84
85 } // namespace internal
86 } // namespace v8
87