LCOV - code coverage report
Current view: top level - src/heap - factory-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 47 47 100.0 %
Date: 2019-03-21 Functions: 81 84 96.4 %

          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_HEAP_FACTORY_INL_H_
       6             : #define V8_HEAP_FACTORY_INL_H_
       7             : 
       8             : #include "src/heap/factory.h"
       9             : 
      10             : // Clients of this interface shouldn't depend on lots of heap internals.
      11             : // Do not include anything from src/heap here!
      12             : #include "src/handles-inl.h"
      13             : #include "src/isolate-inl.h"
      14             : #include "src/objects-inl.h"
      15             : #include "src/objects/feedback-cell.h"
      16             : #include "src/objects/heap-number-inl.h"
      17             : #include "src/objects/oddball.h"
      18             : #include "src/objects/string-inl.h"
      19             : #include "src/string-hasher.h"
      20             : 
      21             : namespace v8 {
      22             : namespace internal {
      23             : 
      24             : #define ROOT_ACCESSOR(Type, name, CamelName)                                 \
      25             :   Handle<Type> Factory::name() {                                             \
      26             :     return Handle<Type>(&isolate()->roots_table()[RootIndex::k##CamelName]); \
      27             :   }
      28       40208 : ROOT_LIST(ROOT_ACCESSOR)
      29             : #undef ROOT_ACCESSOR
      30             : 
      31    28984250 : Handle<String> Factory::InternalizeString(Handle<String> string) {
      32    29434147 :   if (string->IsInternalizedString()) return string;
      33     3944929 :   return StringTable::LookupString(isolate(), string);
      34             : }
      35             : 
      36    90175743 : Handle<Name> Factory::InternalizeName(Handle<Name> name) {
      37    90175743 :   if (name->IsUniqueName()) return name;
      38     7508940 :   return StringTable::LookupString(isolate(), Handle<String>::cast(name));
      39             : }
      40             : 
      41     2717137 : Handle<String> Factory::NewSubString(Handle<String> str, int begin, int end) {
      42     3021692 :   if (begin == 0 && end == str->length()) return str;
      43     2595972 :   return NewProperSubString(str, begin, end);
      44             : }
      45             : 
      46       97121 : Handle<Object> Factory::NewNumberFromSize(size_t value,
      47             :                                           AllocationType allocation) {
      48             :   // We can't use Smi::IsValid() here because that operates on a signed
      49             :   // intptr_t, and casting from size_t could create a bogus sign bit.
      50       97121 :   if (value <= static_cast<size_t>(Smi::kMaxValue)) {
      51             :     return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
      52       97069 :                           isolate());
      53             :   }
      54          52 :   return NewNumber(static_cast<double>(value), allocation);
      55             : }
      56             : 
      57       20357 : Handle<Object> Factory::NewNumberFromInt64(int64_t value,
      58             :                                            AllocationType allocation) {
      59       40597 :   if (value <= std::numeric_limits<int32_t>::max() &&
      60       40597 :       value >= std::numeric_limits<int32_t>::min() &&
      61       20240 :       Smi::IsValid(static_cast<int32_t>(value))) {
      62       40462 :     return Handle<Object>(Smi::FromInt(static_cast<int32_t>(value)), isolate());
      63             :   }
      64         126 :   return NewNumber(static_cast<double>(value), allocation);
      65             : }
      66             : 
      67     6120713 : Handle<HeapNumber> Factory::NewHeapNumber(double value,
      68             :                                           AllocationType allocation) {
      69     6120713 :   Handle<HeapNumber> heap_number = NewHeapNumber(allocation);
      70           4 :   heap_number->set_value(value);
      71     6120713 :   return heap_number;
      72             : }
      73             : 
      74          37 : Handle<MutableHeapNumber> Factory::NewMutableHeapNumber(
      75             :     double value, AllocationType allocation) {
      76          37 :   Handle<MutableHeapNumber> number = NewMutableHeapNumber(allocation);
      77             :   number->set_value(value);
      78          37 :   return number;
      79             : }
      80             : 
      81        2513 : Handle<HeapNumber> Factory::NewHeapNumberFromBits(uint64_t bits,
      82             :                                                   AllocationType allocation) {
      83        2513 :   Handle<HeapNumber> heap_number = NewHeapNumber(allocation);
      84          56 :   heap_number->set_value_as_bits(bits);
      85        2513 :   return heap_number;
      86             : }
      87             : 
      88       98509 : Handle<MutableHeapNumber> Factory::NewMutableHeapNumberFromBits(
      89             :     uint64_t bits, AllocationType allocation) {
      90       98509 :   Handle<MutableHeapNumber> number = NewMutableHeapNumber(allocation);
      91             :   number->set_value_as_bits(bits);
      92       98509 :   return number;
      93             : }
      94             : 
      95             : Handle<MutableHeapNumber> Factory::NewMutableHeapNumberWithHoleNaN(
      96             :     AllocationType allocation) {
      97       49415 :   return NewMutableHeapNumberFromBits(kHoleNanInt64, allocation);
      98             : }
      99             : 
     100     1898515 : Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
     101             :                                                 ElementsKind elements_kind,
     102             :                                                 AllocationType allocation) {
     103             :   return NewJSArrayWithElements(elements, elements_kind, elements->length(),
     104     1898515 :                                 allocation);
     105             : }
     106             : 
     107        5244 : Handle<Object> Factory::NewURIError() {
     108             :   return NewError(isolate()->uri_error_function(),
     109        5244 :                   MessageTemplate::kURIMalformed);
     110             : }
     111             : 
     112     5198337 : Handle<String> Factory::Uint32ToString(uint32_t value, bool check_cache) {
     113             :   Handle<String> result;
     114     5198337 :   int32_t int32v = static_cast<int32_t>(value);
     115    10395682 :   if (int32v >= 0 && Smi::IsValid(int32v)) {
     116    10210442 :     result = NumberToString(Smi::FromInt(int32v), check_cache);
     117             :   } else {
     118       93116 :     result = NumberToString(NewNumberFromUint(value), check_cache);
     119             :   }
     120             : 
     121    10396674 :   if (result->length() <= String::kMaxArrayIndexSize &&
     122             :       result->hash_field() == String::kEmptyHashField) {
     123      470400 :     uint32_t field = StringHasher::MakeArrayIndexHash(value, result->length());
     124             :     result->set_hash_field(field);
     125             :   }
     126     5198337 :   return result;
     127             : }
     128             : 
     129             : }  // namespace internal
     130             : }  // namespace v8
     131             : 
     132             : #endif  // V8_HEAP_FACTORY_INL_H_

Generated by: LCOV version 1.10