Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/property.h" |
| 6 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 7 | #include "src/field-type.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/handles-inl.h" |
| 9 | #include "src/ostreams.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 14 | std::ostream& operator<<(std::ostream& os, |
| 15 | const PropertyAttributes& attributes) { |
| 16 | os << "["; |
| 17 | os << (((attributes & READ_ONLY) == 0) ? "W" : "_"); // writable |
| 18 | os << (((attributes & DONT_ENUM) == 0) ? "E" : "_"); // enumerable |
| 19 | os << (((attributes & DONT_DELETE) == 0) ? "C" : "_"); // configurable |
| 20 | os << "]"; |
| 21 | return os; |
| 22 | } |
| 23 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 24 | DataDescriptor::DataDescriptor(Handle<Name> key, int field_index, |
| 25 | PropertyAttributes attributes, |
| 26 | Representation representation) |
| 27 | : Descriptor(key, FieldType::Any(key->GetIsolate()), attributes, DATA, |
| 28 | representation, field_index) {} |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 29 | |
| 30 | struct FastPropertyDetails { |
| 31 | explicit FastPropertyDetails(const PropertyDetails& v) : details(v) {} |
| 32 | const PropertyDetails details; |
| 33 | }; |
| 34 | |
| 35 | |
| 36 | // Outputs PropertyDetails as a dictionary details. |
| 37 | std::ostream& operator<<(std::ostream& os, const PropertyDetails& details) { |
| 38 | os << "("; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 39 | if (details.location() == kDescriptor) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 40 | os << "immutable "; |
| 41 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 42 | os << (details.kind() == kData ? "data" : "accessor"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 43 | return os << ", dictionary_index: " << details.dictionary_index() |
| 44 | << ", attrs: " << details.attributes() << ")"; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | // Outputs PropertyDetails as a descriptor array details. |
| 49 | std::ostream& operator<<(std::ostream& os, |
| 50 | const FastPropertyDetails& details_fast) { |
| 51 | const PropertyDetails& details = details_fast.details; |
| 52 | os << "("; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | if (details.location() == kDescriptor) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 54 | os << "immutable "; |
| 55 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 56 | os << (details.kind() == kData ? "data" : "accessor"); |
| 57 | os << ": " << details.representation().Mnemonic(); |
| 58 | if (details.location() == kField) { |
| 59 | os << ", field_index: " << details.field_index(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 60 | } |
| 61 | return os << ", p: " << details.pointer() |
| 62 | << ", attrs: " << details.attributes() << ")"; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | #ifdef OBJECT_PRINT |
| 67 | void PropertyDetails::Print(bool dictionary_mode) { |
| 68 | OFStream os(stdout); |
| 69 | if (dictionary_mode) { |
| 70 | os << *this; |
| 71 | } else { |
| 72 | os << FastPropertyDetails(*this); |
| 73 | } |
| 74 | os << "\n" << std::flush; |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | |
| 79 | std::ostream& operator<<(std::ostream& os, const Descriptor& d) { |
| 80 | Object* value = *d.GetValue(); |
| 81 | os << "Descriptor " << Brief(*d.GetKey()) << " @ " << Brief(value) << " "; |
| 82 | if (value->IsAccessorPair()) { |
| 83 | AccessorPair* pair = AccessorPair::cast(value); |
| 84 | os << "(get: " << Brief(pair->getter()) |
| 85 | << ", set: " << Brief(pair->setter()) << ") "; |
| 86 | } |
| 87 | os << FastPropertyDetails(d.GetDetails()); |
| 88 | return os; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 91 | } // namespace internal |
| 92 | } // namespace v8 |