5 #ifndef V8_HEAP_FACTORY_INL_H_ 6 #define V8_HEAP_FACTORY_INL_H_ 8 #include "src/heap/factory.h" 12 #include "src/handles-inl.h" 13 #include "src/objects-inl.h" 14 #include "src/string-hasher.h" 20 #define ROOT_ACCESSOR(Type, name, CamelName) \ 21 Handle<std::remove_pointer<Type>::type> Factory::name() { \ 22 return Handle<std::remove_pointer<Type>::type>(bit_cast<Address*>( \ 23 &isolate()->roots_table()[RootIndex::k##CamelName])); \ 25 ROOT_LIST(ROOT_ACCESSOR)
28 Handle<String> Factory::InternalizeString(Handle<String>
string) {
29 if (string->IsInternalizedString())
return string;
30 return StringTable::LookupString(isolate(),
string);
33 Handle<Name> Factory::InternalizeName(Handle<Name> name) {
34 if (name->IsUniqueName())
return name;
35 return StringTable::LookupString(isolate(), Handle<String>::cast(name));
38 Handle<String> Factory::NewSubString(Handle<String> str,
int begin,
int end) {
39 if (begin == 0 && end == str->length())
return str;
40 return NewProperSubString(str, begin, end);
43 Handle<Object> Factory::NewNumberFromSize(
size_t value,
44 PretenureFlag pretenure) {
47 if (value <= static_cast<size_t>(Smi::kMaxValue)) {
48 return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
51 return NewNumber(static_cast<double>(value), pretenure);
54 Handle<Object> Factory::NewNumberFromInt64(
int64_t value,
55 PretenureFlag pretenure) {
56 if (value <= std::numeric_limits<int32_t>::max() &&
57 value >= std::numeric_limits<int32_t>::min() &&
58 Smi::IsValid(static_cast<int32_t>(value))) {
59 return Handle<Object>(Smi::FromInt(static_cast<int32_t>(value)), isolate());
61 return NewNumber(static_cast<double>(value), pretenure);
64 Handle<HeapNumber> Factory::NewHeapNumber(
double value,
65 PretenureFlag pretenure) {
66 Handle<HeapNumber> heap_number = NewHeapNumber(pretenure);
67 heap_number->set_value(value);
71 Handle<MutableHeapNumber> Factory::NewMutableHeapNumber(
72 double value, PretenureFlag pretenure) {
73 Handle<MutableHeapNumber> number = NewMutableHeapNumber(pretenure);
74 number->set_value(value);
78 Handle<HeapNumber> Factory::NewHeapNumberFromBits(uint64_t bits,
79 PretenureFlag pretenure) {
80 Handle<HeapNumber> heap_number = NewHeapNumber(pretenure);
81 heap_number->set_value_as_bits(bits);
85 Handle<MutableHeapNumber> Factory::NewMutableHeapNumberFromBits(
86 uint64_t bits, PretenureFlag pretenure) {
87 Handle<MutableHeapNumber> number = NewMutableHeapNumber(pretenure);
88 number->set_value_as_bits(bits);
92 Handle<MutableHeapNumber> Factory::NewMutableHeapNumberWithHoleNaN(
93 PretenureFlag pretenure) {
94 return NewMutableHeapNumberFromBits(kHoleNanInt64, pretenure);
97 Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
98 ElementsKind elements_kind,
99 PretenureFlag pretenure) {
100 return NewJSArrayWithElements(elements, elements_kind, elements->length(),
104 Handle<Object> Factory::NewURIError() {
105 return NewError(isolate()->uri_error_function(),
106 MessageTemplate::kURIMalformed);
109 Handle<String> Factory::Uint32ToString(
uint32_t value,
bool check_cache) {
110 Handle<String> result;
111 int32_t int32v =
static_cast<int32_t
>(value);
112 if (int32v >= 0 && Smi::IsValid(int32v)) {
113 result = NumberToString(Smi::FromInt(int32v), check_cache);
115 result = NumberToString(NewNumberFromUint(value), check_cache);
118 if (result->length() <= String::kMaxArrayIndexSize &&
119 result->hash_field() == String::kEmptyHashField) {
120 uint32_t field = StringHasher::MakeArrayIndexHash(value, result->length());
121 result->set_hash_field(field);
129 #endif // V8_HEAP_FACTORY_INL_H_