LCOV - code coverage report
Current view: top level - src - property-descriptor.h (source / functions) Hit Total Coverage
Test: app.info Lines: 37 40 92.5 %
Date: 2019-01-20 Functions: 5 11 45.5 %

          Line data    Source code
       1             : // Copyright 2015 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             : #ifndef V8_PROPERTY_DESCRIPTOR_H_
       6             : #define V8_PROPERTY_DESCRIPTOR_H_
       7             : 
       8             : 
       9             : #include "src/handles.h"
      10             : #include "src/property-details.h"
      11             : 
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16             : class Isolate;
      17             : class Object;
      18             : class PropertyDescriptorObject;
      19             : 
      20             : class PropertyDescriptor {
      21             :  public:
      22       75388 :   PropertyDescriptor()
      23             :       : enumerable_(false),
      24             :         has_enumerable_(false),
      25             :         configurable_(false),
      26             :         has_configurable_(false),
      27             :         writable_(false),
      28     4261644 :         has_writable_(false) {}
      29             : 
      30             :   // ES6 6.2.4.1
      31             :   static bool IsAccessorDescriptor(PropertyDescriptor* desc) {
      32     1381444 :     return desc->has_get() || desc->has_set();
      33             :   }
      34             : 
      35             :   // ES6 6.2.4.2
      36             :   static bool IsDataDescriptor(PropertyDescriptor* desc) {
      37     1348025 :     return desc->has_value() || desc->has_writable();
      38             :   }
      39             : 
      40             :   // ES6 6.2.4.3
      41             :   static bool IsGenericDescriptor(PropertyDescriptor* desc) {
      42      941079 :     return !IsAccessorDescriptor(desc) && !IsDataDescriptor(desc);
      43             :   }
      44             : 
      45             :   // ES6 6.2.4.4
      46             :   Handle<Object> ToObject(Isolate* isolate);
      47             : 
      48             :   Handle<PropertyDescriptorObject> ToPropertyDescriptorObject(Isolate* isolate);
      49             : 
      50             :   // ES6 6.2.4.5
      51             :   static bool ToPropertyDescriptor(Isolate* isolate, Handle<Object> obj,
      52             :                                    PropertyDescriptor* desc);
      53             : 
      54             :   // ES6 6.2.4.6
      55             :   static void CompletePropertyDescriptor(Isolate* isolate,
      56             :                                          PropertyDescriptor* desc);
      57             : 
      58      569178 :   bool is_empty() const {
      59     1145363 :     return !has_enumerable() && !has_configurable() && !has_writable() &&
      60     1332762 :            !has_value() && !has_get() && !has_set();
      61             :   }
      62             : 
      63       18322 :   bool IsRegularAccessorProperty() const {
      64       20126 :     return has_configurable() && has_enumerable() && !has_value() &&
      65       18494 :            !has_writable() && has_get() && has_set();
      66             :   }
      67             : 
      68       18236 :   bool IsRegularDataProperty() const {
      69       29649 :     return has_configurable() && has_enumerable() && has_value() &&
      70       37726 :            has_writable() && !has_get() && !has_set();
      71             :   }
      72             : 
      73     3678108 :   bool enumerable() const { return enumerable_; }
      74             :   void set_enumerable(bool enumerable) {
      75     3712438 :     enumerable_ = enumerable;
      76     3715390 :     has_enumerable_ = true;
      77             :   }
      78     4687087 :   bool has_enumerable() const { return has_enumerable_; }
      79             : 
      80     3749929 :   bool configurable() const { return configurable_; }
      81             :   void set_configurable(bool configurable) {
      82     3730100 :     configurable_ = configurable;
      83     3734098 :     has_configurable_ = true;
      84             :   }
      85     4401273 :   bool has_configurable() const { return has_configurable_; }
      86             : 
      87           0 :   Handle<Object> value() const { return value_; }
      88     3609872 :   void set_value(Handle<Object> value) { value_ = value; }
      89       74327 :   bool has_value() const { return !value_.is_null(); }
      90             : 
      91     3367390 :   bool writable() const { return writable_; }
      92             :   void set_writable(bool writable) {
      93     3503806 :     writable_ = writable;
      94     3507272 :     has_writable_ = true;
      95             :   }
      96     4467073 :   bool has_writable() const { return has_writable_; }
      97             : 
      98           0 :   Handle<Object> get() const { return get_; }
      99      222827 :   void set_get(Handle<Object> get) { get_ = get; }
     100       74327 :   bool has_get() const { return !get_.is_null(); }
     101             : 
     102           0 :   Handle<Object> set() const { return set_; }
     103       79408 :   void set_set(Handle<Object> set) { set_ = set; }
     104       74327 :   bool has_set() const { return !set_.is_null(); }
     105             : 
     106             :   Handle<Object> name() const { return name_; }
     107        3950 :   void set_name(Handle<Object> name) { name_ = name; }
     108             : 
     109      380615 :   PropertyAttributes ToAttributes() {
     110             :     return static_cast<PropertyAttributes>(
     111     1522461 :         (has_enumerable() && !enumerable() ? DONT_ENUM : NONE) |
     112     1141841 :         (has_configurable() && !configurable() ? DONT_DELETE : NONE) |
     113      693495 :         (has_writable() && !writable() ? READ_ONLY : NONE));
     114             :   }
     115             : 
     116             :  private:
     117             :   bool enumerable_ : 1;
     118             :   bool has_enumerable_ : 1;
     119             :   bool configurable_ : 1;
     120             :   bool has_configurable_ : 1;
     121             :   bool writable_ : 1;
     122             :   bool has_writable_ : 1;
     123             :   Handle<Object> value_;
     124             :   Handle<Object> get_;
     125             :   Handle<Object> set_;
     126             :   Handle<Object> name_;
     127             : 
     128             :   // Some compilers (Xcode 5.1, ARM GCC 4.9) insist on having a copy
     129             :   // constructor for std::vector<PropertyDescriptor>, so we can't
     130             :   // DISALLOW_COPY_AND_ASSIGN(PropertyDescriptor); here.
     131             : };
     132             : 
     133             : }  // namespace internal
     134             : }  // namespace v8
     135             : 
     136             : #endif  // V8_PROPERTY_DESCRIPTOR_H_

Generated by: LCOV version 1.10