property.cc 2.79 KB
Newer Older
1 2 3
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// 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/ostreams.h"
10

11 12
namespace v8 {
namespace internal {
13

14 15 16 17 18 19 20 21 22 23
std::ostream& operator<<(std::ostream& os,
                         const PropertyAttributes& attributes) {
  os << "[";
  os << (((attributes & READ_ONLY) == 0) ? "W" : "_");    // writable
  os << (((attributes & DONT_ENUM) == 0) ? "E" : "_");    // enumerable
  os << (((attributes & DONT_DELETE) == 0) ? "C" : "_");  // configurable
  os << "]";
  return os;
}

24 25 26 27 28
DataDescriptor::DataDescriptor(Handle<Name> key, int field_index,
                               PropertyAttributes attributes,
                               Representation representation)
    : Descriptor(key, FieldType::Any(key->GetIsolate()), attributes, DATA,
                 representation, field_index) {}
29

30 31 32 33 34 35 36
struct FastPropertyDetails {
  explicit FastPropertyDetails(const PropertyDetails& v) : details(v) {}
  const PropertyDetails details;
};


// Outputs PropertyDetails as a dictionary details.
37 38
std::ostream& operator<<(std::ostream& os, const PropertyDetails& details) {
  os << "(";
39
  if (details.location() == kDescriptor) {
40
    os << "immutable ";
41
  }
42
  os << (details.kind() == kData ? "data" : "accessor");
43
  return os << ", dictionary_index: " << details.dictionary_index()
44 45 46 47 48 49 50 51 52
            << ", attrs: " << details.attributes() << ")";
}


// Outputs PropertyDetails as a descriptor array details.
std::ostream& operator<<(std::ostream& os,
                         const FastPropertyDetails& details_fast) {
  const PropertyDetails& details = details_fast.details;
  os << "(";
53
  if (details.location() == kDescriptor) {
54
    os << "immutable ";
55
  }
56
  os << (details.kind() == kData ? "data" : "accessor");
57
  os << ": " << details.representation().Mnemonic();
58
  if (details.location() == kField) {
59
    os << ", field_index: " << details.field_index();
60 61 62
  }
  return os << ", p: " << details.pointer()
            << ", attrs: " << details.attributes() << ")";
63 64 65 66 67 68 69 70 71 72 73 74
}


#ifdef OBJECT_PRINT
void PropertyDetails::Print(bool dictionary_mode) {
  OFStream os(stdout);
  if (dictionary_mode) {
    os << *this;
  } else {
    os << FastPropertyDetails(*this);
  }
  os << "\n" << std::flush;
75
}
76
#endif
77 78


79
std::ostream& operator<<(std::ostream& os, const Descriptor& d) {
80 81 82 83 84 85 86 87 88
  Object* value = *d.GetValue();
  os << "Descriptor " << Brief(*d.GetKey()) << " @ " << Brief(value) << " ";
  if (value->IsAccessorPair()) {
    AccessorPair* pair = AccessorPair::cast(value);
    os << "(get: " << Brief(pair->getter())
       << ", set: " << Brief(pair->setter()) << ") ";
  }
  os << FastPropertyDetails(d.GetDetails());
  return os;
89 90
}

91 92
}  // namespace internal
}  // namespace v8