property.cc 3.37 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/objects-inl.h"
10
#include "src/ostreams.h"
11

12 13
namespace v8 {
namespace internal {
14

15 16 17 18 19 20 21 22 23 24
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;
}

25 26 27
Descriptor Descriptor::DataField(Handle<Name> key, int field_index,
                                 PropertyAttributes attributes,
                                 Representation representation) {
28 29 30 31 32 33 34 35 36 37 38 39 40
  return DataField(key, field_index, attributes, kMutable, representation,
                   FieldType::Any(key->GetIsolate()));
}

Descriptor Descriptor::DataField(Handle<Name> key, int field_index,
                                 PropertyAttributes attributes,
                                 PropertyConstness constness,
                                 Representation representation,
                                 Handle<Object> wrapped_field_type) {
  DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell());
  PropertyDetails details(kData, attributes, kField, constness, representation,
                          field_index);
  return Descriptor(key, wrapped_field_type, details);
41
}
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56
Descriptor Descriptor::DataConstant(Handle<Name> key, int field_index,
                                    Handle<Object> value,
                                    PropertyAttributes attributes) {
  if (FLAG_track_constant_fields) {
    Handle<Object> any_type(FieldType::Any(), key->GetIsolate());
    return DataField(key, field_index, attributes, kConst,
                     Representation::Tagged(), any_type);

  } else {
    return Descriptor(key, value, kData, attributes, kDescriptor, kConst,
                      value->OptimalRepresentation(), field_index);
  }
}

57
// Outputs PropertyDetails as a dictionary details.
58
void PropertyDetails::PrintAsSlowTo(std::ostream& os) {
59
  os << "(";
60
  if (constness() == kConst) os << "const ";
61
  os << (kind() == kData ? "data" : "accessor");
62
  os << ", dict_index: " << dictionary_index();
63
  os << ", attrs: " << attributes() << ")";
64 65 66
}

// Outputs PropertyDetails as a descriptor array details.
67
void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) {
68
  os << "(";
69
  if (constness() == kConst) os << "const ";
70 71 72 73 74 75 76 77 78 79 80 81 82 83
  os << (kind() == kData ? "data" : "accessor");
  if (location() == kField) {
    os << " field";
    if (mode & kPrintFieldIndex) {
      os << " " << field_index();
    }
    if (mode & kPrintRepresentation) {
      os << ":" << representation().Mnemonic();
    }
  } else {
    os << " descriptor";
  }
  if (mode & kPrintPointer) {
    os << ", p: " << pointer();
84
  }
85 86
  if (mode & kPrintAttributes) {
    os << ", attrs: " << attributes();
87
  }
88
  os << ")";
89 90 91 92 93 94
}

#ifdef OBJECT_PRINT
void PropertyDetails::Print(bool dictionary_mode) {
  OFStream os(stdout);
  if (dictionary_mode) {
95
    PrintAsSlowTo(os);
96
  } else {
97
    PrintAsFastTo(os, PrintMode::kPrintFull);
98 99
  }
  os << "\n" << std::flush;
100
}
101
#endif
102

103 104
}  // namespace internal
}  // namespace v8