// Copyright 2020 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_HEAP_FACTORY_BASE_H_ #define V8_HEAP_FACTORY_BASE_H_ #include "src/base/export-template.h" #include "src/common/globals.h" #include "src/objects/function-kind.h" #include "src/objects/instance-type.h" #include "src/roots/roots.h" namespace v8 { namespace internal { class HeapObject; class SharedFunctionInfo; class FunctionLiteral; class SeqOneByteString; class SeqTwoByteString; class FreshlyAllocatedBigInt; class ObjectBoilerplateDescription; class ArrayBoilerplateDescription; class TemplateObjectDescription; class SourceTextModuleInfo; class PreparseData; class UncompiledDataWithoutPreparseData; class UncompiledDataWithPreparseData; class BytecodeArray; class CoverageInfo; class ClassPositions; struct SourceRange; template class ZoneVector; template class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase { public: // Converts the given boolean condition to JavaScript boolean value. inline Handle ToBoolean(bool value); // Numbers (e.g. literals) are pretenured by the parser. // The return value may be a smi or a heap number. template inline Handle NewNumber(double value); template inline Handle NewNumberFromInt(int32_t value); template inline Handle NewNumberFromUint(uint32_t value); template inline Handle NewNumberFromSize(size_t value); template inline Handle NewNumberFromInt64(int64_t value); template inline Handle NewHeapNumber(double value); template inline Handle NewHeapNumberFromBits(uint64_t bits); template inline Handle NewHeapNumberWithHoleNaN(); template Handle NewHeapNumber(); Handle NewStruct(InstanceType type, AllocationType allocation = AllocationType::kYoung); // Create a pre-tenured empty AccessorPair. Handle NewAccessorPair(); // Allocates a fixed array initialized with undefined values. Handle NewFixedArray( int length, AllocationType allocation = AllocationType::kYoung); // Allocates a fixed array-like object with given map and initialized with // undefined values. Handle NewFixedArrayWithMap( Handle map, int length, AllocationType allocation = AllocationType::kYoung); // Allocate a new fixed array with non-existing entries (the hole). Handle NewFixedArrayWithHoles( int length, AllocationType allocation = AllocationType::kYoung); // Allocate a new uninitialized fixed double array. // The function returns a pre-allocated empty fixed array for length = 0, // so the return type must be the general fixed array class. Handle NewFixedDoubleArray( int length, AllocationType allocation = AllocationType::kYoung); // Allocates a weak fixed array-like object with given map and initialized // with undefined values. Handle NewWeakFixedArrayWithMap( Map map, int length, AllocationType allocation = AllocationType::kYoung); // Allocates a fixed array which may contain in-place weak references. The // array is initialized with undefined values Handle NewWeakFixedArray( int length, AllocationType allocation = AllocationType::kYoung); Handle NewByteArray( int length, AllocationType allocation = AllocationType::kYoung); Handle NewBytecodeArray(int length, const byte* raw_bytecodes, int frame_size, int parameter_count, Handle constant_pool); // Allocates a fixed array for name-value pairs of boilerplate properties and // calculates the number of properties we need to store in the backing store. Handle NewObjectBoilerplateDescription( int boilerplate, int all_properties, int index_keys, bool has_seen_proto); // Create a new ArrayBoilerplateDescription struct. Handle NewArrayBoilerplateDescription( ElementsKind elements_kind, Handle constant_values); // Create a new TemplateObjectDescription struct. Handle NewTemplateObjectDescription( Handle raw_strings, Handle cooked_strings); Handle