LCOV - code coverage report
Current view: top level - src - property.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 40 49 81.6 %
Date: 2019-01-20 Functions: 11 13 84.6 %

          Line data    Source code
       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/field-type.h"
       8             : #include "src/handles-inl.h"
       9             : #include "src/objects-inl.h"
      10             : #include "src/objects/name-inl.h"
      11             : #include "src/objects/smi.h"
      12             : #include "src/ostreams.h"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : 
      17       43492 : std::ostream& operator<<(std::ostream& os,
      18             :                          const PropertyAttributes& attributes) {
      19       43492 :   os << "[";
      20       43492 :   os << (((attributes & READ_ONLY) == 0) ? "W" : "_");    // writable
      21       43492 :   os << (((attributes & DONT_ENUM) == 0) ? "E" : "_");    // enumerable
      22       43492 :   os << (((attributes & DONT_DELETE) == 0) ? "C" : "_");  // configurable
      23       43492 :   os << "]";
      24       43492 :   return os;
      25             : }
      26             : 
      27     4049320 : Descriptor::Descriptor() : details_(Smi::zero()) {}
      28             : 
      29           0 : Descriptor::Descriptor(Handle<Name> key, const MaybeObjectHandle& value,
      30             :                        PropertyKind kind, PropertyAttributes attributes,
      31             :                        PropertyLocation location, PropertyConstness constness,
      32             :                        Representation representation, int field_index)
      33             :     : key_(key),
      34             :       value_(value),
      35             :       details_(kind, attributes, location, constness, representation,
      36    12140987 :                field_index) {
      37             :   DCHECK(key->IsUniqueName());
      38             :   DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
      39           0 : }
      40             : 
      41        1854 : Descriptor::Descriptor(Handle<Name> key, const MaybeObjectHandle& value,
      42             :                        PropertyDetails details)
      43     7871403 :     : key_(key), value_(value), details_(details) {
      44             :   DCHECK(key->IsUniqueName());
      45             :   DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
      46        1854 : }
      47             : 
      48       32509 : Descriptor Descriptor::DataField(Isolate* isolate, Handle<Name> key,
      49             :                                  int field_index, PropertyAttributes attributes,
      50             :                                  Representation representation) {
      51             :   return DataField(key, field_index, attributes, PropertyConstness::kMutable,
      52       65018 :                    representation, MaybeObjectHandle(FieldType::Any(isolate)));
      53             : }
      54             : 
      55     7837040 : Descriptor Descriptor::DataField(Handle<Name> key, int field_index,
      56             :                                  PropertyAttributes attributes,
      57             :                                  PropertyConstness constness,
      58             :                                  Representation representation,
      59             :                                  const MaybeObjectHandle& wrapped_field_type) {
      60             :   DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeak());
      61             :   PropertyDetails details(kData, attributes, kField, constness, representation,
      62             :                           field_index);
      63     7837040 :   return Descriptor(key, wrapped_field_type, details);
      64             : }
      65             : 
      66     1346442 : Descriptor Descriptor::DataConstant(Handle<Name> key, Handle<Object> value,
      67             :                                     PropertyAttributes attributes) {
      68             :   return Descriptor(key, MaybeObjectHandle(value), kData, attributes,
      69             :                     kDescriptor, PropertyConstness::kConst,
      70     2692891 :                     value->OptimalRepresentation(), 0);
      71             : }
      72             : 
      73     9768753 : Descriptor Descriptor::DataConstant(Isolate* isolate, Handle<Name> key,
      74             :                                     int field_index, Handle<Object> value,
      75             :                                     PropertyAttributes attributes) {
      76             :   if (FLAG_track_constant_fields) {
      77             :     MaybeObjectHandle any_type(FieldType::Any(), isolate);
      78             :     return DataField(key, field_index, attributes, PropertyConstness::kConst,
      79             :                      Representation::Tagged(), any_type);
      80             : 
      81             :   } else {
      82             :     return Descriptor(key, MaybeObjectHandle(value), kData, attributes,
      83             :                       kDescriptor, PropertyConstness::kConst,
      84    19537524 :                       value->OptimalRepresentation(), field_index);
      85             :   }
      86             : }
      87             : 
      88     1025767 : Descriptor Descriptor::AccessorConstant(Handle<Name> key,
      89             :                                         Handle<Object> foreign,
      90             :                                         PropertyAttributes attributes) {
      91             :   return Descriptor(key, MaybeObjectHandle(foreign), kAccessor, attributes,
      92             :                     kDescriptor, PropertyConstness::kConst,
      93     1025767 :                     Representation::Tagged(), 0);
      94             : }
      95             : 
      96             : // Outputs PropertyDetails as a dictionary details.
      97           0 : void PropertyDetails::PrintAsSlowTo(std::ostream& os) {
      98           0 :   os << "(";
      99           0 :   if (constness() == PropertyConstness::kConst) os << "const ";
     100           0 :   os << (kind() == kData ? "data" : "accessor");
     101           0 :   os << ", dict_index: " << dictionary_index();
     102           0 :   os << ", attrs: " << attributes() << ")";
     103           0 : }
     104             : 
     105             : // Outputs PropertyDetails as a descriptor array details.
     106       43492 : void PropertyDetails::PrintAsFastTo(std::ostream& os, PrintMode mode) {
     107       43492 :   os << "(";
     108       43492 :   if (constness() == PropertyConstness::kConst) os << "const ";
     109       43492 :   os << (kind() == kData ? "data" : "accessor");
     110       43492 :   if (location() == kField) {
     111       10744 :     os << " field";
     112       10744 :     if (mode & kPrintFieldIndex) {
     113       10744 :       os << " " << field_index();
     114             :     }
     115       10744 :     if (mode & kPrintRepresentation) {
     116       10744 :       os << ":" << representation().Mnemonic();
     117             :     }
     118             :   } else {
     119       32748 :     os << " descriptor";
     120             :   }
     121       43492 :   if (mode & kPrintPointer) {
     122       43492 :     os << ", p: " << pointer();
     123             :   }
     124       43492 :   if (mode & kPrintAttributes) {
     125       43492 :     os << ", attrs: " << attributes();
     126             :   }
     127       43492 :   os << ")";
     128       43492 : }
     129             : 
     130             : #ifdef OBJECT_PRINT
     131             : void PropertyDetails::Print(bool dictionary_mode) {
     132             :   StdoutStream os;
     133             :   if (dictionary_mode) {
     134             :     PrintAsSlowTo(os);
     135             :   } else {
     136             :     PrintAsFastTo(os, PrintMode::kPrintFull);
     137             :   }
     138             :   os << "\n" << std::flush;
     139             : }
     140             : #endif
     141             : 
     142             : }  // namespace internal
     143      183867 : }  // namespace v8

Generated by: LCOV version 1.10