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