// Copyright 2012 the V8 project authors. All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef V8_FACTORY_H_ #define V8_FACTORY_H_ #include "globals.h" #include "handles.h" #include "heap.h" namespace v8 { namespace internal { // Interface for handle based allocation. class Factory { public: // Allocate a new uninitialized fixed array. Handle NewFixedArray( int size, PretenureFlag pretenure = NOT_TENURED); // Allocate a new fixed array with non-existing entries (the hole). Handle NewFixedArrayWithHoles( int size, PretenureFlag pretenure = NOT_TENURED); // Allocate a new uninitialized fixed double array. Handle NewFixedDoubleArray( int size, PretenureFlag pretenure = NOT_TENURED); Handle NewSeededNumberDictionary( int at_least_space_for); Handle NewUnseededNumberDictionary( int at_least_space_for); Handle NewStringDictionary(int at_least_space_for); Handle NewObjectHashSet(int at_least_space_for); Handle NewObjectHashTable(int at_least_space_for); Handle NewDescriptorArray(int number_of_descriptors, int slack = 0); Handle NewDeoptimizationInputData( int deopt_entry_count, PretenureFlag pretenure); Handle NewDeoptimizationOutputData( int deopt_entry_count, PretenureFlag pretenure); // Allocates a pre-tenured empty AccessorPair. Handle NewAccessorPair(); Handle NewTypeFeedbackInfo(); Handle LookupSymbol(Vector str); Handle LookupSymbol(Handle str); Handle LookupAsciiSymbol(Vector str); Handle LookupAsciiSymbol(Handle, int from, int length); Handle LookupTwoByteSymbol(Vector str); Handle LookupAsciiSymbol(const char* str) { return LookupSymbol(CStrVector(str)); } // String creation functions. Most of the string creation functions take // a Heap::PretenureFlag argument to optionally request that they be // allocated in the old generation. The pretenure flag defaults to // DONT_TENURE. // // Creates a new String object. There are two String encodings: ASCII and // two byte. One should choose between the three string factory functions // based on the encoding of the string buffer that the string is // initialized from. // - ...FromAscii initializes the string from a buffer that is ASCII // encoded (it does not check that the buffer is ASCII encoded) and // the result will be ASCII encoded. // - ...FromUtf8 initializes the string from a buffer that is UTF-8 // encoded. If the characters are all single-byte characters, the // result will be ASCII encoded, otherwise it will converted to two // byte. // - ...FromTwoByte initializes the string from a buffer that is two // byte encoded. If the characters are all single-byte characters, // the result will be converted to ASCII, otherwise it will be left as // two byte. // // ASCII strings are pretenured when used as keys in the SourceCodeCache. Handle NewStringFromAscii( Vector str, PretenureFlag pretenure = NOT_TENURED); // UTF8 strings are pretenured when used for regexp literal patterns and // flags in the parser. Handle NewStringFromUtf8( Vector str, PretenureFlag pretenure = NOT_TENURED); Handle NewStringFromTwoByte( Vector str, PretenureFlag pretenure = NOT_TENURED); // Allocates and partially initializes an ASCII or TwoByte String. The // characters of the string are uninitialized. Currently used in regexp code // only, where they are pretenured. Handle NewRawAsciiString( int length, PretenureFlag pretenure = NOT_TENURED); Handle NewRawTwoByteString( int length, PretenureFlag pretenure = NOT_TENURED); // Create a new cons string object which consists of a pair of strings. Handle NewConsString(Handle first, Handle second); // Create a new string object which holds a substring of a string. Handle NewSubString(Handle str, int begin, int end); // Create a new string object which holds a proper substring of a string. Handle NewProperSubString(Handle str, int begin, int end); // Creates a new external String object. There are two String encodings // in the system: ASCII and two byte. Unlike other String types, it does // not make sense to have a UTF-8 factory function for external strings, // because we cannot change the underlying buffer. Handle NewExternalStringFromAscii( const ExternalAsciiString::Resource* resource); Handle NewExternalStringFromTwoByte( const ExternalTwoByteString::Resource* resource); // Create a global (but otherwise uninitialized) context. Handle NewNativeContext(); // Create a global context. Handle NewGlobalContext(Handle function, Handle scope_info); // Create a module context. Handle NewModuleContext(Handle scope_info); // Create a function context. Handle NewFunctionContext(int length, Handle function); // Create a catch context. Handle NewCatchContext(Handle function, Handle previous, Handle name, Handle thrown_object); // Create a 'with' context. Handle NewWithContext(Handle function, Handle previous, Handle extension); // Create a block context. Handle NewBlockContext(Handle function, Handle previous, Handle scope_info); // Return the Symbol matching the passed in string. Handle SymbolFromString(Handle value); // Allocate a new struct. The struct is pretenured (allocated directly in // the old generation). Handle NewStruct(InstanceType type); Handle NewAccessorInfo(); Handle