Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 1 | // Copyright 2012 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. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 53 | Handle<FixedDoubleArray> NewFixedDoubleArray( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 54 | int size, |
| 55 | PretenureFlag pretenure = NOT_TENURED); |
| 56 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 57 | Handle<SeededNumberDictionary> NewSeededNumberDictionary( |
| 58 | int at_least_space_for); |
| 59 | |
| 60 | Handle<UnseededNumberDictionary> NewUnseededNumberDictionary( |
| 61 | int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 62 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 63 | Handle<StringDictionary> NewStringDictionary(int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 64 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 65 | Handle<ObjectHashSet> NewObjectHashSet(int at_least_space_for); |
| 66 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 67 | Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for); |
| 68 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 69 | Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors); |
| 70 | Handle<DeoptimizationInputData> NewDeoptimizationInputData( |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 71 | int deopt_entry_count, |
| 72 | PretenureFlag pretenure); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 73 | Handle<DeoptimizationOutputData> NewDeoptimizationOutputData( |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 74 | int deopt_entry_count, |
| 75 | PretenureFlag pretenure); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 76 | // Allocates a pre-tenured empty AccessorPair. |
| 77 | Handle<AccessorPair> NewAccessorPair(); |
| 78 | |
| 79 | Handle<TypeFeedbackInfo> NewTypeFeedbackInfo(); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 80 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 81 | Handle<String> LookupSymbol(Vector<const char> str); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 82 | Handle<String> LookupSymbol(Handle<String> str); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 83 | Handle<String> LookupAsciiSymbol(Vector<const char> str); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 84 | Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>, |
| 85 | int from, |
| 86 | int length); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 87 | Handle<String> LookupTwoByteSymbol(Vector<const uc16> str); |
| 88 | Handle<String> LookupAsciiSymbol(const char* str) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 89 | return LookupSymbol(CStrVector(str)); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | // String creation functions. Most of the string creation functions take |
| 94 | // a Heap::PretenureFlag argument to optionally request that they be |
| 95 | // allocated in the old generation. The pretenure flag defaults to |
| 96 | // DONT_TENURE. |
| 97 | // |
| 98 | // Creates a new String object. There are two String encodings: ASCII and |
| 99 | // two byte. One should choose between the three string factory functions |
| 100 | // based on the encoding of the string buffer that the string is |
| 101 | // initialized from. |
| 102 | // - ...FromAscii initializes the string from a buffer that is ASCII |
| 103 | // encoded (it does not check that the buffer is ASCII encoded) and |
| 104 | // the result will be ASCII encoded. |
| 105 | // - ...FromUtf8 initializes the string from a buffer that is UTF-8 |
| 106 | // encoded. If the characters are all single-byte characters, the |
| 107 | // result will be ASCII encoded, otherwise it will converted to two |
| 108 | // byte. |
| 109 | // - ...FromTwoByte initializes the string from a buffer that is two |
| 110 | // byte encoded. If the characters are all single-byte characters, |
| 111 | // the result will be converted to ASCII, otherwise it will be left as |
| 112 | // two byte. |
| 113 | // |
| 114 | // ASCII strings are pretenured when used as keys in the SourceCodeCache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 115 | Handle<String> NewStringFromAscii( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 116 | Vector<const char> str, |
| 117 | PretenureFlag pretenure = NOT_TENURED); |
| 118 | |
| 119 | // UTF8 strings are pretenured when used for regexp literal patterns and |
| 120 | // flags in the parser. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 121 | Handle<String> NewStringFromUtf8( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 122 | Vector<const char> str, |
| 123 | PretenureFlag pretenure = NOT_TENURED); |
| 124 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 125 | Handle<String> NewStringFromTwoByte( |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 126 | Vector<const uc16> str, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 127 | PretenureFlag pretenure = NOT_TENURED); |
| 128 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 129 | // Allocates and partially initializes an ASCII or TwoByte String. The |
| 130 | // characters of the string are uninitialized. Currently used in regexp code |
| 131 | // only, where they are pretenured. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 132 | Handle<SeqAsciiString> NewRawAsciiString( |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 133 | int length, |
| 134 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 135 | Handle<SeqTwoByteString> NewRawTwoByteString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 136 | int length, |
| 137 | PretenureFlag pretenure = NOT_TENURED); |
| 138 | |
| 139 | // 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] | 140 | Handle<String> NewConsString(Handle<String> first, |
| 141 | Handle<String> second); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 142 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 143 | // Create a new string object which holds a substring of a string. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 144 | Handle<String> NewSubString(Handle<String> str, |
| 145 | int begin, |
| 146 | int end); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 147 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 148 | // Create a new string object which holds a proper substring of a string. |
| 149 | Handle<String> NewProperSubString(Handle<String> str, |
| 150 | int begin, |
| 151 | int end); |
| 152 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 153 | // Creates a new external String object. There are two String encodings |
| 154 | // in the system: ASCII and two byte. Unlike other String types, it does |
| 155 | // not make sense to have a UTF-8 factory function for external strings, |
| 156 | // because we cannot change the underlying buffer. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 157 | Handle<String> NewExternalStringFromAscii( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 158 | const ExternalAsciiString::Resource* resource); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 159 | Handle<String> NewExternalStringFromTwoByte( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 160 | const ExternalTwoByteString::Resource* resource); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 161 | |
| 162 | // Create a global (but otherwise uninitialized) context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 163 | Handle<Context> NewGlobalContext(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 164 | |
| 165 | // Create a function context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 166 | Handle<Context> NewFunctionContext(int length, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 167 | Handle<JSFunction> function); |
| 168 | |
| 169 | // Create a catch context. |
| 170 | Handle<Context> NewCatchContext(Handle<JSFunction> function, |
| 171 | Handle<Context> previous, |
| 172 | Handle<String> name, |
| 173 | Handle<Object> thrown_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 174 | |
| 175 | // Create a 'with' context. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 176 | Handle<Context> NewWithContext(Handle<JSFunction> function, |
| 177 | Handle<Context> previous, |
| 178 | Handle<JSObject> extension); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 179 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 180 | // Create a 'block' context. |
| 181 | Handle<Context> NewBlockContext(Handle<JSFunction> function, |
| 182 | Handle<Context> previous, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 183 | Handle<ScopeInfo> scope_info); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 184 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 185 | // Return the Symbol matching the passed in string. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 186 | Handle<String> SymbolFromString(Handle<String> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 187 | |
| 188 | // Allocate a new struct. The struct is pretenured (allocated directly in |
| 189 | // the old generation). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 190 | Handle<Struct> NewStruct(InstanceType type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 191 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 192 | Handle<AccessorInfo> NewAccessorInfo(); |
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<Script> NewScript(Handle<String> source); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 195 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 196 | // Foreign objects are pretenured when allocated by the bootstrapper. |
| 197 | Handle<Foreign> NewForeign(Address addr, |
| 198 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 199 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 200 | // Allocate a new foreign object. The foreign is pretenured (allocated |
| 201 | // directly in the old generation). |
| 202 | Handle<Foreign> NewForeign(const AccessorDescriptor* foreign); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 203 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 204 | Handle<ByteArray> NewByteArray(int length, |
| 205 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 206 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 207 | Handle<ExternalArray> NewExternalArray( |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 208 | int length, |
| 209 | ExternalArrayType array_type, |
| 210 | void* external_pointer, |
| 211 | PretenureFlag pretenure = NOT_TENURED); |
| 212 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 213 | Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell( |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 214 | Handle<Object> value); |
| 215 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 216 | Handle<Map> NewMap(InstanceType type, |
| 217 | int instance_size, |
| 218 | ElementsKind elements_kind = FAST_ELEMENTS); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 219 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 220 | Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 221 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 222 | Handle<Map> CopyMapDropDescriptors(Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 223 | |
| 224 | // Copy the map adding more inobject properties if possible without |
| 225 | // overflowing the instance size. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 226 | Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 227 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 228 | Handle<Map> CopyMapDropTransitions(Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 229 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 230 | Handle<Map> GetElementsTransitionMap(Handle<JSObject> object, |
| 231 | ElementsKind elements_kind); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 232 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 233 | Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 234 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 235 | Handle<FixedDoubleArray> CopyFixedDoubleArray( |
| 236 | Handle<FixedDoubleArray> array); |
| 237 | |
| 238 | // Numbers (e.g. literals) are pretenured by the parser. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 239 | Handle<Object> NewNumber(double value, |
| 240 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 241 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 242 | Handle<Object> NewNumberFromInt(int32_t value, |
| 243 | PretenureFlag pretenure = NOT_TENURED); |
| 244 | Handle<Object> NewNumberFromUint(uint32_t value, |
| 245 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 246 | |
| 247 | // These objects are used by the api to create env-independent data |
| 248 | // structures in the heap. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 249 | Handle<JSObject> NewNeanderObject(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 250 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 251 | Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 252 | |
| 253 | // JS objects are pretenured when allocated by the bootstrapper and |
| 254 | // runtime. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 255 | Handle<JSObject> NewJSObject(Handle<JSFunction> constructor, |
| 256 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 257 | |
| 258 | // Global objects are pretenured. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 259 | Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 260 | |
| 261 | // JS objects are pretenured when allocated by the bootstrapper and |
| 262 | // runtime. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 263 | Handle<JSObject> NewJSObjectFromMap(Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 264 | |
| 265 | // JS arrays are pretenured when allocated by the parser. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 266 | Handle<JSArray> NewJSArray(int capacity, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 267 | ElementsKind elements_kind = FAST_ELEMENTS, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 268 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 269 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 270 | Handle<JSArray> NewJSArrayWithElements( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 271 | Handle<FixedArrayBase> elements, |
| 272 | ElementsKind elements_kind = FAST_ELEMENTS, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 273 | PretenureFlag pretenure = NOT_TENURED); |
| 274 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 275 | void SetElementsCapacityAndLength(Handle<JSArray> array, |
| 276 | int capacity, |
| 277 | int length); |
| 278 | |
| 279 | void SetContent(Handle<JSArray> array, Handle<FixedArrayBase> elements); |
| 280 | |
| 281 | void EnsureCanContainHeapObjectElements(Handle<JSArray> array); |
| 282 | void EnsureCanContainElements(Handle<JSArray> array, |
| 283 | Handle<FixedArrayBase> elements, |
| 284 | EnsureElementsMode mode); |
| 285 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 286 | Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype); |
| 287 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 288 | // Change the type of the argument into a JS object/function and reinitialize. |
| 289 | void BecomeJSObject(Handle<JSReceiver> object); |
| 290 | void BecomeJSFunction(Handle<JSReceiver> object); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 291 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 292 | void SetIdentityHash(Handle<JSObject> object, Object* hash); |
| 293 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 294 | Handle<JSFunction> NewFunction(Handle<String> name, |
| 295 | Handle<Object> prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 296 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 297 | Handle<JSFunction> NewFunctionWithoutPrototype( |
| 298 | Handle<String> name, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 299 | LanguageMode language_mode); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 300 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 301 | Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 302 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 303 | Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 304 | Handle<SharedFunctionInfo> function_info, |
| 305 | Handle<Map> function_map, |
| 306 | PretenureFlag pretenure); |
| 307 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 308 | Handle<JSFunction> NewFunctionFromSharedFunctionInfo( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 309 | Handle<SharedFunctionInfo> function_info, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 310 | Handle<Context> context, |
| 311 | PretenureFlag pretenure = TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 312 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 313 | Handle<ScopeInfo> NewScopeInfo(int length); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 314 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 315 | Handle<Code> NewCode(const CodeDesc& desc, |
| 316 | Code::Flags flags, |
| 317 | Handle<Object> self_reference, |
| 318 | bool immovable = false); |
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<Code> CopyCode(Handle<Code> code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 321 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 322 | Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 323 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 324 | Handle<Object> ToObject(Handle<Object> object); |
| 325 | Handle<Object> ToObject(Handle<Object> object, |
| 326 | Handle<Context> global_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | |
| 328 | // Interface for creating error objects. |
| 329 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 330 | Handle<Object> NewError(const char* maker, const char* type, |
| 331 | Handle<JSArray> args); |
| 332 | Handle<Object> NewError(const char* maker, const char* type, |
| 333 | Vector< Handle<Object> > args); |
| 334 | Handle<Object> NewError(const char* type, |
| 335 | Vector< Handle<Object> > args); |
| 336 | Handle<Object> NewError(Handle<String> message); |
| 337 | Handle<Object> NewError(const char* constructor, |
| 338 | Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 339 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 340 | Handle<Object> NewTypeError(const char* type, |
| 341 | Vector< Handle<Object> > args); |
| 342 | Handle<Object> NewTypeError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 343 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 344 | Handle<Object> NewRangeError(const char* type, |
| 345 | Vector< Handle<Object> > args); |
| 346 | Handle<Object> NewRangeError(Handle<String> message); |
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<Object> NewSyntaxError(const char* type, Handle<JSArray> args); |
| 349 | Handle<Object> NewSyntaxError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 350 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 351 | Handle<Object> NewReferenceError(const char* type, |
| 352 | Vector< Handle<Object> > args); |
| 353 | Handle<Object> NewReferenceError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 354 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 355 | Handle<Object> NewEvalError(const char* type, |
| 356 | Vector< Handle<Object> > args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 357 | |
| 358 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 359 | Handle<JSFunction> NewFunction(Handle<String> name, |
| 360 | InstanceType type, |
| 361 | int instance_size, |
| 362 | Handle<Code> code, |
| 363 | bool force_initial_map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 364 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 365 | Handle<JSFunction> NewFunction(Handle<Map> function_map, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 366 | Handle<SharedFunctionInfo> shared, Handle<Object> prototype); |
| 367 | |
| 368 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 369 | Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name, |
| 370 | InstanceType type, |
| 371 | int instance_size, |
| 372 | Handle<JSObject> prototype, |
| 373 | Handle<Code> code, |
| 374 | bool force_initial_map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 375 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 376 | Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name, |
| 377 | Handle<Code> code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 378 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 379 | Handle<DescriptorArray> CopyAppendForeignDescriptor( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 380 | Handle<DescriptorArray> array, |
| 381 | Handle<String> key, |
| 382 | Handle<Object> value, |
| 383 | PropertyAttributes attributes); |
| 384 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 385 | Handle<String> NumberToString(Handle<Object> number); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 386 | Handle<String> Uint32ToString(uint32_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 387 | |
| 388 | enum ApiInstanceType { |
| 389 | JavaScriptObject, |
| 390 | InnerGlobalObject, |
| 391 | OuterGlobalObject |
| 392 | }; |
| 393 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 394 | Handle<JSFunction> CreateApiFunction( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 395 | Handle<FunctionTemplateInfo> data, |
| 396 | ApiInstanceType type = JavaScriptObject); |
| 397 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 398 | Handle<JSFunction> InstallMembers(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 399 | |
| 400 | // Installs interceptors on the instance. 'desc' is a function template, |
| 401 | // and instance is an object instance created by the function of this |
| 402 | // function template. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 403 | void ConfigureInstance(Handle<FunctionTemplateInfo> desc, |
| 404 | Handle<JSObject> instance, |
| 405 | bool* pending_exception); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 406 | |
| 407 | #define ROOT_ACCESSOR(type, name, camel_name) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 408 | inline Handle<type> name() { \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 409 | return Handle<type>(BitCast<type**>( \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 410 | &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 411 | } |
| 412 | ROOT_LIST(ROOT_ACCESSOR) |
| 413 | #undef ROOT_ACCESSOR_ACCESSOR |
| 414 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 415 | #define SYMBOL_ACCESSOR(name, str) \ |
| 416 | inline Handle<String> name() { \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 417 | return Handle<String>(BitCast<String**>( \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 418 | &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 419 | } |
| 420 | SYMBOL_LIST(SYMBOL_ACCESSOR) |
| 421 | #undef SYMBOL_ACCESSOR |
| 422 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 423 | Handle<String> hidden_symbol() { |
| 424 | return Handle<String>(&isolate()->heap()->hidden_symbol_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 427 | Handle<SharedFunctionInfo> NewSharedFunctionInfo( |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 428 | Handle<String> name, |
| 429 | int number_of_literals, |
| 430 | Handle<Code> code, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 431 | Handle<ScopeInfo> scope_info); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 432 | Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 433 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 434 | Handle<JSMessageObject> NewJSMessageObject( |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 435 | Handle<String> type, |
| 436 | Handle<JSArray> arguments, |
| 437 | int start_position, |
| 438 | int end_position, |
| 439 | Handle<Object> script, |
| 440 | Handle<Object> stack_trace, |
| 441 | Handle<Object> stack_frames); |
| 442 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 443 | Handle<SeededNumberDictionary> DictionaryAtNumberPut( |
| 444 | Handle<SeededNumberDictionary>, |
| 445 | uint32_t key, |
| 446 | Handle<Object> value); |
| 447 | |
| 448 | Handle<UnseededNumberDictionary> DictionaryAtNumberPut( |
| 449 | Handle<UnseededNumberDictionary>, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 450 | uint32_t key, |
| 451 | Handle<Object> value); |
| 452 | |
| 453 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 454 | Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 455 | #endif |
| 456 | |
| 457 | // Return a map using the map cache in the global context. |
| 458 | // The key the an ordered set of property names. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 459 | Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context, |
| 460 | Handle<FixedArray> keys); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 461 | |
| 462 | // Creates a new FixedArray that holds the data associated with the |
| 463 | // atom regexp and stores it in the regexp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 464 | void SetRegExpAtomData(Handle<JSRegExp> regexp, |
| 465 | JSRegExp::Type type, |
| 466 | Handle<String> source, |
| 467 | JSRegExp::Flags flags, |
| 468 | Handle<Object> match_pattern); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 469 | |
| 470 | // Creates a new FixedArray that holds the data associated with the |
| 471 | // irregexp regexp and stores it in the regexp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 472 | void SetRegExpIrregexpData(Handle<JSRegExp> regexp, |
| 473 | JSRegExp::Type type, |
| 474 | Handle<String> source, |
| 475 | JSRegExp::Flags flags, |
| 476 | int capture_count); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 477 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 478 | // Returns the value for a known global constant (a property of the global |
| 479 | // object which is neither configurable nor writable) like 'undefined'. |
| 480 | // Returns a null handle when the given name is unknown. |
| 481 | Handle<Object> GlobalConstantFor(Handle<String> name); |
| 482 | |
| 483 | // Converts the given boolean condition to JavaScript boolean value. |
| 484 | Handle<Object> ToBoolean(bool value); |
| 485 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 486 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 487 | Isolate* isolate() { return reinterpret_cast<Isolate*>(this); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 488 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 489 | Handle<JSFunction> NewFunctionHelper(Handle<String> name, |
| 490 | Handle<Object> prototype); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 491 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 492 | Handle<JSFunction> NewFunctionWithoutPrototypeHelper( |
| 493 | Handle<String> name, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame^] | 494 | LanguageMode language_mode); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 495 | |
| 496 | Handle<DescriptorArray> CopyAppendCallbackDescriptors( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 497 | Handle<DescriptorArray> array, |
| 498 | Handle<Object> descriptors); |
| 499 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 500 | // Create a new map cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 501 | Handle<MapCache> NewMapCache(int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 502 | |
| 503 | // Update the map cache in the global context with (keys, map) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 504 | Handle<MapCache> AddToMapCache(Handle<Context> context, |
| 505 | Handle<FixedArray> keys, |
| 506 | Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 507 | }; |
| 508 | |
| 509 | |
| 510 | } } // namespace v8::internal |
| 511 | |
| 512 | #endif // V8_FACTORY_H_ |