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" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 9 | #include "src/messages.h" |
| 10 | #include "src/type-feedback-vector.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 15 | // Interface for handle based allocation. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 16 | class Factory final { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 17 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 18 | Handle<Oddball> NewOddball(Handle<Map> map, const char* to_string, |
| 19 | Handle<Object> to_number, const char* type_of, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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<OrderedHashSet> NewOrderedHashSet(); |
| 48 | Handle<OrderedHashMap> NewOrderedHashMap(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 49 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 50 | // Create a new boxed value. |
| 51 | Handle<Box> NewBox(Handle<Object> value); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 52 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | // Create a new PrototypeInfo struct. |
| 54 | Handle<PrototypeInfo> NewPrototypeInfo(); |
| 55 | |
| 56 | // Create a new SloppyBlockWithEvalContextExtension struct. |
| 57 | Handle<SloppyBlockWithEvalContextExtension> |
| 58 | NewSloppyBlockWithEvalContextExtension(Handle<ScopeInfo> scope_info, |
| 59 | Handle<JSObject> extension); |
| 60 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 61 | // Create a pre-tenured empty AccessorPair. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 62 | Handle<AccessorPair> NewAccessorPair(); |
| 63 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 64 | // Create an empty TypeFeedbackInfo. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 65 | Handle<TypeFeedbackInfo> NewTypeFeedbackInfo(); |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 66 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | // Finds the internalized copy for string in the string table. |
| 68 | // If not found, a new string is added to the table and returned. |
| 69 | Handle<String> InternalizeUtf8String(Vector<const char> str); |
| 70 | Handle<String> InternalizeUtf8String(const char* str) { |
| 71 | return InternalizeUtf8String(CStrVector(str)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 72 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 73 | Handle<String> InternalizeString(Handle<String> str); |
| 74 | Handle<String> InternalizeOneByteString(Vector<const uint8_t> str); |
| 75 | Handle<String> InternalizeOneByteString( |
| 76 | Handle<SeqOneByteString>, int from, int length); |
| 77 | |
| 78 | Handle<String> InternalizeTwoByteString(Vector<const uc16> str); |
| 79 | |
| 80 | template<class StringTableKey> |
| 81 | Handle<String> InternalizeStringWithKey(StringTableKey* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 82 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 83 | Handle<Name> InternalizeName(Handle<Name> name); |
| 84 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 85 | |
| 86 | // String creation functions. Most of the string creation functions take |
| 87 | // a Heap::PretenureFlag argument to optionally request that they be |
| 88 | // allocated in the old generation. The pretenure flag defaults to |
| 89 | // DONT_TENURE. |
| 90 | // |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 91 | // Creates a new String object. There are two String encodings: one-byte and |
| 92 | // two-byte. One should choose between the three string factory functions |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 93 | // based on the encoding of the string buffer that the string is |
| 94 | // initialized from. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 95 | // - ...FromOneByte initializes the string from a buffer that is Latin1 |
| 96 | // encoded (it does not check that the buffer is Latin1 encoded) and |
| 97 | // the result will be Latin1 encoded. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 98 | // - ...FromUtf8 initializes the string from a buffer that is UTF-8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 99 | // encoded. If the characters are all ASCII characters, the result |
| 100 | // will be Latin1 encoded, otherwise it will converted to two-byte. |
| 101 | // - ...FromTwoByte initializes the string from a buffer that is two-byte |
| 102 | // encoded. If the characters are all Latin1 characters, the result |
| 103 | // 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] | 104 | // |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | // One-byte strings are pretenured when used as keys in the SourceCodeCache. |
| 106 | MUST_USE_RESULT MaybeHandle<String> NewStringFromOneByte( |
| 107 | Vector<const uint8_t> str, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 108 | PretenureFlag pretenure = NOT_TENURED); |
| 109 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 110 | template <size_t N> |
| 111 | inline Handle<String> NewStringFromStaticChars( |
| 112 | const char (&str)[N], PretenureFlag pretenure = NOT_TENURED) { |
| 113 | DCHECK(N == StrLength(str) + 1); |
| 114 | return NewStringFromOneByte(STATIC_CHAR_VECTOR(str), pretenure) |
| 115 | .ToHandleChecked(); |
| 116 | } |
| 117 | |
| 118 | inline Handle<String> NewStringFromAsciiChecked( |
| 119 | const char* str, |
| 120 | PretenureFlag pretenure = NOT_TENURED) { |
| 121 | return NewStringFromOneByte( |
| 122 | OneByteVector(str), pretenure).ToHandleChecked(); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | // Allocates and fully initializes a String. There are two String encodings: |
| 127 | // one-byte and two-byte. One should choose between the threestring |
| 128 | // allocation functions based on the encoding of the string buffer used to |
| 129 | // initialized the string. |
| 130 | // - ...FromOneByte initializes the string from a buffer that is Latin1 |
| 131 | // encoded (it does not check that the buffer is Latin1 encoded) and the |
| 132 | // result will be Latin1 encoded. |
| 133 | // - ...FromUTF8 initializes the string from a buffer that is UTF-8 |
| 134 | // encoded. If the characters are all ASCII characters, the result |
| 135 | // will be Latin1 encoded, otherwise it will converted to two-byte. |
| 136 | // - ...FromTwoByte initializes the string from a buffer that is two-byte |
| 137 | // encoded. If the characters are all Latin1 characters, the |
| 138 | // result will be converted to Latin1, otherwise it will be left as |
| 139 | // two-byte. |
| 140 | |
| 141 | // TODO(dcarney): remove this function. |
| 142 | MUST_USE_RESULT inline MaybeHandle<String> NewStringFromAscii( |
| 143 | Vector<const char> str, |
| 144 | PretenureFlag pretenure = NOT_TENURED) { |
| 145 | return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure); |
| 146 | } |
| 147 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 148 | // UTF8 strings are pretenured when used for regexp literal patterns and |
| 149 | // flags in the parser. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | MUST_USE_RESULT MaybeHandle<String> NewStringFromUtf8( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 151 | Vector<const char> str, |
| 152 | PretenureFlag pretenure = NOT_TENURED); |
| 153 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 154 | MUST_USE_RESULT MaybeHandle<String> NewStringFromTwoByte( |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 155 | Vector<const uc16> str, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 156 | PretenureFlag pretenure = NOT_TENURED); |
| 157 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 158 | // Allocates an internalized string in old space based on the character |
| 159 | // stream. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 160 | Handle<String> NewInternalizedStringFromUtf8(Vector<const char> str, |
| 161 | int chars, uint32_t hash_field); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 163 | Handle<String> NewOneByteInternalizedString(Vector<const uint8_t> str, |
| 164 | uint32_t hash_field); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 165 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 166 | Handle<String> NewOneByteInternalizedSubString( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 167 | Handle<SeqOneByteString> string, int offset, int length, |
| 168 | uint32_t hash_field); |
| 169 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 170 | Handle<String> NewTwoByteInternalizedString(Vector<const uc16> str, |
| 171 | uint32_t hash_field); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 172 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 173 | Handle<String> NewInternalizedStringImpl(Handle<String> string, int chars, |
| 174 | uint32_t hash_field); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 223 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 224 | // Create a global (but otherwise uninitialized) context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 225 | Handle<Context> NewNativeContext(); |
| 226 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 227 | // Create a script context. |
| 228 | Handle<Context> NewScriptContext(Handle<JSFunction> function, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 229 | Handle<ScopeInfo> scope_info); |
| 230 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 231 | // Create an empty script context table. |
| 232 | Handle<ScriptContextTable> NewScriptContextTable(); |
| 233 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 234 | // Create a module context. |
| 235 | Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 236 | |
| 237 | // Create a function context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 238 | Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 239 | |
| 240 | // Create a catch context. |
| 241 | Handle<Context> NewCatchContext(Handle<JSFunction> function, |
| 242 | Handle<Context> previous, |
| 243 | Handle<String> name, |
| 244 | Handle<Object> thrown_object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 245 | |
| 246 | // Create a 'with' context. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 247 | Handle<Context> NewWithContext(Handle<JSFunction> function, |
| 248 | Handle<Context> previous, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 249 | Handle<JSReceiver> extension); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 250 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 251 | // Create a block context. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 252 | Handle<Context> NewBlockContext(Handle<JSFunction> function, |
| 253 | Handle<Context> previous, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 254 | Handle<ScopeInfo> scope_info); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 255 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 256 | // Allocate a new struct. The struct is pretenured (allocated directly in |
| 257 | // the old generation). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 258 | Handle<Struct> NewStruct(InstanceType type); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 259 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 260 | Handle<CodeCache> NewCodeCache(); |
| 261 | |
| 262 | Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry( |
| 263 | int aliased_context_slot); |
| 264 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 265 | Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 266 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 267 | Handle<Script> NewScript(Handle<String> source); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 268 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 269 | // Foreign objects are pretenured when allocated by the bootstrapper. |
| 270 | Handle<Foreign> NewForeign(Address addr, |
| 271 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 272 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 273 | // Allocate a new foreign object. The foreign is pretenured (allocated |
| 274 | // directly in the old generation). |
| 275 | Handle<Foreign> NewForeign(const AccessorDescriptor* foreign); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 276 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 277 | Handle<ByteArray> NewByteArray(int length, |
| 278 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 279 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 280 | Handle<BytecodeArray> NewBytecodeArray(int length, const byte* raw_bytecodes, |
| 281 | int frame_size, int parameter_count, |
| 282 | Handle<FixedArray> constant_pool); |
| 283 | |
| 284 | Handle<FixedTypedArrayBase> NewFixedTypedArrayWithExternalPointer( |
| 285 | int length, ExternalArrayType array_type, void* external_pointer, |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 286 | PretenureFlag pretenure = NOT_TENURED); |
| 287 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 288 | Handle<FixedTypedArrayBase> NewFixedTypedArray( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 289 | int length, ExternalArrayType array_type, bool initialize, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 290 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 291 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 292 | Handle<Cell> NewCell(Handle<Object> value); |
| 293 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 294 | Handle<PropertyCell> NewPropertyCell(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 295 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 296 | Handle<WeakCell> NewWeakCell(Handle<HeapObject> value); |
| 297 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 298 | Handle<TransitionArray> NewTransitionArray(int capacity); |
| 299 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 300 | // Allocate a tenured AllocationSite. It's payload is null. |
| 301 | Handle<AllocationSite> NewAllocationSite(); |
| 302 | |
| 303 | Handle<Map> NewMap( |
| 304 | InstanceType type, |
| 305 | int instance_size, |
| 306 | ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND); |
| 307 | |
| 308 | Handle<HeapObject> NewFillerObject(int size, |
| 309 | bool double_align, |
| 310 | AllocationSpace space); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 311 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 312 | Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 314 | Handle<JSObject> CopyJSObject(Handle<JSObject> object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 315 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 316 | Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object, |
| 317 | Handle<AllocationSite> site); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 318 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 319 | Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array, |
| 320 | Handle<Map> map); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 321 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 322 | Handle<FixedArray> CopyFixedArrayAndGrow( |
| 323 | Handle<FixedArray> array, int grow_by, |
| 324 | PretenureFlag pretenure = NOT_TENURED); |
| 325 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 326 | Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 328 | // This method expects a COW array in new space, and creates a copy |
| 329 | // of it in old space. |
| 330 | Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array); |
| 331 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 332 | Handle<FixedDoubleArray> CopyFixedDoubleArray( |
| 333 | Handle<FixedDoubleArray> array); |
| 334 | |
| 335 | // Numbers (e.g. literals) are pretenured by the parser. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 336 | // The return value may be a smi or a heap number. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 337 | Handle<Object> NewNumber(double value, |
| 338 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 339 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 340 | Handle<Object> NewNumberFromInt(int32_t value, |
| 341 | PretenureFlag pretenure = NOT_TENURED); |
| 342 | Handle<Object> NewNumberFromUint(uint32_t value, |
| 343 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 344 | Handle<Object> NewNumberFromSize(size_t value, |
| 345 | PretenureFlag pretenure = NOT_TENURED) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 346 | // We can't use Smi::IsValid() here because that operates on a signed |
| 347 | // intptr_t, and casting from size_t could create a bogus sign bit. |
| 348 | if (value <= static_cast<size_t>(Smi::kMaxValue)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 349 | return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)), |
| 350 | isolate()); |
| 351 | } |
| 352 | return NewNumber(static_cast<double>(value), pretenure); |
| 353 | } |
| 354 | Handle<HeapNumber> NewHeapNumber(double value, |
| 355 | MutableMode mode = IMMUTABLE, |
| 356 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 357 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 358 | #define SIMD128_NEW_DECL(TYPE, Type, type, lane_count, lane_type) \ |
| 359 | Handle<Type> New##Type(lane_type lanes[lane_count], \ |
| 360 | PretenureFlag pretenure = NOT_TENURED); |
| 361 | SIMD128_TYPES(SIMD128_NEW_DECL) |
| 362 | #undef SIMD128_NEW_DECL |
| 363 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 364 | // These objects are used by the api to create env-independent data |
| 365 | // structures in the heap. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 366 | inline Handle<JSObject> NewNeanderObject() { |
| 367 | return NewJSObjectFromMap(neander_map()); |
| 368 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 369 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 370 | Handle<JSWeakMap> NewJSWeakMap(); |
| 371 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 372 | Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 373 | |
| 374 | // JS objects are pretenured when allocated by the bootstrapper and |
| 375 | // runtime. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 376 | Handle<JSObject> NewJSObject(Handle<JSFunction> constructor, |
| 377 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 378 | // JSObject that should have a memento pointing to the allocation site. |
| 379 | Handle<JSObject> NewJSObjectWithMemento(Handle<JSFunction> constructor, |
| 380 | Handle<AllocationSite> site); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 381 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 382 | // Global objects are pretenured and initialized based on a constructor. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 383 | Handle<JSGlobalObject> NewJSGlobalObject(Handle<JSFunction> constructor); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 384 | |
| 385 | // JS objects are pretenured when allocated by the bootstrapper and |
| 386 | // runtime. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 387 | Handle<JSObject> NewJSObjectFromMap( |
| 388 | Handle<Map> map, |
| 389 | PretenureFlag pretenure = NOT_TENURED, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 390 | Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null()); |
| 391 | |
| 392 | // JS modules are pretenured. |
| 393 | Handle<JSModule> NewJSModule(Handle<Context> context, |
| 394 | Handle<ScopeInfo> scope_info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 395 | |
| 396 | // JS arrays are pretenured when allocated by the parser. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 397 | |
| 398 | // Create a JSArray with no elements. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 399 | Handle<JSArray> NewJSArray(ElementsKind elements_kind, |
| 400 | Strength strength = Strength::WEAK, |
| 401 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 402 | |
| 403 | // Create a JSArray with a specified length and elements initialized |
| 404 | // according to the specified mode. |
| 405 | Handle<JSArray> NewJSArray( |
| 406 | ElementsKind elements_kind, int length, int capacity, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 407 | Strength strength = Strength::WEAK, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 408 | ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS, |
| 409 | PretenureFlag pretenure = NOT_TENURED); |
| 410 | |
| 411 | Handle<JSArray> NewJSArray( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 412 | int capacity, ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND, |
| 413 | Strength strength = Strength::WEAK, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 414 | PretenureFlag pretenure = NOT_TENURED) { |
| 415 | if (capacity != 0) { |
| 416 | elements_kind = GetHoleyElementsKind(elements_kind); |
| 417 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 418 | return NewJSArray(elements_kind, 0, capacity, strength, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 419 | INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure); |
| 420 | } |
| 421 | |
| 422 | // Create a JSArray with the given elements. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 423 | Handle<JSArray> NewJSArrayWithElements(Handle<FixedArrayBase> elements, |
| 424 | ElementsKind elements_kind, int length, |
| 425 | Strength strength = Strength::WEAK, |
| 426 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 427 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 428 | Handle<JSArray> NewJSArrayWithElements( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 429 | Handle<FixedArrayBase> elements, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 430 | ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 431 | Strength strength = Strength::WEAK, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 432 | PretenureFlag pretenure = NOT_TENURED) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 433 | return NewJSArrayWithElements(elements, elements_kind, elements->length(), |
| 434 | strength, pretenure); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 435 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 436 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 437 | void NewJSArrayStorage( |
| 438 | Handle<JSArray> array, |
| 439 | int length, |
| 440 | int capacity, |
| 441 | ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 442 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 443 | Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 444 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 445 | Handle<JSArrayBuffer> NewJSArrayBuffer( |
| 446 | SharedFlag shared = SharedFlag::kNotShared, |
| 447 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 448 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 449 | Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type, |
| 450 | PretenureFlag pretenure = NOT_TENURED); |
| 451 | |
| 452 | Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind, |
| 453 | PretenureFlag pretenure = NOT_TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 454 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 455 | // Creates a new JSTypedArray with the specified buffer. |
| 456 | Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type, |
| 457 | Handle<JSArrayBuffer> buffer, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 458 | size_t byte_offset, size_t length, |
| 459 | PretenureFlag pretenure = NOT_TENURED); |
| 460 | |
| 461 | // Creates a new on-heap JSTypedArray. |
| 462 | Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind, |
| 463 | size_t number_of_elements, |
| 464 | PretenureFlag pretenure = NOT_TENURED); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 465 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 466 | Handle<JSDataView> NewJSDataView(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 467 | Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer, |
| 468 | size_t byte_offset, size_t byte_length); |
| 469 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 470 | Handle<JSMap> NewJSMap(); |
| 471 | Handle<JSSet> NewJSSet(); |
| 472 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 473 | // TODO(aandrey): Maybe these should take table, index and kind arguments. |
| 474 | Handle<JSMapIterator> NewJSMapIterator(); |
| 475 | Handle<JSSetIterator> NewJSSetIterator(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 476 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 477 | // Creates a new JSIteratorResult object with the arguments {value} and |
| 478 | // {done}. Implemented according to ES6 section 7.4.7 CreateIterResultObject. |
| 479 | Handle<JSIteratorResult> NewJSIteratorResult(Handle<Object> value, |
| 480 | Handle<Object> done); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 481 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 482 | // Allocates a bound function. |
| 483 | MaybeHandle<JSBoundFunction> NewJSBoundFunction( |
| 484 | Handle<JSReceiver> target_function, Handle<Object> bound_this, |
| 485 | Vector<Handle<Object>> bound_args); |
| 486 | |
| 487 | // Allocates a Harmony proxy. |
| 488 | Handle<JSProxy> NewJSProxy(Handle<JSReceiver> target, |
| 489 | Handle<JSReceiver> handler); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 490 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 491 | // Reinitialize an JSGlobalProxy based on a constructor. The object |
| 492 | // must have the same size as objects allocated using the |
| 493 | // constructor. The object is reinitialized and behaves as an |
| 494 | // object that has been freshly allocated using the constructor. |
| 495 | void ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> global, |
| 496 | Handle<JSFunction> constructor); |
| 497 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 498 | Handle<JSGlobalProxy> NewUninitializedJSGlobalProxy(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 499 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 500 | Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 501 | Handle<Object> prototype, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 502 | bool read_only_prototype = false, |
| 503 | bool is_strict = false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 504 | Handle<JSFunction> NewFunction(Handle<String> name); |
| 505 | Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 506 | Handle<Code> code, |
| 507 | bool is_strict = false); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 508 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 509 | Handle<JSFunction> NewFunctionFromSharedFunctionInfo( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 510 | Handle<Map> initial_map, Handle<SharedFunctionInfo> function_info, |
| 511 | Handle<Context> context, PretenureFlag pretenure = TENURED); |
| 512 | |
| 513 | Handle<JSFunction> NewFunctionFromSharedFunctionInfo( |
| 514 | Handle<SharedFunctionInfo> function_info, Handle<Context> context, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 515 | PretenureFlag pretenure = TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 516 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 517 | Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code, |
| 518 | Handle<Object> prototype, InstanceType type, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 519 | int instance_size, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 520 | bool read_only_prototype = false, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 521 | bool install_constructor = false, |
| 522 | bool is_strict = false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 523 | Handle<JSFunction> NewFunction(Handle<String> name, |
| 524 | Handle<Code> code, |
| 525 | InstanceType type, |
| 526 | int instance_size); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 527 | Handle<JSFunction> NewFunction(Handle<Map> map, Handle<String> name, |
| 528 | MaybeHandle<Code> maybe_code); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 529 | |
| 530 | // Create a serialized scope info. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 531 | Handle<ScopeInfo> NewScopeInfo(int length); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 532 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 533 | // Create an External object for V8's external API. |
| 534 | Handle<JSObject> NewExternal(void* value); |
| 535 | |
| 536 | // The reference to the Code object is stored in self_reference. |
| 537 | // This allows generated code to reference its own Code object |
| 538 | // by containing this handle. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 539 | Handle<Code> NewCode(const CodeDesc& desc, |
| 540 | Code::Flags flags, |
| 541 | Handle<Object> self_reference, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 542 | bool immovable = false, |
| 543 | bool crankshafted = false, |
| 544 | int prologue_offset = Code::kPrologueOffsetNotSet, |
| 545 | bool is_debug = false); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 546 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 547 | Handle<Code> CopyCode(Handle<Code> code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 548 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 549 | Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 550 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 551 | // Interface for creating error objects. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 552 | Handle<Object> NewError(Handle<JSFunction> constructor, |
| 553 | Handle<String> message); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 554 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 555 | Handle<Object> NewInvalidStringLengthError() { |
| 556 | return NewRangeError(MessageTemplate::kInvalidStringLength); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 557 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 558 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 559 | Handle<Object> NewError(Handle<JSFunction> constructor, |
| 560 | MessageTemplate::Template template_index, |
| 561 | Handle<Object> arg0 = Handle<Object>(), |
| 562 | Handle<Object> arg1 = Handle<Object>(), |
| 563 | Handle<Object> arg2 = Handle<Object>()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 564 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 565 | #define DECLARE_ERROR(NAME) \ |
| 566 | Handle<Object> New##NAME(MessageTemplate::Template template_index, \ |
| 567 | Handle<Object> arg0 = Handle<Object>(), \ |
| 568 | Handle<Object> arg1 = Handle<Object>(), \ |
| 569 | Handle<Object> arg2 = Handle<Object>()); |
| 570 | DECLARE_ERROR(Error) |
| 571 | DECLARE_ERROR(EvalError) |
| 572 | DECLARE_ERROR(RangeError) |
| 573 | DECLARE_ERROR(ReferenceError) |
| 574 | DECLARE_ERROR(SyntaxError) |
| 575 | DECLARE_ERROR(TypeError) |
| 576 | #undef DEFINE_ERROR |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 577 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 578 | Handle<String> NumberToString(Handle<Object> number, |
| 579 | bool check_number_string_cache = true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 580 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 581 | Handle<String> Uint32ToString(uint32_t value) { |
| 582 | return NumberToString(NewNumberFromUint(value)); |
| 583 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 584 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 585 | Handle<JSFunction> InstallMembers(Handle<JSFunction> function); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 586 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 587 | #define ROOT_ACCESSOR(type, name, camel_name) \ |
| 588 | inline Handle<type> name() { \ |
| 589 | return Handle<type>(bit_cast<type**>( \ |
| 590 | &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 591 | } |
| 592 | ROOT_LIST(ROOT_ACCESSOR) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 593 | #undef ROOT_ACCESSOR |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 594 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 595 | #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \ |
| 596 | inline Handle<Map> name##_map() { \ |
| 597 | return Handle<Map>(bit_cast<Map**>( \ |
| 598 | &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 599 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 600 | STRUCT_LIST(STRUCT_MAP_ACCESSOR) |
| 601 | #undef STRUCT_MAP_ACCESSOR |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 602 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 603 | #define STRING_ACCESSOR(name, str) \ |
| 604 | inline Handle<String> name() { \ |
| 605 | return Handle<String>(bit_cast<String**>( \ |
| 606 | &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \ |
| 607 | } |
| 608 | INTERNALIZED_STRING_LIST(STRING_ACCESSOR) |
| 609 | #undef STRING_ACCESSOR |
| 610 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 611 | #define SYMBOL_ACCESSOR(name) \ |
| 612 | inline Handle<Symbol> name() { \ |
| 613 | return Handle<Symbol>(bit_cast<Symbol**>( \ |
| 614 | &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \ |
| 615 | } |
| 616 | PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR) |
| 617 | #undef SYMBOL_ACCESSOR |
| 618 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 619 | #define SYMBOL_ACCESSOR(name, description) \ |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 620 | inline Handle<Symbol> name() { \ |
| 621 | return Handle<Symbol>(bit_cast<Symbol**>( \ |
| 622 | &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \ |
| 623 | } |
| 624 | PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 625 | WELL_KNOWN_SYMBOL_LIST(SYMBOL_ACCESSOR) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 626 | #undef SYMBOL_ACCESSOR |
| 627 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 628 | // Allocates a new SharedFunctionInfo object. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 629 | Handle<SharedFunctionInfo> NewSharedFunctionInfo( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 630 | Handle<String> name, int number_of_literals, FunctionKind kind, |
| 631 | Handle<Code> code, Handle<ScopeInfo> scope_info, |
| 632 | Handle<TypeFeedbackVector> feedback_vector); |
| 633 | Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 634 | MaybeHandle<Code> code, |
| 635 | bool is_constructor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 636 | |
| 637 | // Allocates a new JSMessageObject object. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 638 | Handle<JSMessageObject> NewJSMessageObject(MessageTemplate::Template message, |
| 639 | Handle<Object> argument, |
| 640 | int start_position, |
| 641 | int end_position, |
| 642 | Handle<Object> script, |
| 643 | Handle<Object> stack_frames); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 644 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 645 | Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 646 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 647 | // Return a map for given number of properties using the map cache in the |
| 648 | // native context. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 649 | Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 650 | int number_of_properties, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 651 | bool is_strong, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 652 | bool* is_result_from_cache); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 653 | |
| 654 | // Creates a new FixedArray that holds the data associated with the |
| 655 | // atom regexp and stores it in the regexp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 656 | void SetRegExpAtomData(Handle<JSRegExp> regexp, |
| 657 | JSRegExp::Type type, |
| 658 | Handle<String> source, |
| 659 | JSRegExp::Flags flags, |
| 660 | Handle<Object> match_pattern); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 661 | |
| 662 | // Creates a new FixedArray that holds the data associated with the |
| 663 | // irregexp regexp and stores it in the regexp. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 664 | void SetRegExpIrregexpData(Handle<JSRegExp> regexp, |
| 665 | JSRegExp::Type type, |
| 666 | Handle<String> source, |
| 667 | JSRegExp::Flags flags, |
| 668 | int capture_count); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 669 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 670 | // Returns the value for a known global constant (a property of the global |
| 671 | // object which is neither configurable nor writable) like 'undefined'. |
| 672 | // Returns a null handle when the given name is unknown. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 673 | Handle<Object> GlobalConstantFor(Handle<Name> name); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 674 | |
| 675 | // Converts the given boolean condition to JavaScript boolean value. |
| 676 | Handle<Object> ToBoolean(bool value); |
| 677 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 678 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 679 | Isolate* isolate() { return reinterpret_cast<Isolate*>(this); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 680 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 681 | // Creates a heap object based on the map. The fields of the heap object are |
| 682 | // not initialized by New<>() functions. It's the responsibility of the caller |
| 683 | // to do that. |
| 684 | template<typename T> |
| 685 | Handle<T> New(Handle<Map> map, AllocationSpace space); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 686 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 687 | template<typename T> |
| 688 | Handle<T> New(Handle<Map> map, |
| 689 | AllocationSpace space, |
| 690 | Handle<AllocationSite> allocation_site); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 691 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 692 | // Creates a code object that is not yet fully initialized yet. |
| 693 | inline Handle<Code> NewCodeRaw(int object_size, bool immovable); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 694 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 695 | // Attempt to find the number in a small cache. If we finds it, return |
| 696 | // the string representation of the number. Otherwise return undefined. |
| 697 | Handle<Object> GetNumberStringCache(Handle<Object> number); |
| 698 | |
| 699 | // Update the cache with a new number-string pair. |
| 700 | void SetNumberStringCache(Handle<Object> number, Handle<String> string); |
| 701 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 702 | // Creates a function initialized with a shared part. |
| 703 | Handle<JSFunction> NewFunction(Handle<Map> map, |
| 704 | Handle<SharedFunctionInfo> info, |
| 705 | Handle<Context> context, |
| 706 | PretenureFlag pretenure = TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 707 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 708 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 709 | } // namespace internal |
| 710 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 711 | |
| 712 | #endif // V8_FACTORY_H_ |