Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_FACTORY_H_ |
| 6 | #define V8_FACTORY_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/isolate.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 13 | // Interface for handle based allocation. |
| 14 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 15 | class Factory FINAL { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 16 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 17 | Handle<Oddball> NewOddball(Handle<Map> map, |
| 18 | const char* to_string, |
| 19 | Handle<Object> to_number, |
| 20 | byte kind); |
| 21 | |
| 22 | // Allocates a fixed array initialized with undefined values. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 23 | Handle<FixedArray> NewFixedArray( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 24 | int size, |
| 25 | PretenureFlag pretenure = NOT_TENURED); |
| 26 | |
| 27 | // Allocate a new fixed array with non-existing entries (the hole). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 28 | Handle<FixedArray> NewFixedArrayWithHoles( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 29 | int size, |
| 30 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 31 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 32 | // Allocates an uninitialized fixed array. It must be filled by the caller. |
| 33 | Handle<FixedArray> NewUninitializedFixedArray(int size); |
| 34 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 35 | // Allocate a new uninitialized fixed double array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 36 | // The function returns a pre-allocated empty fixed array for capacity = 0, |
| 37 | // so the return type must be the general fixed array class. |
| 38 | Handle<FixedArrayBase> NewFixedDoubleArray( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 39 | int size, |
| 40 | PretenureFlag pretenure = NOT_TENURED); |
| 41 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 42 | // Allocate a new fixed double array with hole values. |
| 43 | Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles( |
| 44 | int size, |
| 45 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 46 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 47 | Handle<ConstantPoolArray> NewConstantPoolArray( |
| 48 | const ConstantPoolArray::NumberOfEntries& small); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 49 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 50 | Handle<ConstantPoolArray> NewExtendedConstantPoolArray( |
| 51 | const ConstantPoolArray::NumberOfEntries& small, |
| 52 | const ConstantPoolArray::NumberOfEntries& extended); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 53 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 54 | Handle<OrderedHashSet> NewOrderedHashSet(); |
| 55 | Handle<OrderedHashMap> NewOrderedHashMap(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 56 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 57 | // Create a new boxed value. |
| 58 | Handle<Box> NewBox(Handle<Object> value); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 59 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 60 | // Create a pre-tenured empty AccessorPair. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 61 | Handle<AccessorPair> NewAccessorPair(); |
| 62 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 63 | // Create an empty TypeFeedbackInfo. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 64 | Handle<TypeFeedbackInfo> NewTypeFeedbackInfo(); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 65 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 66 | // Finds the internalized copy for string in the string table. |
| 67 | // If not found, a new string is added to the table and returned. |
| 68 | Handle<String> InternalizeUtf8String(Vector<const char> str); |
| 69 | Handle<String> InternalizeUtf8String(const char* str) { |
| 70 | return InternalizeUtf8String(CStrVector(str)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 71 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 72 | Handle<String> InternalizeString(Handle<String> str); |
| 73 | Handle<String> InternalizeOneByteString(Vector<const uint8_t> str); |
| 74 | Handle<String> InternalizeOneByteString( |
| 75 | Handle<SeqOneByteString>, int from, int length); |
| 76 | |
| 77 | Handle<String> InternalizeTwoByteString(Vector<const uc16> str); |
| 78 | |
| 79 | template<class StringTableKey> |
| 80 | Handle<String> InternalizeStringWithKey(StringTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 81 | |
| 82 | |
| 83 | // String creation functions. Most of the string creation functions take |
| 84 | // a Heap::PretenureFlag argument to optionally request that they be |
| 85 | // allocated in the old generation. The pretenure flag defaults to |
| 86 | // DONT_TENURE. |
| 87 | // |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 88 | // Creates a new String object. There are two String encodings: one-byte and |
| 89 | // two-byte. One should choose between the three string factory functions |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 90 | // based on the encoding of the string buffer that the string is |
| 91 | // initialized from. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 92 | // - ...FromOneByte initializes the string from a buffer that is Latin1 |
| 93 | // encoded (it does not check that the buffer is Latin1 encoded) and |
| 94 | // the result will be Latin1 encoded. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 95 | // - ...FromUtf8 initializes the string from a buffer that is UTF-8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 96 | // encoded. If the characters are all ASCII characters, the result |
| 97 | // will be Latin1 encoded, otherwise it will converted to two-byte. |
| 98 | // - ...FromTwoByte initializes the string from a buffer that is two-byte |
| 99 | // encoded. If the characters are all Latin1 characters, the result |
| 100 | // will be converted to Latin1, otherwise it will be left as two-byte. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 101 | // |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 102 | // One-byte strings are pretenured when used as keys in the SourceCodeCache. |
| 103 | MUST_USE_RESULT MaybeHandle<String> NewStringFromOneByte( |
| 104 | Vector<const uint8_t> str, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 105 | PretenureFlag pretenure = NOT_TENURED); |
| 106 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 107 | template <size_t N> |
| 108 | inline Handle<String> NewStringFromStaticChars( |
| 109 | const char (&str)[N], PretenureFlag pretenure = NOT_TENURED) { |
| 110 | DCHECK(N == StrLength(str) + 1); |
| 111 | return NewStringFromOneByte(STATIC_CHAR_VECTOR(str), pretenure) |
| 112 | .ToHandleChecked(); |
| 113 | } |
| 114 | |
| 115 | inline Handle<String> NewStringFromAsciiChecked( |
| 116 | const char* str, |
| 117 | PretenureFlag pretenure = NOT_TENURED) { |
| 118 | return NewStringFromOneByte( |
| 119 | OneByteVector(str), pretenure).ToHandleChecked(); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | // Allocates and fully initializes a String. There are two String encodings: |
| 124 | // one-byte and two-byte. One should choose between the threestring |
| 125 | // allocation functions based on the encoding of the string buffer used to |
| 126 | // initialized the string. |
| 127 | // - ...FromOneByte initializes the string from a buffer that is Latin1 |
| 128 | // encoded (it does not check that the buffer is Latin1 encoded) and the |
| 129 | // result will be Latin1 encoded. |
| 130 | // - ...FromUTF8 initializes the string from a buffer that is UTF-8 |
| 131 | // encoded. If the characters are all ASCII characters, the result |
| 132 | // will be Latin1 encoded, otherwise it will converted to two-byte. |
| 133 | // - ...FromTwoByte initializes the string from a buffer that is two-byte |
| 134 | // encoded. If the characters are all Latin1 characters, the |
| 135 | // result will be converted to Latin1, otherwise it will be left as |
| 136 | // two-byte. |
| 137 | |
| 138 | // TODO(dcarney): remove this function. |
| 139 | MUST_USE_RESULT inline MaybeHandle<String> NewStringFromAscii( |
| 140 | Vector<const char> str, |
| 141 | PretenureFlag pretenure = NOT_TENURED) { |
| 142 | return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure); |
| 143 | } |
| 144 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 145 | // UTF8 strings are pretenured when used for regexp literal patterns and |
| 146 | // flags in the parser. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 147 | MUST_USE_RESULT MaybeHandle<String> NewStringFromUtf8( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 148 | Vector<const char> str, |
| 149 | PretenureFlag pretenure = NOT_TENURED); |
| 150 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 151 | MUST_USE_RESULT MaybeHandle<String> NewStringFromTwoByte( |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 152 | Vector<const uc16> str, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 153 | PretenureFlag pretenure = NOT_TENURED); |
| 154 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 155 | // Allocates an internalized string in old space based on the character |
| 156 | // stream. |
| 157 | MUST_USE_RESULT Handle<String> NewInternalizedStringFromUtf8( |
| 158 | Vector<const char> str, |
| 159 | int chars, |
| 160 | uint32_t hash_field); |
| 161 | |
| 162 | MUST_USE_RESULT Handle<String> NewOneByteInternalizedString( |
| 163 | Vector<const uint8_t> str, uint32_t hash_field); |
| 164 | |
| 165 | MUST_USE_RESULT Handle<String> NewOneByteInternalizedSubString( |
| 166 | Handle<SeqOneByteString> string, int offset, int length, |
| 167 | uint32_t hash_field); |
| 168 | |
| 169 | MUST_USE_RESULT Handle<String> NewTwoByteInternalizedString( |
| 170 | Vector<const uc16> str, |
| 171 | uint32_t hash_field); |
| 172 | |
| 173 | MUST_USE_RESULT Handle<String> NewInternalizedStringImpl( |
| 174 | Handle<String> string, int chars, uint32_t hash_field); |
| 175 | |
| 176 | // Compute the matching internalized string map for a string if possible. |
| 177 | // Empty handle is returned if string is in new space or not flattened. |
| 178 | MUST_USE_RESULT MaybeHandle<Map> InternalizedStringMapForString( |
| 179 | Handle<String> string); |
| 180 | |
| 181 | // Allocates and partially initializes an one-byte or two-byte String. The |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 182 | // characters of the string are uninitialized. Currently used in regexp code |
| 183 | // only, where they are pretenured. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 184 | MUST_USE_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString( |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 185 | int length, |
| 186 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 187 | MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 188 | int length, |
| 189 | PretenureFlag pretenure = NOT_TENURED); |
| 190 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 191 | // Creates a single character string where the character has given code. |
| 192 | // A cache is used for Latin1 codes. |
| 193 | Handle<String> LookupSingleCharacterStringFromCode(uint32_t code); |
| 194 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 195 | // Create a new cons string object which consists of a pair of strings. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 196 | MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left, |
| 197 | Handle<String> right); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 198 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 199 | // Create a new string object which holds a proper substring of a string. |
| 200 | Handle<String> NewProperSubString(Handle<String> str, |
| 201 | int begin, |
| 202 | int end); |
| 203 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 204 | // Create a new string object which holds a substring of a string. |
| 205 | Handle<String> NewSubString(Handle<String> str, int begin, int end) { |
| 206 | if (begin == 0 && end == str->length()) return str; |
| 207 | return NewProperSubString(str, begin, end); |
| 208 | } |
| 209 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 210 | // Creates a new external String object. There are two String encodings |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 211 | // in the system: one-byte and two-byte. Unlike other String types, it does |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 212 | // not make sense to have a UTF-8 factory function for external strings, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 213 | // because we cannot change the underlying buffer. Note that these strings |
| 214 | // are backed by a string resource that resides outside the V8 heap. |
| 215 | MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromOneByte( |
| 216 | const ExternalOneByteString::Resource* resource); |
| 217 | MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromTwoByte( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 218 | const ExternalTwoByteString::Resource* resource); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 219 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 220 | // Create a symbol. |
| 221 | Handle<Symbol> NewSymbol(); |
| 222 | Handle<Symbol> NewPrivateSymbol(); |
| 223 | Handle<Symbol> NewPrivateOwnSymbol(); |
| 224 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 225 | // Create a global (but otherwise uninitialized) context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 226 | Handle<Context> NewNativeContext(); |
| 227 | |
| 228 | // Create a global context. |
| 229 | Handle<Context> NewGlobalContext(Handle<JSFunction> function, |
| 230 | Handle<ScopeInfo> scope_info); |
| 231 | |
| 232 | // Create a module context. |
| 233 | Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 234 | |
| 235 | // Create a function context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 236 | Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 237 | |
| 238 | // Create a catch context. |
| 239 | Handle<Context> NewCatchContext(Handle<JSFunction> function, |
| 240 | Handle<Context> previous, |
| 241 | Handle<String> name, |
| 242 | Handle<Object> thrown_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 243 | |
| 244 | // Create a 'with' context. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 245 | Handle<Context> NewWithContext(Handle<JSFunction> function, |
| 246 | Handle<Context> previous, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 247 | Handle<JSReceiver> extension); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 248 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 249 | // Create a block context. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 250 | Handle<Context> NewBlockContext(Handle<JSFunction> function, |
| 251 | Handle<Context> previous, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 252 | Handle<ScopeInfo> scope_info); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 253 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 254 | // Allocate a new struct. The struct is pretenured (allocated directly in |
| 255 | // the old generation). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 256 | Handle<Struct> NewStruct(InstanceType type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 257 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 258 | Handle<CodeCache> NewCodeCache(); |
| 259 | |
| 260 | Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry( |
| 261 | int aliased_context_slot); |
| 262 | |
| 263 | Handle<DeclaredAccessorDescriptor> NewDeclaredAccessorDescriptor(); |
| 264 | |
| 265 | Handle<DeclaredAccessorInfo> NewDeclaredAccessorInfo(); |
| 266 | |
| 267 | Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 268 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 269 | Handle<Script> NewScript(Handle<String> source); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 270 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 271 | // Foreign objects are pretenured when allocated by the bootstrapper. |
| 272 | Handle<Foreign> NewForeign(Address addr, |
| 273 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 274 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 275 | // Allocate a new foreign object. The foreign is pretenured (allocated |
| 276 | // directly in the old generation). |
| 277 | Handle<Foreign> NewForeign(const AccessorDescriptor* foreign); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 278 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 279 | Handle<ByteArray> NewByteArray(int length, |
| 280 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 281 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 282 | Handle<ExternalArray> NewExternalArray( |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 283 | int length, |
| 284 | ExternalArrayType array_type, |
| 285 | void* external_pointer, |
| 286 | PretenureFlag pretenure = NOT_TENURED); |
| 287 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 288 | Handle<FixedTypedArrayBase> NewFixedTypedArray( |
| 289 | int length, |
| 290 | ExternalArrayType array_type, |
| 291 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 292 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 293 | Handle<Cell> NewCell(Handle<Object> value); |
| 294 | |
| 295 | Handle<PropertyCell> NewPropertyCellWithHole(); |
| 296 | |
| 297 | Handle<PropertyCell> NewPropertyCell(Handle<Object> value); |
| 298 | |
| 299 | // Allocate a tenured AllocationSite. It's payload is null. |
| 300 | Handle<AllocationSite> NewAllocationSite(); |
| 301 | |
| 302 | Handle<Map> NewMap( |
| 303 | InstanceType type, |
| 304 | int instance_size, |
| 305 | ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND); |
| 306 | |
| 307 | Handle<HeapObject> NewFillerObject(int size, |
| 308 | bool double_align, |
| 309 | AllocationSpace space); |
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<JSObject> NewFunctionPrototype(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 312 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 313 | Handle<JSObject> CopyJSObject(Handle<JSObject> object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 314 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 315 | Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object, |
| 316 | Handle<AllocationSite> site); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 317 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 318 | Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array, |
| 319 | Handle<Map> map); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 320 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 321 | Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 322 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 323 | // This method expects a COW array in new space, and creates a copy |
| 324 | // of it in old space. |
| 325 | Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array); |
| 326 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 327 | Handle<FixedDoubleArray> CopyFixedDoubleArray( |
| 328 | Handle<FixedDoubleArray> array); |
| 329 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 330 | Handle<ConstantPoolArray> CopyConstantPoolArray( |
| 331 | Handle<ConstantPoolArray> array); |
| 332 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 333 | // Numbers (e.g. literals) are pretenured by the parser. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 334 | // The return value may be a smi or a heap number. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 335 | Handle<Object> NewNumber(double value, |
| 336 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 337 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 338 | Handle<Object> NewNumberFromInt(int32_t value, |
| 339 | PretenureFlag pretenure = NOT_TENURED); |
| 340 | Handle<Object> NewNumberFromUint(uint32_t value, |
| 341 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 342 | Handle<Object> NewNumberFromSize(size_t value, |
| 343 | PretenureFlag pretenure = NOT_TENURED) { |
| 344 | if (Smi::IsValid(static_cast<intptr_t>(value))) { |
| 345 | return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)), |
| 346 | isolate()); |
| 347 | } |
| 348 | return NewNumber(static_cast<double>(value), pretenure); |
| 349 | } |
| 350 | Handle<HeapNumber> NewHeapNumber(double value, |
| 351 | MutableMode mode = IMMUTABLE, |
| 352 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 353 | |
| 354 | // These objects are used by the api to create env-independent data |
| 355 | // structures in the heap. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 356 | inline Handle<JSObject> NewNeanderObject() { |
| 357 | return NewJSObjectFromMap(neander_map()); |
| 358 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 359 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 360 | Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 361 | |
| 362 | // JS objects are pretenured when allocated by the bootstrapper and |
| 363 | // runtime. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 364 | Handle<JSObject> NewJSObject(Handle<JSFunction> constructor, |
| 365 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 366 | // JSObject that should have a memento pointing to the allocation site. |
| 367 | Handle<JSObject> NewJSObjectWithMemento(Handle<JSFunction> constructor, |
| 368 | Handle<AllocationSite> site); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 369 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 370 | // Global objects are pretenured and initialized based on a constructor. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 371 | Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 372 | |
| 373 | // JS objects are pretenured when allocated by the bootstrapper and |
| 374 | // runtime. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 375 | Handle<JSObject> NewJSObjectFromMap( |
| 376 | Handle<Map> map, |
| 377 | PretenureFlag pretenure = NOT_TENURED, |
| 378 | bool allocate_properties = true, |
| 379 | Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null()); |
| 380 | |
| 381 | // JS modules are pretenured. |
| 382 | Handle<JSModule> NewJSModule(Handle<Context> context, |
| 383 | Handle<ScopeInfo> scope_info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 384 | |
| 385 | // JS arrays are pretenured when allocated by the parser. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 386 | |
| 387 | // Create a JSArray with no elements. |
| 388 | Handle<JSArray> NewJSArray( |
| 389 | ElementsKind elements_kind, |
| 390 | PretenureFlag pretenure = NOT_TENURED); |
| 391 | |
| 392 | // Create a JSArray with a specified length and elements initialized |
| 393 | // according to the specified mode. |
| 394 | Handle<JSArray> NewJSArray( |
| 395 | ElementsKind elements_kind, int length, int capacity, |
| 396 | ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS, |
| 397 | PretenureFlag pretenure = NOT_TENURED); |
| 398 | |
| 399 | Handle<JSArray> NewJSArray( |
| 400 | int capacity, |
| 401 | ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND, |
| 402 | PretenureFlag pretenure = NOT_TENURED) { |
| 403 | if (capacity != 0) { |
| 404 | elements_kind = GetHoleyElementsKind(elements_kind); |
| 405 | } |
| 406 | return NewJSArray(elements_kind, 0, capacity, |
| 407 | INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure); |
| 408 | } |
| 409 | |
| 410 | // Create a JSArray with the given elements. |
| 411 | Handle<JSArray> NewJSArrayWithElements( |
| 412 | Handle<FixedArrayBase> elements, |
| 413 | ElementsKind elements_kind, |
| 414 | int length, |
| 415 | PretenureFlag pretenure = NOT_TENURED); |
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<JSArray> NewJSArrayWithElements( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 418 | Handle<FixedArrayBase> elements, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 419 | ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND, |
| 420 | PretenureFlag pretenure = NOT_TENURED) { |
| 421 | return NewJSArrayWithElements( |
| 422 | elements, elements_kind, elements->length(), pretenure); |
| 423 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 424 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 425 | void NewJSArrayStorage( |
| 426 | Handle<JSArray> array, |
| 427 | int length, |
| 428 | int capacity, |
| 429 | ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 430 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 431 | Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 432 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 433 | Handle<JSArrayBuffer> NewJSArrayBuffer(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 434 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 435 | Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type); |
| 436 | |
| 437 | Handle<JSDataView> NewJSDataView(); |
| 438 | |
| 439 | // Allocates a Harmony proxy. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 440 | Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype); |
| 441 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 442 | // Allocates a Harmony function proxy. |
| 443 | Handle<JSProxy> NewJSFunctionProxy(Handle<Object> handler, |
| 444 | Handle<Object> call_trap, |
| 445 | Handle<Object> construct_trap, |
| 446 | Handle<Object> prototype); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 447 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 448 | // Reinitialize an JSGlobalProxy based on a constructor. The object |
| 449 | // must have the same size as objects allocated using the |
| 450 | // constructor. The object is reinitialized and behaves as an |
| 451 | // object that has been freshly allocated using the constructor. |
| 452 | void ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> global, |
| 453 | Handle<JSFunction> constructor); |
| 454 | |
| 455 | // Change the type of the argument into a JS object/function and reinitialize. |
| 456 | void BecomeJSObject(Handle<JSProxy> object); |
| 457 | void BecomeJSFunction(Handle<JSProxy> object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 458 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 459 | Handle<JSFunction> NewFunction(Handle<String> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 460 | Handle<Code> code, |
| 461 | Handle<Object> prototype, |
| 462 | bool read_only_prototype = false); |
| 463 | Handle<JSFunction> NewFunction(Handle<String> name); |
| 464 | Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name, |
| 465 | Handle<Code> code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 466 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 467 | Handle<JSFunction> NewFunctionFromSharedFunctionInfo( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 468 | Handle<SharedFunctionInfo> function_info, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 469 | Handle<Context> context, |
| 470 | PretenureFlag pretenure = TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 471 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 472 | Handle<JSFunction> NewFunction(Handle<String> name, |
| 473 | Handle<Code> code, |
| 474 | Handle<Object> prototype, |
| 475 | InstanceType type, |
| 476 | int instance_size, |
| 477 | bool read_only_prototype = false); |
| 478 | Handle<JSFunction> NewFunction(Handle<String> name, |
| 479 | Handle<Code> code, |
| 480 | InstanceType type, |
| 481 | int instance_size); |
| 482 | |
| 483 | // Create a serialized scope info. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 484 | Handle<ScopeInfo> NewScopeInfo(int length); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 485 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 486 | // Create an External object for V8's external API. |
| 487 | Handle<JSObject> NewExternal(void* value); |
| 488 | |
| 489 | // The reference to the Code object is stored in self_reference. |
| 490 | // This allows generated code to reference its own Code object |
| 491 | // by containing this handle. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 492 | Handle<Code> NewCode(const CodeDesc& desc, |
| 493 | Code::Flags flags, |
| 494 | Handle<Object> self_reference, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 495 | bool immovable = false, |
| 496 | bool crankshafted = false, |
| 497 | int prologue_offset = Code::kPrologueOffsetNotSet, |
| 498 | bool is_debug = false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 500 | Handle<Code> CopyCode(Handle<Code> code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 501 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 502 | Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 503 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 504 | // Interface for creating error objects. |
| 505 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 506 | MaybeHandle<Object> NewError(const char* maker, const char* message, |
| 507 | Handle<JSArray> args); |
| 508 | Handle<String> EmergencyNewError(const char* message, Handle<JSArray> args); |
| 509 | MaybeHandle<Object> NewError(const char* maker, const char* message, |
| 510 | Vector<Handle<Object> > args); |
| 511 | MaybeHandle<Object> NewError(const char* message, |
| 512 | Vector<Handle<Object> > args); |
| 513 | MaybeHandle<Object> NewError(Handle<String> message); |
| 514 | MaybeHandle<Object> NewError(const char* constructor, Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 515 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 516 | MaybeHandle<Object> NewTypeError(const char* message, |
| 517 | Vector<Handle<Object> > args); |
| 518 | MaybeHandle<Object> NewTypeError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 519 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 520 | MaybeHandle<Object> NewRangeError(const char* message, |
| 521 | Vector<Handle<Object> > args); |
| 522 | MaybeHandle<Object> NewRangeError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 523 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 524 | MaybeHandle<Object> NewInvalidStringLengthError() { |
| 525 | return NewRangeError("invalid_string_length", |
| 526 | HandleVector<Object>(NULL, 0)); |
| 527 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 528 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 529 | MaybeHandle<Object> NewSyntaxError(const char* message, Handle<JSArray> args); |
| 530 | MaybeHandle<Object> NewSyntaxError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 531 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 532 | MaybeHandle<Object> NewReferenceError(const char* message, |
| 533 | Vector<Handle<Object> > args); |
| 534 | MaybeHandle<Object> NewReferenceError(const char* message, |
| 535 | Handle<JSArray> args); |
| 536 | MaybeHandle<Object> NewReferenceError(Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 537 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 538 | MaybeHandle<Object> NewEvalError(const char* message, |
| 539 | Vector<Handle<Object> > args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 540 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 541 | Handle<String> NumberToString(Handle<Object> number, |
| 542 | bool check_number_string_cache = true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 543 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 544 | Handle<String> Uint32ToString(uint32_t value) { |
| 545 | return NumberToString(NewNumberFromUint(value)); |
| 546 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 547 | |
| 548 | enum ApiInstanceType { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 549 | JavaScriptObjectType, |
| 550 | GlobalObjectType, |
| 551 | GlobalProxyType |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 552 | }; |
| 553 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 554 | Handle<JSFunction> CreateApiFunction( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 555 | Handle<FunctionTemplateInfo> data, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 556 | Handle<Object> prototype, |
| 557 | ApiInstanceType type = JavaScriptObjectType); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 558 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 559 | Handle<JSFunction> InstallMembers(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 560 | |
| 561 | // Installs interceptors on the instance. 'desc' is a function template, |
| 562 | // and instance is an object instance created by the function of this |
| 563 | // function template. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 564 | MUST_USE_RESULT MaybeHandle<FunctionTemplateInfo> ConfigureInstance( |
| 565 | Handle<FunctionTemplateInfo> desc, Handle<JSObject> instance); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 566 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 567 | #define ROOT_ACCESSOR(type, name, camel_name) \ |
| 568 | inline Handle<type> name() { \ |
| 569 | return Handle<type>(bit_cast<type**>( \ |
| 570 | &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 571 | } |
| 572 | ROOT_LIST(ROOT_ACCESSOR) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 573 | #undef ROOT_ACCESSOR |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 574 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 575 | #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \ |
| 576 | inline Handle<Map> name##_map() { \ |
| 577 | return Handle<Map>(bit_cast<Map**>( \ |
| 578 | &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 579 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 580 | STRUCT_LIST(STRUCT_MAP_ACCESSOR) |
| 581 | #undef STRUCT_MAP_ACCESSOR |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 582 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 583 | #define STRING_ACCESSOR(name, str) \ |
| 584 | inline Handle<String> name() { \ |
| 585 | return Handle<String>(bit_cast<String**>( \ |
| 586 | &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \ |
| 587 | } |
| 588 | INTERNALIZED_STRING_LIST(STRING_ACCESSOR) |
| 589 | #undef STRING_ACCESSOR |
| 590 | |
| 591 | inline void set_string_table(Handle<StringTable> table) { |
| 592 | isolate()->heap()->set_string_table(*table); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 595 | Handle<String> hidden_string() { |
| 596 | return Handle<String>(&isolate()->heap()->hidden_string_); |
| 597 | } |
| 598 | |
| 599 | // Allocates a new SharedFunctionInfo object. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 600 | Handle<SharedFunctionInfo> NewSharedFunctionInfo( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 601 | Handle<String> name, int number_of_literals, FunctionKind kind, |
| 602 | Handle<Code> code, Handle<ScopeInfo> scope_info, |
| 603 | Handle<TypeFeedbackVector> feedback_vector); |
| 604 | Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name, |
| 605 | MaybeHandle<Code> code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 606 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 607 | // Allocate a new type feedback vector |
| 608 | Handle<TypeFeedbackVector> NewTypeFeedbackVector(int slot_count); |
| 609 | |
| 610 | // Allocates a new JSMessageObject object. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 611 | Handle<JSMessageObject> NewJSMessageObject( |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 612 | Handle<String> type, |
| 613 | Handle<JSArray> arguments, |
| 614 | int start_position, |
| 615 | int end_position, |
| 616 | Handle<Object> script, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 617 | Handle<Object> stack_frames); |
| 618 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 619 | Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 620 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 621 | // Return a map using the map cache in the native context. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 622 | // The key the an ordered set of property names. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 623 | Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context, |
| 624 | Handle<FixedArray> keys); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 625 | |
| 626 | // Creates a new FixedArray that holds the data associated with the |
| 627 | // atom regexp and stores it in the regexp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 628 | void SetRegExpAtomData(Handle<JSRegExp> regexp, |
| 629 | JSRegExp::Type type, |
| 630 | Handle<String> source, |
| 631 | JSRegExp::Flags flags, |
| 632 | Handle<Object> match_pattern); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 633 | |
| 634 | // Creates a new FixedArray that holds the data associated with the |
| 635 | // irregexp regexp and stores it in the regexp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 636 | void SetRegExpIrregexpData(Handle<JSRegExp> regexp, |
| 637 | JSRegExp::Type type, |
| 638 | Handle<String> source, |
| 639 | JSRegExp::Flags flags, |
| 640 | int capture_count); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 641 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 642 | // Returns the value for a known global constant (a property of the global |
| 643 | // object which is neither configurable nor writable) like 'undefined'. |
| 644 | // Returns a null handle when the given name is unknown. |
| 645 | Handle<Object> GlobalConstantFor(Handle<String> name); |
| 646 | |
| 647 | // Converts the given boolean condition to JavaScript boolean value. |
| 648 | Handle<Object> ToBoolean(bool value); |
| 649 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 650 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 651 | Isolate* isolate() { return reinterpret_cast<Isolate*>(this); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 652 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 653 | // Creates a heap object based on the map. The fields of the heap object are |
| 654 | // not initialized by New<>() functions. It's the responsibility of the caller |
| 655 | // to do that. |
| 656 | template<typename T> |
| 657 | Handle<T> New(Handle<Map> map, AllocationSpace space); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 658 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 659 | template<typename T> |
| 660 | Handle<T> New(Handle<Map> map, |
| 661 | AllocationSpace space, |
| 662 | Handle<AllocationSite> allocation_site); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 663 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 664 | // Creates a code object that is not yet fully initialized yet. |
| 665 | inline Handle<Code> NewCodeRaw(int object_size, bool immovable); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 666 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 667 | // Create a new map cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 668 | Handle<MapCache> NewMapCache(int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 669 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 670 | // Update the map cache in the native context with (keys, map) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 671 | Handle<MapCache> AddToMapCache(Handle<Context> context, |
| 672 | Handle<FixedArray> keys, |
| 673 | Handle<Map> map); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 674 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 675 | // Attempt to find the number in a small cache. If we finds it, return |
| 676 | // the string representation of the number. Otherwise return undefined. |
| 677 | Handle<Object> GetNumberStringCache(Handle<Object> number); |
| 678 | |
| 679 | // Update the cache with a new number-string pair. |
| 680 | void SetNumberStringCache(Handle<Object> number, Handle<String> string); |
| 681 | |
| 682 | // Initializes a function with a shared part and prototype. |
| 683 | // Note: this code was factored out of NewFunction such that other parts of |
| 684 | // the VM could use it. Specifically, a function that creates instances of |
| 685 | // type JS_FUNCTION_TYPE benefit from the use of this function. |
| 686 | inline void InitializeFunction(Handle<JSFunction> function, |
| 687 | Handle<SharedFunctionInfo> info, |
| 688 | Handle<Context> context); |
| 689 | |
| 690 | // Creates a function initialized with a shared part. |
| 691 | Handle<JSFunction> NewFunction(Handle<Map> map, |
| 692 | Handle<SharedFunctionInfo> info, |
| 693 | Handle<Context> context, |
| 694 | PretenureFlag pretenure = TENURED); |
| 695 | |
| 696 | Handle<JSFunction> NewFunction(Handle<Map> map, |
| 697 | Handle<String> name, |
| 698 | MaybeHandle<Code> maybe_code); |
| 699 | |
| 700 | // Reinitialize a JSProxy into an (empty) JS object of respective type and |
| 701 | // size, but keeping the original prototype. The receiver must have at least |
| 702 | // the size of the new object. The object is reinitialized and behaves as an |
| 703 | // object that has been freshly allocated. |
| 704 | void ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, int size); |
| 705 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 706 | |
| 707 | } } // namespace v8::internal |
| 708 | |
| 709 | #endif // V8_FACTORY_H_ |