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