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