Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_FACTORY_H_ |
| 29 | #define V8_FACTORY_H_ |
| 30 | |
| 31 | #include "globals.h" |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 32 | #include "handles.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | #include "heap.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 38 | // Interface for handle based allocation. |
| 39 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 40 | class Factory { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | public: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 42 | // Allocate a new uninitialized fixed array. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 43 | Handle<FixedArray> NewFixedArray( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | int size, |
| 45 | PretenureFlag pretenure = NOT_TENURED); |
| 46 | |
| 47 | // Allocate a new fixed array with non-existing entries (the hole). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 48 | Handle<FixedArray> NewFixedArrayWithHoles( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 49 | int size, |
| 50 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 51 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 52 | // Allocate a new uninitialized fixed double array. |
| 53 | Handle<FixedArray> NewFixedDoubleArray( |
| 54 | int size, |
| 55 | PretenureFlag pretenure = NOT_TENURED); |
| 56 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 57 | Handle<NumberDictionary> NewNumberDictionary(int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 58 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 59 | Handle<StringDictionary> NewStringDictionary(int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 60 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 61 | Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for); |
| 62 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 63 | Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors); |
| 64 | Handle<DeoptimizationInputData> NewDeoptimizationInputData( |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 65 | int deopt_entry_count, |
| 66 | PretenureFlag pretenure); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 67 | Handle<DeoptimizationOutputData> NewDeoptimizationOutputData( |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 68 | int deopt_entry_count, |
| 69 | PretenureFlag pretenure); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 70 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 71 | Handle<String> LookupSymbol(Vector<const char> str); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 72 | Handle<String> LookupSymbol(Handle<String> str); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 73 | Handle<String> LookupAsciiSymbol(Vector<const char> str); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 74 | Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>, |
| 75 | int from, |
| 76 | int length); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 77 | Handle<String> LookupTwoByteSymbol(Vector<const uc16> str); |
| 78 | Handle<String> LookupAsciiSymbol(const char* str) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 79 | return LookupSymbol(CStrVector(str)); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | // String creation functions. Most of the string creation functions take |
| 84 | // a Heap::PretenureFlag argument to optionally request that they be |
| 85 | // allocated in the old generation. The pretenure flag defaults to |
| 86 | // DONT_TENURE. |
| 87 | // |
| 88 | // Creates a new String object. There are two String encodings: ASCII and |
| 89 | // two byte. One should choose between the three string factory functions |
| 90 | // based on the encoding of the string buffer that the string is |
| 91 | // initialized from. |
| 92 | // - ...FromAscii initializes the string from a buffer that is ASCII |
| 93 | // encoded (it does not check that the buffer is ASCII encoded) and |
| 94 | // the result will be ASCII encoded. |
| 95 | // - ...FromUtf8 initializes the string from a buffer that is UTF-8 |
| 96 | // encoded. If the characters are all single-byte characters, the |
| 97 | // result will be ASCII encoded, otherwise it will converted to two |
| 98 | // byte. |
| 99 | // - ...FromTwoByte initializes the string from a buffer that is two |
| 100 | // byte encoded. If the characters are all single-byte characters, |
| 101 | // the result will be converted to ASCII, otherwise it will be left as |
| 102 | // two byte. |
| 103 | // |
| 104 | // ASCII strings are pretenured when used as keys in the SourceCodeCache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 105 | Handle<String> NewStringFromAscii( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 106 | Vector<const char> str, |
| 107 | PretenureFlag pretenure = NOT_TENURED); |
| 108 | |
| 109 | // UTF8 strings are pretenured when used for regexp literal patterns and |
| 110 | // flags in the parser. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 111 | Handle<String> NewStringFromUtf8( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 112 | Vector<const char> str, |
| 113 | PretenureFlag pretenure = NOT_TENURED); |
| 114 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 115 | Handle<String> NewStringFromTwoByte( |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 116 | Vector<const uc16> str, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 117 | PretenureFlag pretenure = NOT_TENURED); |
| 118 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 119 | // Allocates and partially initializes an ASCII or TwoByte String. The |
| 120 | // characters of the string are uninitialized. Currently used in regexp code |
| 121 | // only, where they are pretenured. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 122 | Handle<SeqAsciiString> NewRawAsciiString( |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 123 | int length, |
| 124 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 125 | Handle<SeqTwoByteString> NewRawTwoByteString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 126 | int length, |
| 127 | PretenureFlag pretenure = NOT_TENURED); |
| 128 | |
| 129 | // Create a new cons string object which consists of a pair of strings. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 130 | Handle<String> NewConsString(Handle<String> first, |
| 131 | Handle<String> second); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 132 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 133 | // Create a new string object which holds a substring of a string. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 134 | Handle<String> NewSubString(Handle<String> str, |
| 135 | int begin, |
| 136 | int end); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 137 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 138 | // Create a new string object which holds a proper substring of a string. |
| 139 | Handle<String> NewProperSubString(Handle<String> str, |
| 140 | int begin, |
| 141 | int end); |
| 142 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 143 | // Creates a new external String object. There are two String encodings |
| 144 | // in the system: ASCII and two byte. Unlike other String types, it does |
| 145 | // not make sense to have a UTF-8 factory function for external strings, |
| 146 | // because we cannot change the underlying buffer. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 147 | Handle<String> NewExternalStringFromAscii( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 148 | ExternalAsciiString::Resource* resource); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 149 | Handle<String> NewExternalStringFromTwoByte( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 150 | ExternalTwoByteString::Resource* resource); |
| 151 | |
| 152 | // Create a global (but otherwise uninitialized) context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 153 | Handle<Context> NewGlobalContext(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 154 | |
| 155 | // Create a function context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 156 | Handle<Context> NewFunctionContext(int length, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 157 | Handle<JSFunction> function); |
| 158 | |
| 159 | // Create a catch context. |
| 160 | Handle<Context> NewCatchContext(Handle<JSFunction> function, |
| 161 | Handle<Context> previous, |
| 162 | Handle<String> name, |
| 163 | Handle<Object> thrown_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 164 | |
| 165 | // Create a 'with' context. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 166 | Handle<Context> NewWithContext(Handle<JSFunction> function, |
| 167 | Handle<Context> previous, |
| 168 | Handle<JSObject> extension); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 169 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 170 | // Create a 'block' context. |
| 171 | Handle<Context> NewBlockContext(Handle<JSFunction> function, |
| 172 | Handle<Context> previous, |
| 173 | Handle<SerializedScopeInfo> scope_info); |
| 174 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 175 | // Return the Symbol matching the passed in string. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 176 | Handle<String> SymbolFromString(Handle<String> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 177 | |
| 178 | // Allocate a new struct. The struct is pretenured (allocated directly in |
| 179 | // the old generation). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 180 | Handle<Struct> NewStruct(InstanceType type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 181 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 182 | Handle<AccessorInfo> NewAccessorInfo(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 183 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 184 | Handle<Script> NewScript(Handle<String> source); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 185 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 186 | // Foreign objects are pretenured when allocated by the bootstrapper. |
| 187 | Handle<Foreign> NewForeign(Address addr, |
| 188 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 189 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 190 | // Allocate a new foreign object. The foreign is pretenured (allocated |
| 191 | // directly in the old generation). |
| 192 | Handle<Foreign> NewForeign(const AccessorDescriptor* foreign); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 193 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 194 | Handle<ByteArray> NewByteArray(int length, |
| 195 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 196 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 197 | Handle<ExternalArray> NewExternalArray( |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 198 | int length, |
| 199 | ExternalArrayType array_type, |
| 200 | void* external_pointer, |
| 201 | PretenureFlag pretenure = NOT_TENURED); |
| 202 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 203 | Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell( |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 204 | Handle<Object> value); |
| 205 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 206 | Handle<Map> NewMap(InstanceType type, int instance_size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 207 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 208 | Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 209 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 210 | Handle<Map> CopyMapDropDescriptors(Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 211 | |
| 212 | // Copy the map adding more inobject properties if possible without |
| 213 | // overflowing the instance size. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 214 | Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 215 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 216 | Handle<Map> CopyMapDropTransitions(Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 217 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 218 | Handle<Map> GetFastElementsMap(Handle<Map> map); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 219 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 220 | Handle<Map> GetSlowElementsMap(Handle<Map> map); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 221 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 222 | Handle<Map> GetExternalArrayElementsMap(Handle<Map> map, |
| 223 | ExternalArrayType array_type, |
| 224 | bool safe_to_add_transition); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 225 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 226 | Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 227 | |
| 228 | // Numbers (eg, literals) are pretenured by the parser. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 229 | Handle<Object> NewNumber(double value, |
| 230 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 231 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 232 | Handle<Object> NewNumberFromInt(int value); |
| 233 | Handle<Object> NewNumberFromUint(uint32_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 234 | |
| 235 | // These objects are used by the api to create env-independent data |
| 236 | // structures in the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 237 | Handle<JSObject> NewNeanderObject(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 238 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 239 | Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 240 | |
| 241 | // JS objects are pretenured when allocated by the bootstrapper and |
| 242 | // runtime. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 243 | Handle<JSObject> NewJSObject(Handle<JSFunction> constructor, |
| 244 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 245 | |
| 246 | // Global objects are pretenured. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 247 | Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 248 | |
| 249 | // JS objects are pretenured when allocated by the bootstrapper and |
| 250 | // runtime. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 251 | Handle<JSObject> NewJSObjectFromMap(Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 252 | |
| 253 | // JS arrays are pretenured when allocated by the parser. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 254 | Handle<JSArray> NewJSArray(int capacity, |
| 255 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 256 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 257 | Handle<JSArray> NewJSArrayWithElements( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 258 | Handle<FixedArray> elements, |
| 259 | PretenureFlag pretenure = NOT_TENURED); |
| 260 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 261 | Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype); |
| 262 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 263 | // Change the type of the argument into a regular JS object and reinitialize. |
| 264 | void BecomeJSObject(Handle<JSProxy> object); |
| 265 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 266 | Handle<JSFunction> NewFunction(Handle<String> name, |
| 267 | Handle<Object> prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 268 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 269 | Handle<JSFunction> NewFunctionWithoutPrototype( |
| 270 | Handle<String> name, |
| 271 | StrictModeFlag strict_mode); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 272 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 273 | Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 274 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 275 | Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 276 | Handle<SharedFunctionInfo> function_info, |
| 277 | Handle<Map> function_map, |
| 278 | PretenureFlag pretenure); |
| 279 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 280 | Handle<JSFunction> NewFunctionFromSharedFunctionInfo( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 281 | Handle<SharedFunctionInfo> function_info, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 282 | Handle<Context> context, |
| 283 | PretenureFlag pretenure = TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 284 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 285 | Handle<SerializedScopeInfo> NewSerializedScopeInfo(int length); |
| 286 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 287 | Handle<Code> NewCode(const CodeDesc& desc, |
| 288 | Code::Flags flags, |
| 289 | Handle<Object> self_reference, |
| 290 | bool immovable = false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 291 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 292 | Handle<Code> CopyCode(Handle<Code> code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 293 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 294 | Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 295 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 296 | Handle<Object> ToObject(Handle<Object> object); |
| 297 | Handle<Object> ToObject(Handle<Object> object, |
| 298 | Handle<Context> global_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | |
| 300 | // Interface for creating error objects. |
| 301 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 302 | Handle<Object> NewError(const char* maker, const char* type, |
| 303 | Handle<JSArray> args); |
| 304 | Handle<Object> NewError(const char* maker, const char* type, |
| 305 | Vector< Handle<Object> > args); |
| 306 | Handle<Object> NewError(const char* type, |
| 307 | Vector< Handle<Object> > args); |
| 308 | Handle<Object> NewError(Handle<String> message); |
| 309 | Handle<Object> NewError(const char* constructor, |
| 310 | Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 311 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 312 | Handle<Object> NewTypeError(const char* type, |
| 313 | Vector< Handle<Object> > args); |
| 314 | Handle<Object> NewTypeError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 315 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 316 | Handle<Object> NewRangeError(const char* type, |
| 317 | Vector< Handle<Object> > args); |
| 318 | Handle<Object> NewRangeError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 319 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 320 | Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args); |
| 321 | Handle<Object> NewSyntaxError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 322 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 323 | Handle<Object> NewReferenceError(const char* type, |
| 324 | Vector< Handle<Object> > args); |
| 325 | Handle<Object> NewReferenceError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 326 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 327 | Handle<Object> NewEvalError(const char* type, |
| 328 | Vector< Handle<Object> > args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 329 | |
| 330 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 331 | Handle<JSFunction> NewFunction(Handle<String> name, |
| 332 | InstanceType type, |
| 333 | int instance_size, |
| 334 | Handle<Code> code, |
| 335 | bool force_initial_map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 336 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 337 | Handle<JSFunction> NewFunction(Handle<Map> function_map, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 338 | Handle<SharedFunctionInfo> shared, Handle<Object> prototype); |
| 339 | |
| 340 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 341 | Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name, |
| 342 | InstanceType type, |
| 343 | int instance_size, |
| 344 | Handle<JSObject> prototype, |
| 345 | Handle<Code> code, |
| 346 | bool force_initial_map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 347 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 348 | Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name, |
| 349 | Handle<Code> code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 350 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 351 | Handle<DescriptorArray> CopyAppendForeignDescriptor( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 352 | Handle<DescriptorArray> array, |
| 353 | Handle<String> key, |
| 354 | Handle<Object> value, |
| 355 | PropertyAttributes attributes); |
| 356 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 357 | Handle<String> NumberToString(Handle<Object> number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 358 | |
| 359 | enum ApiInstanceType { |
| 360 | JavaScriptObject, |
| 361 | InnerGlobalObject, |
| 362 | OuterGlobalObject |
| 363 | }; |
| 364 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 365 | Handle<JSFunction> CreateApiFunction( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 366 | Handle<FunctionTemplateInfo> data, |
| 367 | ApiInstanceType type = JavaScriptObject); |
| 368 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 369 | Handle<JSFunction> InstallMembers(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 370 | |
| 371 | // Installs interceptors on the instance. 'desc' is a function template, |
| 372 | // and instance is an object instance created by the function of this |
| 373 | // function template. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 374 | void ConfigureInstance(Handle<FunctionTemplateInfo> desc, |
| 375 | Handle<JSObject> instance, |
| 376 | bool* pending_exception); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 377 | |
| 378 | #define ROOT_ACCESSOR(type, name, camel_name) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 379 | inline Handle<type> name() { \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 380 | return Handle<type>(BitCast<type**>( \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 381 | &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 382 | } |
| 383 | ROOT_LIST(ROOT_ACCESSOR) |
| 384 | #undef ROOT_ACCESSOR_ACCESSOR |
| 385 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 386 | #define SYMBOL_ACCESSOR(name, str) \ |
| 387 | inline Handle<String> name() { \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 388 | return Handle<String>(BitCast<String**>( \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 389 | &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 390 | } |
| 391 | SYMBOL_LIST(SYMBOL_ACCESSOR) |
| 392 | #undef SYMBOL_ACCESSOR |
| 393 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 394 | Handle<String> hidden_symbol() { |
| 395 | return Handle<String>(&isolate()->heap()->hidden_symbol_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 398 | Handle<SharedFunctionInfo> NewSharedFunctionInfo( |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 399 | Handle<String> name, |
| 400 | int number_of_literals, |
| 401 | Handle<Code> code, |
| 402 | Handle<SerializedScopeInfo> scope_info); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 403 | Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 404 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 405 | Handle<JSMessageObject> NewJSMessageObject( |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 406 | Handle<String> type, |
| 407 | Handle<JSArray> arguments, |
| 408 | int start_position, |
| 409 | int end_position, |
| 410 | Handle<Object> script, |
| 411 | Handle<Object> stack_trace, |
| 412 | Handle<Object> stack_frames); |
| 413 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 414 | Handle<NumberDictionary> DictionaryAtNumberPut( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 415 | Handle<NumberDictionary>, |
| 416 | uint32_t key, |
| 417 | Handle<Object> value); |
| 418 | |
| 419 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 420 | Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 421 | #endif |
| 422 | |
| 423 | // Return a map using the map cache in the global context. |
| 424 | // The key the an ordered set of property names. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 425 | Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context, |
| 426 | Handle<FixedArray> keys); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 427 | |
| 428 | // Creates a new FixedArray that holds the data associated with the |
| 429 | // atom regexp and stores it in the regexp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 430 | void SetRegExpAtomData(Handle<JSRegExp> regexp, |
| 431 | JSRegExp::Type type, |
| 432 | Handle<String> source, |
| 433 | JSRegExp::Flags flags, |
| 434 | Handle<Object> match_pattern); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 435 | |
| 436 | // Creates a new FixedArray that holds the data associated with the |
| 437 | // irregexp regexp and stores it in the regexp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 438 | void SetRegExpIrregexpData(Handle<JSRegExp> regexp, |
| 439 | JSRegExp::Type type, |
| 440 | Handle<String> source, |
| 441 | JSRegExp::Flags flags, |
| 442 | int capture_count); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 443 | |
| 444 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 445 | Isolate* isolate() { return reinterpret_cast<Isolate*>(this); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 446 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 447 | Handle<JSFunction> NewFunctionHelper(Handle<String> name, |
| 448 | Handle<Object> prototype); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 449 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 450 | Handle<JSFunction> NewFunctionWithoutPrototypeHelper( |
| 451 | Handle<String> name, |
| 452 | StrictModeFlag strict_mode); |
| 453 | |
| 454 | Handle<DescriptorArray> CopyAppendCallbackDescriptors( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 455 | Handle<DescriptorArray> array, |
| 456 | Handle<Object> descriptors); |
| 457 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 458 | // Create a new map cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 459 | Handle<MapCache> NewMapCache(int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 460 | |
| 461 | // Update the map cache in the global context with (keys, map) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 462 | Handle<MapCache> AddToMapCache(Handle<Context> context, |
| 463 | Handle<FixedArray> keys, |
| 464 | Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 465 | }; |
| 466 | |
| 467 | |
| 468 | } } // namespace v8::internal |
| 469 | |
| 470 | #endif // V8_FACTORY_H_ |