LCOV - code coverage report
Current view: top level - src/objects - name-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 45 45 100.0 %
Date: 2019-02-19 Functions: 19 19 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-write-barrier-inl.h"
      11             : #include "src/objects/map-inl.h"
      12             : 
      13             : // Has to be the last include (doesn't have include guards):
      14             : #include "src/objects/object-macros.h"
      15             : 
      16             : namespace v8 {
      17             : namespace internal {
      18             : 
      19  2652076147 : OBJECT_CONSTRUCTORS_IMPL(Name, HeapObject)
      20    41750290 : OBJECT_CONSTRUCTORS_IMPL(Symbol, Name)
      21             : 
      22  1326038931 : CAST_ACCESSOR(Name)
      23    20875147 : CAST_ACCESSOR(Symbol)
      24             : 
      25      165215 : ACCESSORS(Symbol, name, Object, kNameOffset)
      26    19782727 : INT_ACCESSORS(Symbol, flags, kFlagsOffset)
      27    18315327 : BIT_FIELD_ACCESSORS(Symbol, flags, is_private, Symbol::IsPrivateBit)
      28         225 : BIT_FIELD_ACCESSORS(Symbol, flags, is_well_known_symbol,
      29             :                     Symbol::IsWellKnownSymbolBit)
      30         183 : BIT_FIELD_ACCESSORS(Symbol, flags, is_public, Symbol::IsPublicBit)
      31     1321789 : BIT_FIELD_ACCESSORS(Symbol, flags, is_interesting_symbol,
      32             :                     Symbol::IsInterestingSymbolBit)
      33             : 
      34             : bool Symbol::is_private_name() const {
      35      126297 :   bool value = Symbol::IsPrivateNameBit::decode(flags());
      36             :   DCHECK_IMPLIES(value, is_private());
      37             :   return value;
      38             : }
      39             : 
      40             : void Symbol::set_is_private_name() {
      41             :   // TODO(gsathya): Re-order the bits to have these next to each other
      42             :   // and just do the bit shifts once.
      43        1738 :   set_flags(Symbol::IsPrivateBit::update(flags(), true));
      44         869 :   set_flags(Symbol::IsPrivateNameBit::update(flags(), true));
      45             : }
      46             : 
      47    96845786 : bool Name::IsUniqueName() const {
      48             :   uint32_t type = map()->instance_type();
      49    96845786 :   return (type & (kIsNotStringMask | kIsNotInternalizedMask)) !=
      50    96845786 :          (kStringTag | kNotInternalizedTag);
      51             : }
      52             : 
      53   497868144 : uint32_t Name::hash_field() {
      54  1972689937 :   return READ_UINT32_FIELD(*this, kHashFieldOffset);
      55             : }
      56             : 
      57             : void Name::set_hash_field(uint32_t value) {
      58   243917003 :   WRITE_UINT32_FIELD(*this, kHashFieldOffset, value);
      59             : }
      60             : 
      61       62940 : bool Name::Equals(Name other) {
      62       62940 :   if (other == *this) return true;
      63      155445 :   if ((this->IsInternalizedString() && other->IsInternalizedString()) ||
      64       52628 :       this->IsSymbol() || other->IsSymbol()) {
      65             :     return false;
      66             :   }
      67           9 :   return String::cast(*this)->SlowEquals(String::cast(other));
      68             : }
      69             : 
      70       91275 : bool Name::Equals(Isolate* isolate, Handle<Name> one, Handle<Name> two) {
      71       91275 :   if (one.is_identical_to(two)) return true;
      72       82592 :   if ((one->IsInternalizedString() && two->IsInternalizedString()) ||
      73       22680 :       one->IsSymbol() || two->IsSymbol()) {
      74             :     return false;
      75             :   }
      76             :   return String::SlowEquals(isolate, Handle<String>::cast(one),
      77          18 :                             Handle<String>::cast(two));
      78             : }
      79             : 
      80   497864972 : bool Name::IsHashFieldComputed(uint32_t field) {
      81  1671605088 :   return (field & kHashNotComputedMask) == 0;
      82             : }
      83             : 
      84             : bool Name::HasHashCode() { return IsHashFieldComputed(hash_field()); }
      85             : 
      86  1613426257 : uint32_t Name::Hash() {
      87             :   // Fast case: has hash code already been computed?
      88   497866621 :   uint32_t field = hash_field();
      89  1613423672 :   if (IsHashFieldComputed(field)) return field >> kHashShift;
      90             :   // Slow case: compute hash code and set it. Has to be a string.
      91             :   // Also the string must be writable, because read-only strings will have their
      92             :   // hash values precomputed.
      93             :   return String::cast(*this)->ComputeAndSetHash(
      94   139569888 :       Isolate::FromHeap(GetHeapFromWritableObject(*this)));
      95             : }
      96             : 
      97    18127092 : bool Name::IsInterestingSymbol() const {
      98    37575917 :   return IsSymbol() && Symbol::cast(*this)->is_interesting_symbol();
      99             : }
     100             : 
     101   154672663 : bool Name::IsPrivate() {
     102   327539815 :   return this->IsSymbol() && Symbol::cast(*this)->is_private();
     103             : }
     104             : 
     105       18064 : bool Name::IsPrivateName() {
     106             :   bool is_private_name =
     107       53679 :       this->IsSymbol() && Symbol::cast(*this)->is_private_name();
     108             :   DCHECK_IMPLIES(is_private_name, IsPrivate());
     109       18064 :   return is_private_name;
     110             : }
     111             : 
     112    27509359 : bool Name::AsArrayIndex(uint32_t* index) {
     113    81650282 :   return IsString() && String::cast(*this)->AsArrayIndex(index);
     114             : }
     115             : 
     116             : // static
     117             : bool Name::ContainsCachedArrayIndex(uint32_t hash) {
     118     1958489 :   return (hash & Name::kDoesNotContainCachedArrayIndexMask) == 0;
     119             : }
     120             : 
     121             : }  // namespace internal
     122             : }  // namespace v8
     123             : 
     124             : #include "src/objects/object-macros-undef.h"
     125             : 
     126             : #endif  // V8_OBJECTS_NAME_INL_H_

Generated by: LCOV version 1.10