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