LCOV - code coverage report
Current view: top level - src/objects - name-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 42 42 100.0 %
Date: 2019-01-20 Functions: 13 13 100.0 %

          Line data    Source code
       1             : // Copyright 2017 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_OBJECTS_NAME_INL_H_
       6             : #define V8_OBJECTS_NAME_INL_H_
       7             : 
       8             : #include "src/objects/name.h"
       9             : 
      10             : #include "src/heap/heap-inl.h"
      11             : #include "src/heap/heap-write-barrier.h"
      12             : #include "src/objects/map-inl.h"
      13             : 
      14             : // Has to be the last include (doesn't have include guards):
      15             : #include "src/objects/object-macros.h"
      16             : 
      17             : namespace v8 {
      18             : namespace internal {
      19             : 
      20  2449188112 : OBJECT_CONSTRUCTORS_IMPL(Name, HeapObject)
      21  1516547596 : OBJECT_CONSTRUCTORS_IMPL(Symbol, Name)
      22             : 
      23  1224595102 : CAST_ACCESSOR(Name)
      24   758276199 : CAST_ACCESSOR(Symbol)
      25             : 
      26      218497 : ACCESSORS(Symbol, name, Object, kNameOffset)
      27    20454912 : INT_ACCESSORS(Symbol, flags, kFlagsOffset)
      28    18714383 : BIT_FIELD_ACCESSORS(Symbol, flags, is_private, Symbol::IsPrivateBit)
      29         393 : BIT_FIELD_ACCESSORS(Symbol, flags, is_well_known_symbol,
      30             :                     Symbol::IsWellKnownSymbolBit)
      31         183 : BIT_FIELD_ACCESSORS(Symbol, flags, is_public, Symbol::IsPublicBit)
      32     1592932 : BIT_FIELD_ACCESSORS(Symbol, flags, is_interesting_symbol,
      33             :                     Symbol::IsInterestingSymbolBit)
      34             : 
      35             : bool Symbol::is_private_name() const {
      36      128079 :   bool value = Symbol::IsPrivateNameBit::decode(flags());
      37             :   DCHECK_IMPLIES(value, is_private());
      38             :   return value;
      39             : }
      40             : 
      41             : void Symbol::set_is_private_name() {
      42             :   // TODO(gsathya): Re-order the bits to have these next to each other
      43             :   // and just do the bit shifts once.
      44        1680 :   set_flags(Symbol::IsPrivateBit::update(flags(), true));
      45         840 :   set_flags(Symbol::IsPrivateNameBit::update(flags(), true));
      46             : }
      47             : 
      48    99939368 : bool Name::IsUniqueName() const {
      49             :   uint32_t type = map()->instance_type();
      50    99939368 :   return (type & (kIsNotStringMask | kIsNotInternalizedMask)) !=
      51    99939368 :          (kStringTag | kNotInternalizedTag);
      52             : }
      53             : 
      54             : uint32_t Name::hash_field() {
      55  1720816199 :   return READ_UINT32_FIELD(this, kHashFieldOffset);
      56             : }
      57             : 
      58             : void Name::set_hash_field(uint32_t value) {
      59   248415889 :   WRITE_UINT32_FIELD(this, kHashFieldOffset, value);
      60             : }
      61             : 
      62       70505 : bool Name::Equals(Name other) {
      63       70505 :   if (other == *this) return true;
      64      157148 :   if ((this->IsInternalizedString() && other->IsInternalizedString()) ||
      65       53198 :       this->IsSymbol() || other->IsSymbol()) {
      66             :     return false;
      67             :   }
      68           9 :   return String::cast(*this)->SlowEquals(String::cast(other));
      69             : }
      70             : 
      71       92084 : bool Name::Equals(Isolate* isolate, Handle<Name> one, Handle<Name> two) {
      72       92084 :   if (one.is_identical_to(two)) return true;
      73       82651 :   if ((one->IsInternalizedString() && two->IsInternalizedString()) ||
      74       22387 :       one->IsSymbol() || two->IsSymbol()) {
      75             :     return false;
      76             :   }
      77             :   return String::SlowEquals(isolate, Handle<String>::cast(one),
      78          18 :                             Handle<String>::cast(two));
      79             : }
      80             : 
      81             : bool Name::IsHashFieldComputed(uint32_t field) {
      82  1430450786 :   return (field & kHashNotComputedMask) == 0;
      83             : }
      84             : 
      85             : bool Name::HasHashCode() { return IsHashFieldComputed(hash_field()); }
      86             : 
      87  1372156433 : uint32_t Name::Hash() {
      88             :   // Fast case: has hash code already been computed?
      89             :   uint32_t field = hash_field();
      90  1372156433 :   if (IsHashFieldComputed(field)) return field >> kHashShift;
      91             :   // Slow case: compute hash code and set it. Has to be a string.
      92             :   // Also the string must be writable, because read-only strings will have their
      93             :   // hash values precomputed.
      94             :   return String::cast(*this)->ComputeAndSetHash(
      95    71369413 :       Heap::FromWritableHeapObject(*this)->isolate());
      96             : }
      97             : 
      98    19449041 : bool Name::IsInterestingSymbol() const {
      99    40490909 :   return IsSymbol() && Symbol::cast(*this)->is_interesting_symbol();
     100             : }
     101             : 
     102   159345545 : bool Name::IsPrivate() {
     103   337284319 :   return this->IsSymbol() && Symbol::cast(*this)->is_private();
     104             : }
     105             : 
     106       17882 : bool Name::IsPrivateName() {
     107             :   bool is_private_name =
     108       53223 :       this->IsSymbol() && Symbol::cast(*this)->is_private_name();
     109             :   DCHECK_IMPLIES(is_private_name, IsPrivate());
     110       17882 :   return is_private_name;
     111             : }
     112             : 
     113    27624817 : bool Name::AsArrayIndex(uint32_t* index) {
     114    82002239 :   return IsString() && String::cast(*this)->AsArrayIndex(index);
     115             : }
     116             : 
     117             : // static
     118             : bool Name::ContainsCachedArrayIndex(uint32_t hash) {
     119     1955588 :   return (hash & Name::kDoesNotContainCachedArrayIndexMask) == 0;
     120             : }
     121             : 
     122             : }  // namespace internal
     123             : }  // namespace v8
     124             : 
     125             : #include "src/objects/object-macros-undef.h"
     126             : 
     127             : #endif  // V8_OBJECTS_NAME_INL_H_

Generated by: LCOV version 1.10