blob: 51ba09dd2629db736967b47cc503fbb3eb2e67fa [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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 Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_FACTORY_H_
6#define V8_FACTORY_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/isolate.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009#include "src/messages.h"
10#include "src/type-feedback-vector.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000011
12namespace v8 {
13namespace internal {
14
Emily Bernierd0a1eb72015-03-24 16:35:39 -040015// Interface for handle based allocation.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000016class Factory final {
Steve Blocka7e24c12009-10-30 11:49:00 +000017 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000018 Handle<Oddball> NewOddball(Handle<Map> map, const char* to_string,
Ben Murdochda12d292016-06-02 14:46:10 +010019 Handle<Object> to_number, bool to_boolean,
20 const char* type_of, byte kind);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000021
22 // Allocates a fixed array initialized with undefined values.
Steve Block44f0eee2011-05-26 01:26:41 +010023 Handle<FixedArray> NewFixedArray(
Steve Blocka7e24c12009-10-30 11:49:00 +000024 int size,
25 PretenureFlag pretenure = NOT_TENURED);
26
27 // Allocate a new fixed array with non-existing entries (the hole).
Steve Block44f0eee2011-05-26 01:26:41 +010028 Handle<FixedArray> NewFixedArrayWithHoles(
Steve Block6ded16b2010-05-10 14:33:55 +010029 int size,
30 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +000031
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032 // Allocates an uninitialized fixed array. It must be filled by the caller.
33 Handle<FixedArray> NewUninitializedFixedArray(int size);
34
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000035 // Allocate a new uninitialized fixed double array.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036 // 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 Murdoch3fb3ca82011-12-02 17:19:32 +000039 int size,
40 PretenureFlag pretenure = NOT_TENURED);
41
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042 // Allocate a new fixed double array with hole values.
43 Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles(
44 int size,
45 PretenureFlag pretenure = NOT_TENURED);
Ben Murdochc7cc0282012-03-05 14:35:55 +000046
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047 Handle<OrderedHashSet> NewOrderedHashSet();
48 Handle<OrderedHashMap> NewOrderedHashMap();
Ben Murdoch3ef787d2012-04-12 10:51:47 +010049
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050 // Create a new boxed value.
51 Handle<Box> NewBox(Handle<Object> value);
Ben Murdoch69a99ed2011-11-30 16:03:39 +000052
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000053 // 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 Murdochb8a8cc12014-11-26 15:28:44 +000061 // Create a pre-tenured empty AccessorPair.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010062 Handle<AccessorPair> NewAccessorPair();
63
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064 // Create an empty TypeFeedbackInfo.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010065 Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +010066
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067 // 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 Blocka7e24c12009-10-30 11:49:00 +000072 }
Ben Murdoch097c5b22016-05-18 11:27:45 +010073
Ben Murdochb8a8cc12014-11-26 15:28:44 +000074 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 Blocka7e24c12009-10-30 11:49:00 +000082
Ben Murdoch097c5b22016-05-18 11:27:45 +010083 // 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 Murdoch4a90d5f2016-03-22 12:00:34 +000088
Ben Murdoch097c5b22016-05-18 11:27:45 +010089 Handle<Name> InternalizeName(Handle<Name> name) {
90 if (name->IsUniqueName()) return name;
91 return StringTable::LookupString(isolate(), Handle<String>::cast(name));
92 }
Steve Blocka7e24c12009-10-30 11:49:00 +000093
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 Murdochb8a8cc12014-11-26 15:28:44 +000099 // 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 Blocka7e24c12009-10-30 11:49:00 +0000101 // based on the encoding of the string buffer that the string is
102 // initialized from.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000103 // - ...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 Blocka7e24c12009-10-30 11:49:00 +0000106 // - ...FromUtf8 initializes the string from a buffer that is UTF-8
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107 // 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 Blocka7e24c12009-10-30 11:49:00 +0000112 //
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000113 // 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 Blocka7e24c12009-10-30 11:49:00 +0000116 PretenureFlag pretenure = NOT_TENURED);
117
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000118 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 Blocka7e24c12009-10-30 11:49:00 +0000156 // UTF8 strings are pretenured when used for regexp literal patterns and
157 // flags in the parser.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000158 MUST_USE_RESULT MaybeHandle<String> NewStringFromUtf8(
Steve Blocka7e24c12009-10-30 11:49:00 +0000159 Vector<const char> str,
160 PretenureFlag pretenure = NOT_TENURED);
161
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000162 MUST_USE_RESULT MaybeHandle<String> NewStringFromTwoByte(
Leon Clarkeac952652010-07-15 11:15:24 +0100163 Vector<const uc16> str,
Steve Blocka7e24c12009-10-30 11:49:00 +0000164 PretenureFlag pretenure = NOT_TENURED);
165
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000166 // Allocates an internalized string in old space based on the character
167 // stream.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000168 Handle<String> NewInternalizedStringFromUtf8(Vector<const char> str,
169 int chars, uint32_t hash_field);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000170
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000171 Handle<String> NewOneByteInternalizedString(Vector<const uint8_t> str,
172 uint32_t hash_field);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000173
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000174 Handle<String> NewOneByteInternalizedSubString(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000175 Handle<SeqOneByteString> string, int offset, int length,
176 uint32_t hash_field);
177
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000178 Handle<String> NewTwoByteInternalizedString(Vector<const uc16> str,
179 uint32_t hash_field);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000180
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000181 Handle<String> NewInternalizedStringImpl(Handle<String> string, int chars,
182 uint32_t hash_field);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000183
184 // Compute the matching internalized string map for a string if possible.
185 // Empty handle is returned if string is in new space or not flattened.
186 MUST_USE_RESULT MaybeHandle<Map> InternalizedStringMapForString(
187 Handle<String> string);
188
189 // Allocates and partially initializes an one-byte or two-byte String. The
Leon Clarkeac952652010-07-15 11:15:24 +0100190 // characters of the string are uninitialized. Currently used in regexp code
191 // only, where they are pretenured.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000192 MUST_USE_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString(
Leon Clarkeac952652010-07-15 11:15:24 +0100193 int length,
194 PretenureFlag pretenure = NOT_TENURED);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000195 MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString(
Steve Blocka7e24c12009-10-30 11:49:00 +0000196 int length,
197 PretenureFlag pretenure = NOT_TENURED);
198
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000199 // Creates a single character string where the character has given code.
200 // A cache is used for Latin1 codes.
201 Handle<String> LookupSingleCharacterStringFromCode(uint32_t code);
202
Steve Blocka7e24c12009-10-30 11:49:00 +0000203 // Create a new cons string object which consists of a pair of strings.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000204 MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left,
205 Handle<String> right);
Steve Blocka7e24c12009-10-30 11:49:00 +0000206
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000207 // Create a new string object which holds a proper substring of a string.
208 Handle<String> NewProperSubString(Handle<String> str,
209 int begin,
210 int end);
211
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000212 // Create a new string object which holds a substring of a string.
213 Handle<String> NewSubString(Handle<String> str, int begin, int end) {
214 if (begin == 0 && end == str->length()) return str;
215 return NewProperSubString(str, begin, end);
216 }
217
Steve Blocka7e24c12009-10-30 11:49:00 +0000218 // Creates a new external String object. There are two String encodings
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000219 // in the system: one-byte and two-byte. Unlike other String types, it does
Steve Blocka7e24c12009-10-30 11:49:00 +0000220 // not make sense to have a UTF-8 factory function for external strings,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000221 // because we cannot change the underlying buffer. Note that these strings
222 // are backed by a string resource that resides outside the V8 heap.
223 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromOneByte(
224 const ExternalOneByteString::Resource* resource);
225 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromTwoByte(
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100226 const ExternalTwoByteString::Resource* resource);
Steve Blocka7e24c12009-10-30 11:49:00 +0000227
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000228 // Create a symbol.
229 Handle<Symbol> NewSymbol();
230 Handle<Symbol> NewPrivateSymbol();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000231
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 // Create a global (but otherwise uninitialized) context.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000233 Handle<Context> NewNativeContext();
234
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400235 // Create a script context.
236 Handle<Context> NewScriptContext(Handle<JSFunction> function,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000237 Handle<ScopeInfo> scope_info);
238
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400239 // Create an empty script context table.
240 Handle<ScriptContextTable> NewScriptContextTable();
241
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242 // Create a module context.
243 Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000244
245 // Create a function context.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000246 Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000247
248 // Create a catch context.
249 Handle<Context> NewCatchContext(Handle<JSFunction> function,
250 Handle<Context> previous,
251 Handle<String> name,
252 Handle<Object> thrown_object);
Steve Blocka7e24c12009-10-30 11:49:00 +0000253
254 // Create a 'with' context.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000255 Handle<Context> NewWithContext(Handle<JSFunction> function,
256 Handle<Context> previous,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000257 Handle<JSReceiver> extension);
Steve Blocka7e24c12009-10-30 11:49:00 +0000258
Ben Murdochda12d292016-06-02 14:46:10 +0100259 Handle<Context> NewDebugEvaluateContext(Handle<Context> previous,
260 Handle<JSReceiver> extension,
261 Handle<Context> wrapped,
262 Handle<StringSet> whitelist);
263
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000264 // Create a block context.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000265 Handle<Context> NewBlockContext(Handle<JSFunction> function,
266 Handle<Context> previous,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100267 Handle<ScopeInfo> scope_info);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000268
Steve Blocka7e24c12009-10-30 11:49:00 +0000269 // Allocate a new struct. The struct is pretenured (allocated directly in
270 // the old generation).
Steve Block44f0eee2011-05-26 01:26:41 +0100271 Handle<Struct> NewStruct(InstanceType type);
Steve Blocka7e24c12009-10-30 11:49:00 +0000272
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000273 Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
274 int aliased_context_slot);
275
Ben Murdoch097c5b22016-05-18 11:27:45 +0100276 Handle<AccessorInfo> NewAccessorInfo();
Steve Blocka7e24c12009-10-30 11:49:00 +0000277
Steve Block44f0eee2011-05-26 01:26:41 +0100278 Handle<Script> NewScript(Handle<String> source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000279
Ben Murdoch257744e2011-11-30 15:57:28 +0000280 // Foreign objects are pretenured when allocated by the bootstrapper.
281 Handle<Foreign> NewForeign(Address addr,
282 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000283
Ben Murdoch257744e2011-11-30 15:57:28 +0000284 // Allocate a new foreign object. The foreign is pretenured (allocated
285 // directly in the old generation).
286 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
Steve Blocka7e24c12009-10-30 11:49:00 +0000287
Steve Block44f0eee2011-05-26 01:26:41 +0100288 Handle<ByteArray> NewByteArray(int length,
289 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000290
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000291 Handle<BytecodeArray> NewBytecodeArray(int length, const byte* raw_bytecodes,
292 int frame_size, int parameter_count,
293 Handle<FixedArray> constant_pool);
294
295 Handle<FixedTypedArrayBase> NewFixedTypedArrayWithExternalPointer(
296 int length, ExternalArrayType array_type, void* external_pointer,
Steve Block3ce2e202009-11-05 08:53:23 +0000297 PretenureFlag pretenure = NOT_TENURED);
298
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000299 Handle<FixedTypedArrayBase> NewFixedTypedArray(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000300 int length, ExternalArrayType array_type, bool initialize,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000301 PretenureFlag pretenure = NOT_TENURED);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100302
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000303 Handle<Cell> NewCell(Handle<Object> value);
304
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000305 Handle<PropertyCell> NewPropertyCell();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000306
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400307 Handle<WeakCell> NewWeakCell(Handle<HeapObject> value);
308
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000309 Handle<TransitionArray> NewTransitionArray(int capacity);
310
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000311 // Allocate a tenured AllocationSite. It's payload is null.
312 Handle<AllocationSite> NewAllocationSite();
313
314 Handle<Map> NewMap(
315 InstanceType type,
316 int instance_size,
317 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
318
319 Handle<HeapObject> NewFillerObject(int size,
320 bool double_align,
321 AllocationSpace space);
Steve Blocka7e24c12009-10-30 11:49:00 +0000322
Steve Block44f0eee2011-05-26 01:26:41 +0100323 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000324
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000325 Handle<JSObject> CopyJSObject(Handle<JSObject> object);
Steve Blocka7e24c12009-10-30 11:49:00 +0000326
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000327 Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
328 Handle<AllocationSite> site);
Steve Blocka7e24c12009-10-30 11:49:00 +0000329
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000330 Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
331 Handle<Map> map);
Steve Block1e0659c2011-05-24 12:43:12 +0100332
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000333 Handle<FixedArray> CopyFixedArrayAndGrow(
334 Handle<FixedArray> array, int grow_by,
335 PretenureFlag pretenure = NOT_TENURED);
336
Ben Murdoch097c5b22016-05-18 11:27:45 +0100337 Handle<FixedArray> CopyFixedArrayUpTo(Handle<FixedArray> array, int new_len,
338 PretenureFlag pretenure = NOT_TENURED);
339
Steve Block44f0eee2011-05-26 01:26:41 +0100340 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
Steve Blocka7e24c12009-10-30 11:49:00 +0000341
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000342 // This method expects a COW array in new space, and creates a copy
343 // of it in old space.
344 Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
345
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100346 Handle<FixedDoubleArray> CopyFixedDoubleArray(
347 Handle<FixedDoubleArray> array);
348
349 // Numbers (e.g. literals) are pretenured by the parser.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000350 // The return value may be a smi or a heap number.
Steve Block44f0eee2011-05-26 01:26:41 +0100351 Handle<Object> NewNumber(double value,
352 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000353
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100354 Handle<Object> NewNumberFromInt(int32_t value,
355 PretenureFlag pretenure = NOT_TENURED);
356 Handle<Object> NewNumberFromUint(uint32_t value,
357 PretenureFlag pretenure = NOT_TENURED);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000358 Handle<Object> NewNumberFromSize(size_t value,
359 PretenureFlag pretenure = NOT_TENURED) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000360 // We can't use Smi::IsValid() here because that operates on a signed
361 // intptr_t, and casting from size_t could create a bogus sign bit.
362 if (value <= static_cast<size_t>(Smi::kMaxValue)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000363 return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
364 isolate());
365 }
366 return NewNumber(static_cast<double>(value), pretenure);
367 }
368 Handle<HeapNumber> NewHeapNumber(double value,
369 MutableMode mode = IMMUTABLE,
370 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000371
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000372#define SIMD128_NEW_DECL(TYPE, Type, type, lane_count, lane_type) \
373 Handle<Type> New##Type(lane_type lanes[lane_count], \
374 PretenureFlag pretenure = NOT_TENURED);
375 SIMD128_TYPES(SIMD128_NEW_DECL)
376#undef SIMD128_NEW_DECL
377
Steve Blocka7e24c12009-10-30 11:49:00 +0000378 // These objects are used by the api to create env-independent data
379 // structures in the heap.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000380 inline Handle<JSObject> NewNeanderObject() {
381 return NewJSObjectFromMap(neander_map());
382 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000383
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000384 Handle<JSWeakMap> NewJSWeakMap();
385
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000386 Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000387
388 // JS objects are pretenured when allocated by the bootstrapper and
389 // runtime.
Steve Block44f0eee2011-05-26 01:26:41 +0100390 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
391 PretenureFlag pretenure = NOT_TENURED);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000392 // JSObject that should have a memento pointing to the allocation site.
393 Handle<JSObject> NewJSObjectWithMemento(Handle<JSFunction> constructor,
394 Handle<AllocationSite> site);
Ben Murdochda12d292016-06-02 14:46:10 +0100395 // JSObject without a prototype.
396 Handle<JSObject> NewJSObjectWithNullProto();
Steve Blocka7e24c12009-10-30 11:49:00 +0000397
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000398 // Global objects are pretenured and initialized based on a constructor.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000399 Handle<JSGlobalObject> NewJSGlobalObject(Handle<JSFunction> constructor);
Steve Blocka7e24c12009-10-30 11:49:00 +0000400
401 // JS objects are pretenured when allocated by the bootstrapper and
402 // runtime.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000403 Handle<JSObject> NewJSObjectFromMap(
404 Handle<Map> map,
405 PretenureFlag pretenure = NOT_TENURED,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000406 Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
407
408 // JS modules are pretenured.
409 Handle<JSModule> NewJSModule(Handle<Context> context,
410 Handle<ScopeInfo> scope_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000411
412 // JS arrays are pretenured when allocated by the parser.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000413
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000414 // Create a JSArray with a specified length and elements initialized
415 // according to the specified mode.
416 Handle<JSArray> NewJSArray(
417 ElementsKind elements_kind, int length, int capacity,
418 ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS,
419 PretenureFlag pretenure = NOT_TENURED);
420
421 Handle<JSArray> NewJSArray(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000422 int capacity, ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000423 PretenureFlag pretenure = NOT_TENURED) {
424 if (capacity != 0) {
425 elements_kind = GetHoleyElementsKind(elements_kind);
426 }
Ben Murdochda12d292016-06-02 14:46:10 +0100427 return NewJSArray(elements_kind, 0, capacity,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000428 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
429 }
430
431 // Create a JSArray with the given elements.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000432 Handle<JSArray> NewJSArrayWithElements(Handle<FixedArrayBase> elements,
433 ElementsKind elements_kind, int length,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000434 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000435
Steve Block44f0eee2011-05-26 01:26:41 +0100436 Handle<JSArray> NewJSArrayWithElements(
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100437 Handle<FixedArrayBase> elements,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000438 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
439 PretenureFlag pretenure = NOT_TENURED) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000440 return NewJSArrayWithElements(elements, elements_kind, elements->length(),
Ben Murdochda12d292016-06-02 14:46:10 +0100441 pretenure);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000442 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000443
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000444 void NewJSArrayStorage(
445 Handle<JSArray> array,
446 int length,
447 int capacity,
448 ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100449
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000450 Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100451
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000452 Handle<JSArrayBuffer> NewJSArrayBuffer(
453 SharedFlag shared = SharedFlag::kNotShared,
454 PretenureFlag pretenure = NOT_TENURED);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100455
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000456 Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
457 PretenureFlag pretenure = NOT_TENURED);
458
459 Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
460 PretenureFlag pretenure = NOT_TENURED);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000461
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400462 // Creates a new JSTypedArray with the specified buffer.
463 Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
464 Handle<JSArrayBuffer> buffer,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000465 size_t byte_offset, size_t length,
466 PretenureFlag pretenure = NOT_TENURED);
467
468 // Creates a new on-heap JSTypedArray.
469 Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
470 size_t number_of_elements,
471 PretenureFlag pretenure = NOT_TENURED);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400472
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000473 Handle<JSDataView> NewJSDataView();
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400474 Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer,
475 size_t byte_offset, size_t byte_length);
476
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000477 Handle<JSMap> NewJSMap();
478 Handle<JSSet> NewJSSet();
479
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400480 // TODO(aandrey): Maybe these should take table, index and kind arguments.
481 Handle<JSMapIterator> NewJSMapIterator();
482 Handle<JSSetIterator> NewJSSetIterator();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000483
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000484 // Allocates a bound function.
485 MaybeHandle<JSBoundFunction> NewJSBoundFunction(
486 Handle<JSReceiver> target_function, Handle<Object> bound_this,
487 Vector<Handle<Object>> bound_args);
488
489 // Allocates a Harmony proxy.
490 Handle<JSProxy> NewJSProxy(Handle<JSReceiver> target,
491 Handle<JSReceiver> handler);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000492
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000493 // Reinitialize an JSGlobalProxy based on a constructor. The object
494 // must have the same size as objects allocated using the
495 // constructor. The object is reinitialized and behaves as an
496 // object that has been freshly allocated using the constructor.
497 void ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> global,
498 Handle<JSFunction> constructor);
499
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000500 Handle<JSGlobalProxy> NewUninitializedJSGlobalProxy();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100501
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000502 Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000503 Handle<Object> prototype,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000504 bool read_only_prototype = false,
505 bool is_strict = false);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000506 Handle<JSFunction> NewFunction(Handle<String> name);
507 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000508 Handle<Code> code,
509 bool is_strict = false);
Steve Block6ded16b2010-05-10 14:33:55 +0100510
Steve Block44f0eee2011-05-26 01:26:41 +0100511 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000512 Handle<Map> initial_map, Handle<SharedFunctionInfo> function_info,
513 Handle<Context> context, PretenureFlag pretenure = TENURED);
514
515 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
516 Handle<SharedFunctionInfo> function_info, Handle<Context> context,
Leon Clarkee46be812010-01-19 14:06:41 +0000517 PretenureFlag pretenure = TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000518
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400519 Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
520 Handle<Object> prototype, InstanceType type,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000521 int instance_size,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400522 bool read_only_prototype = false,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000523 bool install_constructor = false,
524 bool is_strict = false);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000525 Handle<JSFunction> NewFunction(Handle<String> name,
526 Handle<Code> code,
527 InstanceType type,
528 int instance_size);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000529 Handle<JSFunction> NewFunction(Handle<Map> map, Handle<String> name,
530 MaybeHandle<Code> maybe_code);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000531
532 // Create a serialized scope info.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100533 Handle<ScopeInfo> NewScopeInfo(int length);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000534
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000535 // Create an External object for V8's external API.
536 Handle<JSObject> NewExternal(void* value);
537
538 // The reference to the Code object is stored in self_reference.
539 // This allows generated code to reference its own Code object
540 // by containing this handle.
Steve Block44f0eee2011-05-26 01:26:41 +0100541 Handle<Code> NewCode(const CodeDesc& desc,
542 Code::Flags flags,
543 Handle<Object> self_reference,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000544 bool immovable = false,
545 bool crankshafted = false,
546 int prologue_offset = Code::kPrologueOffsetNotSet,
547 bool is_debug = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000548
Steve Block44f0eee2011-05-26 01:26:41 +0100549 Handle<Code> CopyCode(Handle<Code> code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000550
Steve Block44f0eee2011-05-26 01:26:41 +0100551 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
Steve Block6ded16b2010-05-10 14:33:55 +0100552
Ben Murdoch097c5b22016-05-18 11:27:45 +0100553 Handle<BytecodeArray> CopyBytecodeArray(Handle<BytecodeArray>);
554
Steve Blocka7e24c12009-10-30 11:49:00 +0000555 // Interface for creating error objects.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000556 Handle<Object> NewError(Handle<JSFunction> constructor,
557 Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000558
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000559 Handle<Object> NewInvalidStringLengthError() {
560 return NewRangeError(MessageTemplate::kInvalidStringLength);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000561 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000562
Ben Murdochc5610432016-08-08 18:44:38 +0100563 Handle<Object> NewURIError() {
564 return NewError(isolate()->uri_error_function(),
565 MessageTemplate::kURIMalformed);
566 }
567
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000568 Handle<Object> NewError(Handle<JSFunction> constructor,
569 MessageTemplate::Template template_index,
570 Handle<Object> arg0 = Handle<Object>(),
571 Handle<Object> arg1 = Handle<Object>(),
572 Handle<Object> arg2 = Handle<Object>());
Steve Blocka7e24c12009-10-30 11:49:00 +0000573
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000574#define DECLARE_ERROR(NAME) \
575 Handle<Object> New##NAME(MessageTemplate::Template template_index, \
576 Handle<Object> arg0 = Handle<Object>(), \
577 Handle<Object> arg1 = Handle<Object>(), \
578 Handle<Object> arg2 = Handle<Object>());
579 DECLARE_ERROR(Error)
580 DECLARE_ERROR(EvalError)
581 DECLARE_ERROR(RangeError)
582 DECLARE_ERROR(ReferenceError)
583 DECLARE_ERROR(SyntaxError)
584 DECLARE_ERROR(TypeError)
585#undef DEFINE_ERROR
Steve Blocka7e24c12009-10-30 11:49:00 +0000586
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000587 Handle<String> NumberToString(Handle<Object> number,
588 bool check_number_string_cache = true);
Steve Blocka7e24c12009-10-30 11:49:00 +0000589
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000590 Handle<String> Uint32ToString(uint32_t value) {
591 return NumberToString(NewNumberFromUint(value));
592 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000593
Steve Block44f0eee2011-05-26 01:26:41 +0100594 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000595
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000596#define ROOT_ACCESSOR(type, name, camel_name) \
597 inline Handle<type> name() { \
598 return Handle<type>(bit_cast<type**>( \
599 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000600 }
601 ROOT_LIST(ROOT_ACCESSOR)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000602#undef ROOT_ACCESSOR
Steve Blocka7e24c12009-10-30 11:49:00 +0000603
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000604#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
605 inline Handle<Map> name##_map() { \
606 return Handle<Map>(bit_cast<Map**>( \
607 &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000608 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000609 STRUCT_LIST(STRUCT_MAP_ACCESSOR)
610#undef STRUCT_MAP_ACCESSOR
Steve Blocka7e24c12009-10-30 11:49:00 +0000611
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000612#define STRING_ACCESSOR(name, str) \
613 inline Handle<String> name() { \
614 return Handle<String>(bit_cast<String**>( \
615 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
616 }
617 INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
618#undef STRING_ACCESSOR
619
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400620#define SYMBOL_ACCESSOR(name) \
621 inline Handle<Symbol> name() { \
622 return Handle<Symbol>(bit_cast<Symbol**>( \
623 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
624 }
625 PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
626#undef SYMBOL_ACCESSOR
627
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000628#define SYMBOL_ACCESSOR(name, description) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400629 inline Handle<Symbol> name() { \
630 return Handle<Symbol>(bit_cast<Symbol**>( \
631 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
632 }
633 PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000634 WELL_KNOWN_SYMBOL_LIST(SYMBOL_ACCESSOR)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400635#undef SYMBOL_ACCESSOR
636
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000637 // Allocates a new SharedFunctionInfo object.
Steve Block44f0eee2011-05-26 01:26:41 +0100638 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000639 Handle<String> name, int number_of_literals, FunctionKind kind,
Ben Murdochda12d292016-06-02 14:46:10 +0100640 Handle<Code> code, Handle<ScopeInfo> scope_info);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000641 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000642 MaybeHandle<Code> code,
643 bool is_constructor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000644
645 // Allocates a new JSMessageObject object.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000646 Handle<JSMessageObject> NewJSMessageObject(MessageTemplate::Template message,
647 Handle<Object> argument,
648 int start_position,
649 int end_position,
650 Handle<Object> script,
651 Handle<Object> stack_frames);
Steve Block1e0659c2011-05-24 12:43:12 +0100652
Steve Block44f0eee2011-05-26 01:26:41 +0100653 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000654
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400655 // Return a map for given number of properties using the map cache in the
656 // native context.
Steve Block44f0eee2011-05-26 01:26:41 +0100657 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400658 int number_of_properties,
659 bool* is_result_from_cache);
Steve Blocka7e24c12009-10-30 11:49:00 +0000660
661 // Creates a new FixedArray that holds the data associated with the
662 // atom regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100663 void SetRegExpAtomData(Handle<JSRegExp> regexp,
664 JSRegExp::Type type,
665 Handle<String> source,
666 JSRegExp::Flags flags,
667 Handle<Object> match_pattern);
Steve Blocka7e24c12009-10-30 11:49:00 +0000668
669 // Creates a new FixedArray that holds the data associated with the
670 // irregexp regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100671 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
672 JSRegExp::Type type,
673 Handle<String> source,
674 JSRegExp::Flags flags,
675 int capture_count);
Steve Blocka7e24c12009-10-30 11:49:00 +0000676
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100677 // Returns the value for a known global constant (a property of the global
678 // object which is neither configurable nor writable) like 'undefined'.
679 // Returns a null handle when the given name is unknown.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000680 Handle<Object> GlobalConstantFor(Handle<Name> name);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100681
682 // Converts the given boolean condition to JavaScript boolean value.
683 Handle<Object> ToBoolean(bool value);
684
Steve Blocka7e24c12009-10-30 11:49:00 +0000685 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100686 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000687
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000688 // Creates a heap object based on the map. The fields of the heap object are
689 // not initialized by New<>() functions. It's the responsibility of the caller
690 // to do that.
691 template<typename T>
692 Handle<T> New(Handle<Map> map, AllocationSpace space);
Steve Block6ded16b2010-05-10 14:33:55 +0100693
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000694 template<typename T>
695 Handle<T> New(Handle<Map> map,
696 AllocationSpace space,
697 Handle<AllocationSite> allocation_site);
Steve Block44f0eee2011-05-26 01:26:41 +0100698
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000699 // Creates a code object that is not yet fully initialized yet.
700 inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
Steve Blocka7e24c12009-10-30 11:49:00 +0000701
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000702 // Attempt to find the number in a small cache. If we finds it, return
703 // the string representation of the number. Otherwise return undefined.
704 Handle<Object> GetNumberStringCache(Handle<Object> number);
705
706 // Update the cache with a new number-string pair.
707 void SetNumberStringCache(Handle<Object> number, Handle<String> string);
708
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000709 // Creates a function initialized with a shared part.
710 Handle<JSFunction> NewFunction(Handle<Map> map,
711 Handle<SharedFunctionInfo> info,
712 Handle<Context> context,
713 PretenureFlag pretenure = TENURED);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100714
715 // Create a JSArray with no elements and no length.
716 Handle<JSArray> NewJSArray(ElementsKind elements_kind,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100717 PretenureFlag pretenure = NOT_TENURED);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000718};
Steve Blocka7e24c12009-10-30 11:49:00 +0000719
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000720} // namespace internal
721} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000722
723#endif // V8_FACTORY_H_