LCOV - code coverage report
Current view: top level - src - factory-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 38 38 100.0 %
Date: 2017-10-20 Functions: 24 25 96.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_FACTORY_INL_H_
       6             : #define V8_FACTORY_INL_H_
       7             : 
       8             : #include "src/factory.h"
       9             : 
      10             : #include "src/handles-inl.h"
      11             : #include "src/objects-inl.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16             : #define ROOT_ACCESSOR(type, name, camel_name)                         \
      17             :   Handle<type> Factory::name() {                                      \
      18             :     return Handle<type>(bit_cast<type**>(                             \
      19             :         &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
      20             :   }
      21   605098582 : ROOT_LIST(ROOT_ACCESSOR)
      22             : #undef ROOT_ACCESSOR
      23             : 
      24             : #define STRUCT_MAP_ACCESSOR(NAME, Name, name)                      \
      25             :   Handle<Map> Factory::name##_map() {                              \
      26             :     return Handle<Map>(bit_cast<Map**>(                            \
      27             :         &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \
      28             :   }
      29      264455 : STRUCT_LIST(STRUCT_MAP_ACCESSOR)
      30             : #undef STRUCT_MAP_ACCESSOR
      31             : 
      32             : #define STRING_ACCESSOR(name, str)                              \
      33             :   Handle<String> Factory::name() {                              \
      34             :     return Handle<String>(bit_cast<String**>(                   \
      35             :         &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
      36             :   }
      37    49368607 : INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
      38             : #undef STRING_ACCESSOR
      39             : 
      40             : #define SYMBOL_ACCESSOR(name)                                   \
      41             :   Handle<Symbol> Factory::name() {                              \
      42             :     return Handle<Symbol>(bit_cast<Symbol**>(                   \
      43             :         &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
      44             :   }
      45    46604123 : PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
      46             : #undef SYMBOL_ACCESSOR
      47             : 
      48             : #define SYMBOL_ACCESSOR(name, description)                      \
      49             :   Handle<Symbol> Factory::name() {                              \
      50             :     return Handle<Symbol>(bit_cast<Symbol**>(                   \
      51             :         &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
      52             :   }
      53     7370378 : PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
      54     2212298 : WELL_KNOWN_SYMBOL_LIST(SYMBOL_ACCESSOR)
      55             : #undef SYMBOL_ACCESSOR
      56             : 
      57    20361905 : Handle<String> Factory::InternalizeString(Handle<String> string) {
      58    20361905 :   if (string->IsInternalizedString()) return string;
      59      210238 :   return StringTable::LookupString(isolate(), string);
      60             : }
      61             : 
      62   185161523 : Handle<Name> Factory::InternalizeName(Handle<Name> name) {
      63   185161523 :   if (name->IsUniqueName()) return name;
      64    12507649 :   return StringTable::LookupString(isolate(), Handle<String>::cast(name));
      65             : }
      66             : 
      67     3318669 : Handle<String> Factory::NewSubString(Handle<String> str, int begin, int end) {
      68     3640090 :   if (begin == 0 && end == str->length()) return str;
      69     3196051 :   return NewProperSubString(str, begin, end);
      70             : }
      71             : 
      72      263510 : Handle<Object> Factory::NewNumberFromSize(size_t value,
      73             :                                           PretenureFlag pretenure) {
      74             :   // We can't use Smi::IsValid() here because that operates on a signed
      75             :   // intptr_t, and casting from size_t could create a bogus sign bit.
      76      263510 :   if (value <= static_cast<size_t>(Smi::kMaxValue)) {
      77      263437 :     return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
      78      263437 :                           isolate());
      79             :   }
      80          73 :   return NewNumber(static_cast<double>(value), pretenure);
      81             : }
      82             : 
      83       29913 : Handle<Object> Factory::NewNumberFromInt64(int64_t value,
      84             :                                            PretenureFlag pretenure) {
      85       29859 :   if (value <= std::numeric_limits<int32_t>::max() &&
      86       29913 :       value >= std::numeric_limits<int32_t>::min() &&
      87             :       Smi::IsValid(static_cast<int32_t>(value))) {
      88       59718 :     return Handle<Object>(Smi::FromInt(static_cast<int32_t>(value)), isolate());
      89             :   }
      90          54 :   return NewNumber(static_cast<double>(value), pretenure);
      91             : }
      92             : 
      93          28 : Handle<HeapNumber> Factory::NewHeapNumber(double value, MutableMode mode,
      94             :                                           PretenureFlag pretenure) {
      95     5323515 :   Handle<HeapNumber> heap_number = NewHeapNumber(mode, pretenure);
      96             :   heap_number->set_value(value);
      97          28 :   return heap_number;
      98             : }
      99             : 
     100             : Handle<HeapNumber> Factory::NewHeapNumberFromBits(uint64_t bits,
     101             :                                                   MutableMode mode,
     102             :                                                   PretenureFlag pretenure) {
     103       30229 :   Handle<HeapNumber> heap_number = NewHeapNumber(mode, pretenure);
     104             :   heap_number->set_value_as_bits(bits);
     105             :   return heap_number;
     106             : }
     107             : 
     108             : Handle<HeapNumber> Factory::NewMutableHeapNumber(PretenureFlag pretenure) {
     109             :   return NewHeapNumberFromBits(kHoleNanInt64, MUTABLE, pretenure);
     110             : }
     111             : 
     112       50356 : Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
     113             :                                                 ElementsKind elements_kind,
     114             :                                                 PretenureFlag pretenure) {
     115             :   return NewJSArrayWithElements(elements, elements_kind, elements->length(),
     116     7132865 :                                 pretenure);
     117             : }
     118             : 
     119        5292 : Handle<Object> Factory::NewURIError() {
     120             :   return NewError(isolate()->uri_error_function(),
     121        5292 :                   MessageTemplate::kURIMalformed);
     122             : }
     123             : 
     124     1890930 : Handle<String> Factory::Uint32ToString(uint32_t value) {
     125     1890930 :   Handle<String> result = NumberToString(NewNumberFromUint(value));
     126             : 
     127     1890930 :   if (result->length() <= String::kMaxArrayIndexSize) {
     128     1513078 :     uint32_t field = StringHasher::MakeArrayIndexHash(value, result->length());
     129             :     result->set_hash_field(field);
     130             :   }
     131     1890930 :   return result;
     132             : }
     133             : 
     134             : }  // namespace internal
     135             : }  // namespace v8
     136             : 
     137             : #endif  // V8_FACTORY_INL_H_

Generated by: LCOV version 1.10