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.
4 
5 #ifndef V8_HEAP_FACTORY_H_
6 #define V8_HEAP_FACTORY_H_
7 
8 #include "src/builtins/builtins.h"
9 #include "src/globals.h"
10 #include "src/handles.h"
11 #include "src/heap/heap.h"
12 #include "src/messages.h"
13 #include "src/objects/code.h"
14 #include "src/objects/dictionary.h"
15 #include "src/objects/hash-table.h"
16 #include "src/objects/js-array.h"
17 #include "src/objects/js-regexp.h"
18 #include "src/objects/ordered-hash-table.h"
19 #include "src/objects/string.h"
20 
21 namespace v8 {
22 namespace internal {
23 
24 // Forward declarations.
25 class AliasedArgumentsEntry;
26 class BoilerplateDescription;
27 class BreakPoint;
28 class BreakPointInfo;
29 class CallableTask;
30 class CallbackTask;
31 class CallHandlerInfo;
32 class ConstantElementsPair;
33 class CoverageInfo;
34 class DebugInfo;
35 class EnumCache;
36 class FreshlyAllocatedBigInt;
37 class Isolate;
38 class JSMap;
39 class JSMapIterator;
40 class JSModuleNamespace;
41 class JSSet;
42 class JSSetIterator;
43 class JSWeakMap;
44 class LoadHandler;
45 class ModuleInfo;
46 class NewFunctionArgs;
47 class PreParsedScopeData;
48 class PromiseResolveThenableJobTask;
49 class RegExpMatchInfo;
50 class ScriptContextTable;
51 class StoreHandler;
52 class TemplateObjectDescription;
53 class WasmExportedFunctionData;
54 struct SourceRange;
55 template <typename T>
56 class ZoneVector;
57 
58 enum FunctionMode {
59   kWithNameBit = 1 << 0,
60   kWithHomeObjectBit = 1 << 1,
61   kWithWritablePrototypeBit = 1 << 2,
62   kWithReadonlyPrototypeBit = 1 << 3,
63   kWithPrototypeBits = kWithWritablePrototypeBit | kWithReadonlyPrototypeBit,
64 
65   // Without prototype.
66   FUNCTION_WITHOUT_PROTOTYPE = 0,
67   METHOD_WITH_NAME = kWithNameBit,
68   METHOD_WITH_HOME_OBJECT = kWithHomeObjectBit,
69   METHOD_WITH_NAME_AND_HOME_OBJECT = kWithNameBit | kWithHomeObjectBit,
70 
71   // With writable prototype.
72   FUNCTION_WITH_WRITEABLE_PROTOTYPE = kWithWritablePrototypeBit,
73   FUNCTION_WITH_NAME_AND_WRITEABLE_PROTOTYPE =
74       kWithWritablePrototypeBit | kWithNameBit,
75   FUNCTION_WITH_HOME_OBJECT_AND_WRITEABLE_PROTOTYPE =
76       kWithWritablePrototypeBit | kWithHomeObjectBit,
77   FUNCTION_WITH_NAME_AND_HOME_OBJECT_AND_WRITEABLE_PROTOTYPE =
78       kWithWritablePrototypeBit | kWithNameBit | kWithHomeObjectBit,
79 
80   // With readonly prototype.
81   FUNCTION_WITH_READONLY_PROTOTYPE = kWithReadonlyPrototypeBit,
82   FUNCTION_WITH_NAME_AND_READONLY_PROTOTYPE =
83       kWithReadonlyPrototypeBit | kWithNameBit,
84 };
85 
86 // Interface for handle based allocation.
87 class V8_EXPORT_PRIVATE Factory {
88  public:
89   Handle<Oddball> NewOddball(Handle<Map> map, const char* to_string,
90                              Handle<Object> to_number, const char* type_of,
91                              byte kind,
92                              PretenureFlag pretenure = TENURED_READ_ONLY);
93 
94   // Marks self references within code generation.
95   Handle<Oddball> NewSelfReferenceMarker(PretenureFlag pretenure = TENURED);
96 
97   // Allocates a fixed array-like object with given map and initialized with
98   // undefined values.
99   template <typename T = FixedArray>
100   Handle<T> NewFixedArrayWithMap(Heap::RootListIndex map_root_index, int length,
101                                  PretenureFlag pretenure = NOT_TENURED);
102 
103   // Allocates a weak fixed array-like object with given map and initialized
104   // with undefined values.
105   template <typename T = WeakFixedArray>
106   Handle<T> NewWeakFixedArrayWithMap(Heap::RootListIndex map_root_index,
107                                      int length,
108                                      PretenureFlag pretenure = NOT_TENURED);
109 
110   // Allocates a fixed array initialized with undefined values.
111   Handle<FixedArray> NewFixedArray(int length,
112                                    PretenureFlag pretenure = NOT_TENURED);
113 
114   // Allocates a fixed array which may contain in-place weak references. The
115   // array is initialized with undefined values
116   Handle<WeakFixedArray> NewWeakFixedArray(
117       int length, PretenureFlag pretenure = NOT_TENURED);
118 
119   // Allocates a property array initialized with undefined values.
120   Handle<PropertyArray> NewPropertyArray(int length,
121                                          PretenureFlag pretenure = NOT_TENURED);
122   // Tries allocating a fixed array initialized with undefined values.
123   // In case of an allocation failure (OOM) an empty handle is returned.
124   // The caller has to manually signal an
125   // v8::internal::Heap::FatalProcessOutOfMemory typically by calling
126   // NewFixedArray as a fallback.
127   V8_WARN_UNUSED_RESULT
128   MaybeHandle<FixedArray> TryNewFixedArray(
129       int length, PretenureFlag pretenure = NOT_TENURED);
130 
131   // Allocate a new fixed array with non-existing entries (the hole).
132   Handle<FixedArray> NewFixedArrayWithHoles(
133       int length, PretenureFlag pretenure = NOT_TENURED);
134 
135   // Allocates an uninitialized fixed array. It must be filled by the caller.
136   Handle<FixedArray> NewUninitializedFixedArray(
137       int length, PretenureFlag pretenure = NOT_TENURED);
138 
139   // Allocates a feedback vector whose slots are initialized with undefined
140   // values.
141   Handle<FeedbackVector> NewFeedbackVector(
142       Handle<SharedFunctionInfo> shared, PretenureFlag pretenure = NOT_TENURED);
143 
144   // Allocates a fixed array for name-value pairs of boilerplate properties and
145   // calculates the number of properties we need to store in the backing store.
146   Handle<BoilerplateDescription> NewBoilerplateDescription(int boilerplate,
147                                                            int all_properties,
148                                                            int index_keys,
149                                                            bool has_seen_proto);
150 
151   // Allocate a new uninitialized fixed double array.
152   // The function returns a pre-allocated empty fixed array for length = 0,
153   // so the return type must be the general fixed array class.
154   Handle<FixedArrayBase> NewFixedDoubleArray(
155       int length, PretenureFlag pretenure = NOT_TENURED);
156 
157   // Allocate a new fixed double array with hole values.
158   Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles(
159       int size, PretenureFlag pretenure = NOT_TENURED);
160 
161   // Allocates a FeedbackMedata object and zeroes the data section.
162   Handle<FeedbackMetadata> NewFeedbackMetadata(int slot_count,
163                                                PretenureFlag tenure = TENURED);
164 
165   Handle<FrameArray> NewFrameArray(int number_of_frames,
166                                    PretenureFlag pretenure = NOT_TENURED);
167 
168   Handle<OrderedHashSet> NewOrderedHashSet();
169   Handle<OrderedHashMap> NewOrderedHashMap();
170 
171   Handle<SmallOrderedHashSet> NewSmallOrderedHashSet(
172       int capacity = SmallOrderedHashSet::kMinCapacity,
173       PretenureFlag pretenure = NOT_TENURED);
174   Handle<SmallOrderedHashMap> NewSmallOrderedHashMap(
175       int capacity = SmallOrderedHashMap::kMinCapacity,
176       PretenureFlag pretenure = NOT_TENURED);
177 
178   // Create a new PrototypeInfo struct.
179   Handle<PrototypeInfo> NewPrototypeInfo();
180 
181   // Create a new EnumCache struct.
182   Handle<EnumCache> NewEnumCache(Handle<FixedArray> keys,
183                                  Handle<FixedArray> indices);
184 
185   // Create a new Tuple2 struct.
186   Handle<Tuple2> NewTuple2(Handle<Object> value1, Handle<Object> value2,
187                            PretenureFlag pretenure);
188 
189   // Create a new Tuple3 struct.
190   Handle<Tuple3> NewTuple3(Handle<Object> value1, Handle<Object> value2,
191                            Handle<Object> value3, PretenureFlag pretenure);
192 
193   // Create a new ConstantElementsPair struct.
194   Handle<ConstantElementsPair> NewConstantElementsPair(
195       ElementsKind elements_kind, Handle<FixedArrayBase> constant_values);
196 
197   // Create a new TemplateObjectDescription struct.
198   Handle<TemplateObjectDescription> NewTemplateObjectDescription(
199       Handle<FixedArray> raw_strings, Handle<FixedArray> cooked_strings);
200 
201   // Create a pre-tenured empty AccessorPair.
202   Handle<AccessorPair> NewAccessorPair();
203 
204   // Finds the internalized copy for string in the string table.
205   // If not found, a new string is added to the table and returned.
206   Handle<String> InternalizeUtf8String(Vector<const char> str);
InternalizeUtf8String(const char * str)207   Handle<String> InternalizeUtf8String(const char* str) {
208     return InternalizeUtf8String(CStrVector(str));
209   }
210 
211   Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
212   Handle<String> InternalizeOneByteString(Handle<SeqOneByteString>, int from,
213                                           int length);
214 
215   Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
216 
217   template <class StringTableKey>
218   Handle<String> InternalizeStringWithKey(StringTableKey* key);
219 
220   // Internalized strings are created in the old generation (data space).
221   inline Handle<String> InternalizeString(Handle<String> string);
222 
223   inline Handle<Name> InternalizeName(Handle<Name> name);
224 
225   // String creation functions.  Most of the string creation functions take
226   // a Heap::PretenureFlag argument to optionally request that they be
227   // allocated in the old generation.  The pretenure flag defaults to
228   // DONT_TENURE.
229   //
230   // Creates a new String object.  There are two String encodings: one-byte and
231   // two-byte.  One should choose between the three string factory functions
232   // based on the encoding of the string buffer that the string is
233   // initialized from.
234   //   - ...FromOneByte initializes the string from a buffer that is Latin1
235   //     encoded (it does not check that the buffer is Latin1 encoded) and
236   //     the result will be Latin1 encoded.
237   //   - ...FromUtf8 initializes the string from a buffer that is UTF-8
238   //     encoded.  If the characters are all ASCII characters, the result
239   //     will be Latin1 encoded, otherwise it will converted to two-byte.
240   //   - ...FromTwoByte initializes the string from a buffer that is two-byte
241   //     encoded.  If the characters are all Latin1 characters, the result
242   //     will be converted to Latin1, otherwise it will be left as two-byte.
243   //
244   // One-byte strings are pretenured when used as keys in the SourceCodeCache.
245   V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromOneByte(
246       Vector<const uint8_t> str, PretenureFlag pretenure = NOT_TENURED);
247 
248   template <size_t N>
249   inline Handle<String> NewStringFromStaticChars(
250       const char (&str)[N], PretenureFlag pretenure = NOT_TENURED) {
251     DCHECK(N == StrLength(str) + 1);
252     return NewStringFromOneByte(STATIC_CHAR_VECTOR(str), pretenure)
253         .ToHandleChecked();
254   }
255 
256   inline Handle<String> NewStringFromAsciiChecked(
257       const char* str, PretenureFlag pretenure = NOT_TENURED) {
258     return NewStringFromOneByte(OneByteVector(str), pretenure)
259         .ToHandleChecked();
260   }
261 
262   // UTF8 strings are pretenured when used for regexp literal patterns and
263   // flags in the parser.
264   V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromUtf8(
265       Vector<const char> str, PretenureFlag pretenure = NOT_TENURED);
266 
267   V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromUtf8SubString(
268       Handle<SeqOneByteString> str, int begin, int end,
269       PretenureFlag pretenure = NOT_TENURED);
270 
271   V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromTwoByte(
272       Vector<const uc16> str, PretenureFlag pretenure = NOT_TENURED);
273 
274   V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromTwoByte(
275       const ZoneVector<uc16>* str, PretenureFlag pretenure = NOT_TENURED);
276 
277   Handle<JSStringIterator> NewJSStringIterator(Handle<String> string);
278 
279   // Allocates an internalized string in old space based on the character
280   // stream.
281   Handle<String> NewInternalizedStringFromUtf8(Vector<const char> str,
282                                                int chars, uint32_t hash_field);
283 
284   Handle<String> NewOneByteInternalizedString(Vector<const uint8_t> str,
285                                               uint32_t hash_field);
286 
287   Handle<String> NewOneByteInternalizedSubString(
288       Handle<SeqOneByteString> string, int offset, int length,
289       uint32_t hash_field);
290 
291   Handle<String> NewTwoByteInternalizedString(Vector<const uc16> str,
292                                               uint32_t hash_field);
293 
294   Handle<String> NewInternalizedStringImpl(Handle<String> string, int chars,
295                                            uint32_t hash_field);
296 
297   // Compute the matching internalized string map for a string if possible.
298   // Empty handle is returned if string is in new space or not flattened.
299   V8_WARN_UNUSED_RESULT MaybeHandle<Map> InternalizedStringMapForString(
300       Handle<String> string);
301 
302   // Creates an internalized copy of an external string. |string| must be
303   // of type StringClass.
304   template <class StringClass>
305   Handle<StringClass> InternalizeExternalString(Handle<String> string);
306 
307   // Allocates and partially initializes an one-byte or two-byte String. The
308   // characters of the string are uninitialized. Currently used in regexp code
309   // only, where they are pretenured.
310   V8_WARN_UNUSED_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString(
311       int length, PretenureFlag pretenure = NOT_TENURED);
312   V8_WARN_UNUSED_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString(
313       int length, PretenureFlag pretenure = NOT_TENURED);
314 
315   // Creates a single character string where the character has given code.
316   // A cache is used for Latin1 codes.
317   Handle<String> LookupSingleCharacterStringFromCode(uint32_t code);
318 
319   // Create a new cons string object which consists of a pair of strings.
320   V8_WARN_UNUSED_RESULT MaybeHandle<String> NewConsString(Handle<String> left,
321                                                           Handle<String> right);
322 
323   V8_WARN_UNUSED_RESULT Handle<String> NewConsString(Handle<String> left,
324                                                      Handle<String> right,
325                                                      int length, bool one_byte);
326 
327   // Create or lookup a single characters tring made up of a utf16 surrogate
328   // pair.
329   Handle<String> NewSurrogatePairString(uint16_t lead, uint16_t trail);
330 
331   // Create a new string object which holds a proper substring of a string.
332   Handle<String> NewProperSubString(Handle<String> str, int begin, int end);
333 
334   // Create a new string object which holds a substring of a string.
335   inline Handle<String> NewSubString(Handle<String> str, int begin, int end);
336 
337   // Creates a new external String object.  There are two String encodings
338   // in the system: one-byte and two-byte.  Unlike other String types, it does
339   // not make sense to have a UTF-8 factory function for external strings,
340   // because we cannot change the underlying buffer.  Note that these strings
341   // are backed by a string resource that resides outside the V8 heap.
342   V8_WARN_UNUSED_RESULT MaybeHandle<String> NewExternalStringFromOneByte(
343       const ExternalOneByteString::Resource* resource);
344   V8_WARN_UNUSED_RESULT MaybeHandle<String> NewExternalStringFromTwoByte(
345       const ExternalTwoByteString::Resource* resource);
346   // Create a new external string object for one-byte encoded native script.
347   // It does not cache the resource data pointer.
348   Handle<ExternalOneByteString> NewNativeSourceString(
349       const ExternalOneByteString::Resource* resource);
350 
351   // Create a symbol in old or read-only space.
352   Handle<Symbol> NewSymbol(PretenureFlag pretenure = TENURED);
353   Handle<Symbol> NewPrivateSymbol(PretenureFlag pretenure = TENURED);
354   Handle<Symbol> NewPrivateFieldSymbol();
355 
356   // Create a global (but otherwise uninitialized) context.
357   Handle<Context> NewNativeContext();
358 
359   // Create a script context.
360   Handle<Context> NewScriptContext(Handle<Context> outer,
361                                    Handle<ScopeInfo> scope_info);
362 
363   // Create an empty script context table.
364   Handle<ScriptContextTable> NewScriptContextTable();
365 
366   // Create a module context.
367   Handle<Context> NewModuleContext(Handle<Module> module, Handle<Context> outer,
368                                    Handle<ScopeInfo> scope_info);
369 
370   // Create a function or eval context.
371   Handle<Context> NewFunctionContext(Handle<Context> outer,
372                                      Handle<ScopeInfo> scope_info);
373 
374   // Create a catch context.
375   Handle<Context> NewCatchContext(Handle<Context> previous,
376                                   Handle<ScopeInfo> scope_info,
377                                   Handle<Object> thrown_object);
378 
379   // Create a 'with' context.
380   Handle<Context> NewWithContext(Handle<Context> previous,
381                                  Handle<ScopeInfo> scope_info,
382                                  Handle<JSReceiver> extension);
383 
384   Handle<Context> NewDebugEvaluateContext(Handle<Context> previous,
385                                           Handle<ScopeInfo> scope_info,
386                                           Handle<JSReceiver> extension,
387                                           Handle<Context> wrapped,
388                                           Handle<StringSet> whitelist);
389 
390   // Create a block context.
391   Handle<Context> NewBlockContext(Handle<Context> previous,
392                                   Handle<ScopeInfo> scope_info);
393 
394   Handle<Struct> NewStruct(InstanceType type,
395                            PretenureFlag pretenure = NOT_TENURED);
396 
397   Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
398       int aliased_context_slot);
399 
400   Handle<AccessorInfo> NewAccessorInfo();
401 
402   Handle<Script> NewScript(Handle<String> source,
403                            PretenureFlag tenure = TENURED);
404 
405   Handle<BreakPointInfo> NewBreakPointInfo(int source_position);
406   Handle<BreakPoint> NewBreakPoint(int id, Handle<String> condition);
407   Handle<StackFrameInfo> NewStackFrameInfo();
408   Handle<SourcePositionTableWithFrameCache>
409   NewSourcePositionTableWithFrameCache(
410       Handle<ByteArray> source_position_table,
411       Handle<SimpleNumberDictionary> stack_frame_cache);
412 
413   // Allocate various microtasks.
414   Handle<CallableTask> NewCallableTask(Handle<JSReceiver> callable,
415                                        Handle<Context> context);
416   Handle<CallbackTask> NewCallbackTask(Handle<Foreign> callback,
417                                        Handle<Foreign> data);
418   Handle<PromiseResolveThenableJobTask> NewPromiseResolveThenableJobTask(
419       Handle<JSPromise> promise_to_resolve, Handle<JSReceiver> then,
420       Handle<JSReceiver> thenable, Handle<Context> context);
421 
422   // Foreign objects are pretenured when allocated by the bootstrapper.
423   Handle<Foreign> NewForeign(Address addr,
424                              PretenureFlag pretenure = NOT_TENURED);
425 
426   Handle<ByteArray> NewByteArray(int length,
427                                  PretenureFlag pretenure = NOT_TENURED);
428 
429   Handle<BytecodeArray> NewBytecodeArray(int length, const byte* raw_bytecodes,
430                                          int frame_size, int parameter_count,
431                                          Handle<FixedArray> constant_pool);
432 
433   Handle<FixedTypedArrayBase> NewFixedTypedArrayWithExternalPointer(
434       int length, ExternalArrayType array_type, void* external_pointer,
435       PretenureFlag pretenure = NOT_TENURED);
436 
437   Handle<FixedTypedArrayBase> NewFixedTypedArray(
438       size_t length, size_t byte_length, ExternalArrayType array_type,
439       bool initialize, PretenureFlag pretenure = NOT_TENURED);
440 
441   Handle<Cell> NewCell(Handle<Object> value);
442 
443   Handle<PropertyCell> NewPropertyCell(Handle<Name> name,
444                                        PretenureFlag pretenure = TENURED);
445 
446   Handle<WeakCell> NewWeakCell(Handle<HeapObject> value,
447                                PretenureFlag pretenure = TENURED);
448 
449   Handle<FeedbackCell> NewNoClosuresCell(Handle<HeapObject> value);
450   Handle<FeedbackCell> NewOneClosureCell(Handle<HeapObject> value);
451   Handle<FeedbackCell> NewManyClosuresCell(Handle<HeapObject> value);
452 
453   Handle<TransitionArray> NewTransitionArray(int number_of_transitions,
454                                              int slack = 0);
455 
456   // Allocate a tenured AllocationSite. Its payload is null.
457   Handle<AllocationSite> NewAllocationSite();
458 
459   // Allocates and initializes a new Map.
460   Handle<Map> NewMap(InstanceType type, int instance_size,
461                      ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
462                      int inobject_properties = 0);
463   // Initializes the fields of a newly created Map. Exposed for tests and
464   // heap setup; other code should just call NewMap which takes care of it.
465   Map* InitializeMap(Map* map, InstanceType type, int instance_size,
466                      ElementsKind elements_kind, int inobject_properties);
467 
468   // Allocate a block of memory in the given space (filled with a filler).
469   // Used as a fall-back for generated code when the space is full.
470   Handle<HeapObject> NewFillerObject(int size, bool double_align,
471                                      AllocationSpace space);
472 
473   Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
474 
475   // Returns a deep copy of the JavaScript object.
476   // Properties and elements are copied too.
477   Handle<JSObject> CopyJSObject(Handle<JSObject> object);
478   // Same as above, but also takes an AllocationSite to be appended in an
479   // AllocationMemento.
480   Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
481                                                   Handle<AllocationSite> site);
482 
483   Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
484                                            Handle<Map> map);
485 
486   Handle<FixedArray> CopyFixedArrayAndGrow(
487       Handle<FixedArray> array, int grow_by,
488       PretenureFlag pretenure = NOT_TENURED);
489 
490   Handle<WeakFixedArray> CopyWeakFixedArrayAndGrow(
491       Handle<WeakFixedArray> array, int grow_by,
492       PretenureFlag pretenure = NOT_TENURED);
493 
494   Handle<WeakArrayList> CopyWeakArrayListAndGrow(
495       Handle<WeakArrayList> array, int grow_by,
496       PretenureFlag pretenure = NOT_TENURED);
497 
498   Handle<PropertyArray> CopyPropertyArrayAndGrow(
499       Handle<PropertyArray> array, int grow_by,
500       PretenureFlag pretenure = NOT_TENURED);
501 
502   Handle<FixedArray> CopyFixedArrayUpTo(Handle<FixedArray> array, int new_len,
503                                         PretenureFlag pretenure = NOT_TENURED);
504 
505   Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
506 
507   // This method expects a COW array in new space, and creates a copy
508   // of it in old space.
509   Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
510 
511   Handle<FixedDoubleArray> CopyFixedDoubleArray(Handle<FixedDoubleArray> array);
512 
513   Handle<FeedbackVector> CopyFeedbackVector(Handle<FeedbackVector> array);
514 
515   // Numbers (e.g. literals) are pretenured by the parser.
516   // The return value may be a smi or a heap number.
517   Handle<Object> NewNumber(double value, PretenureFlag pretenure = NOT_TENURED);
518 
519   Handle<Object> NewNumberFromInt(int32_t value,
520                                   PretenureFlag pretenure = NOT_TENURED);
521   Handle<Object> NewNumberFromUint(uint32_t value,
522                                    PretenureFlag pretenure = NOT_TENURED);
523   inline Handle<Object> NewNumberFromSize(
524       size_t value, PretenureFlag pretenure = NOT_TENURED);
525   inline Handle<Object> NewNumberFromInt64(
526       int64_t value, PretenureFlag pretenure = NOT_TENURED);
527   inline Handle<HeapNumber> NewHeapNumber(
528       double value, MutableMode mode = IMMUTABLE,
529       PretenureFlag pretenure = NOT_TENURED);
530   inline Handle<HeapNumber> NewHeapNumberFromBits(
531       uint64_t bits, MutableMode mode = IMMUTABLE,
532       PretenureFlag pretenure = NOT_TENURED);
533   // Creates mutable heap number object with value field set to hole NaN.
534   inline Handle<HeapNumber> NewMutableHeapNumber(
535       PretenureFlag pretenure = NOT_TENURED);
536 
537   // Creates heap number object with not yet set value field.
538   Handle<HeapNumber> NewHeapNumber(MutableMode mode,
539                                    PretenureFlag pretenure = NOT_TENURED);
540 
541   // Allocates a new BigInt with {length} digits. Only to be used by
542   // MutableBigInt::New*.
543   Handle<FreshlyAllocatedBigInt> NewBigInt(
544       int length, PretenureFlag pretenure = NOT_TENURED);
545 
546   Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
547 
548   // Allocates and initializes a new JavaScript object based on a
549   // constructor.
550   // JS objects are pretenured when allocated by the bootstrapper and
551   // runtime.
552   Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
553                                PretenureFlag pretenure = NOT_TENURED);
554   // JSObject without a prototype.
555   Handle<JSObject> NewJSObjectWithNullProto(
556       PretenureFlag pretenure = NOT_TENURED);
557 
558   // Global objects are pretenured and initialized based on a constructor.
559   Handle<JSGlobalObject> NewJSGlobalObject(Handle<JSFunction> constructor);
560 
561   // Allocates and initializes a new JavaScript object based on a map.
562   // Passing an allocation site means that a memento will be created that
563   // points to the site.
564   // JS objects are pretenured when allocated by the bootstrapper and
565   // runtime.
566   Handle<JSObject> NewJSObjectFromMap(
567       Handle<Map> map, PretenureFlag pretenure = NOT_TENURED,
568       Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
569   Handle<JSObject> NewSlowJSObjectFromMap(
570       Handle<Map> map,
571       int number_of_slow_properties = NameDictionary::kInitialCapacity,
572       PretenureFlag pretenure = NOT_TENURED);
573 
574   // JS arrays are pretenured when allocated by the parser.
575 
576   // Create a JSArray with a specified length and elements initialized
577   // according to the specified mode.
578   Handle<JSArray> NewJSArray(
579       ElementsKind elements_kind, int length, int capacity,
580       ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS,
581       PretenureFlag pretenure = NOT_TENURED);
582 
583   Handle<JSArray> NewJSArray(
584       int capacity, ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
585       PretenureFlag pretenure = NOT_TENURED) {
586     if (capacity != 0) {
587       elements_kind = GetHoleyElementsKind(elements_kind);
588     }
589     return NewJSArray(elements_kind, 0, capacity,
590                       INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
591   }
592 
593   // Create a JSArray with the given elements.
594   Handle<JSArray> NewJSArrayWithElements(Handle<FixedArrayBase> elements,
595                                          ElementsKind elements_kind, int length,
596                                          PretenureFlag pretenure = NOT_TENURED);
597 
598   inline Handle<JSArray> NewJSArrayWithElements(
599       Handle<FixedArrayBase> elements,
600       ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
601       PretenureFlag pretenure = NOT_TENURED);
602 
603   void NewJSArrayStorage(
604       Handle<JSArray> array, int length, int capacity,
605       ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
606 
607   Handle<JSWeakMap> NewJSWeakMap();
608 
609   Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
610 
611   Handle<JSModuleNamespace> NewJSModuleNamespace();
612 
613   Handle<Module> NewModule(Handle<SharedFunctionInfo> code);
614 
615   Handle<JSArrayBuffer> NewJSArrayBuffer(
616       SharedFlag shared = SharedFlag::kNotShared,
617       PretenureFlag pretenure = NOT_TENURED);
618 
619   static void TypeAndSizeForElementsKind(ElementsKind kind,
620                                          ExternalArrayType* array_type,
621                                          size_t* element_size);
622 
623   Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
624                                        PretenureFlag pretenure = NOT_TENURED);
625 
626   Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
627                                        PretenureFlag pretenure = NOT_TENURED);
628 
629   // Creates a new JSTypedArray with the specified buffer.
630   Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
631                                        Handle<JSArrayBuffer> buffer,
632                                        size_t byte_offset, size_t length,
633                                        PretenureFlag pretenure = NOT_TENURED);
634 
635   // Creates a new on-heap JSTypedArray.
636   Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
637                                        size_t number_of_elements,
638                                        PretenureFlag pretenure = NOT_TENURED);
639 
640   Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer,
641                                    size_t byte_offset, size_t byte_length);
642 
643   Handle<JSIteratorResult> NewJSIteratorResult(Handle<Object> value, bool done);
644   Handle<JSAsyncFromSyncIterator> NewJSAsyncFromSyncIterator(
645       Handle<JSReceiver> sync_iterator, Handle<Object> next);
646 
647   Handle<JSMap> NewJSMap();
648   Handle<JSSet> NewJSSet();
649 
650   Handle<JSMapIterator> NewJSMapIterator(Handle<Map> map,
651                                          Handle<OrderedHashMap> table,
652                                          int index);
653   Handle<JSSetIterator> NewJSSetIterator(Handle<Map> map,
654                                          Handle<OrderedHashSet> table,
655                                          int index);
656 
657   // Allocates a bound function.
658   MaybeHandle<JSBoundFunction> NewJSBoundFunction(
659       Handle<JSReceiver> target_function, Handle<Object> bound_this,
660       Vector<Handle<Object>> bound_args);
661 
662   // Allocates a Harmony proxy.
663   Handle<JSProxy> NewJSProxy(Handle<JSReceiver> target,
664                              Handle<JSReceiver> handler);
665 
666   // Reinitialize an JSGlobalProxy based on a constructor.  The object
667   // must have the same size as objects allocated using the
668   // constructor.  The object is reinitialized and behaves as an
669   // object that has been freshly allocated using the constructor.
670   void ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> global,
671                                  Handle<JSFunction> constructor);
672 
673   Handle<JSGlobalProxy> NewUninitializedJSGlobalProxy(int size);
674 
675   // Creates a new JSFunction according to the given args. This is the function
676   // you'll probably want to use when creating a JSFunction from the runtime.
677   Handle<JSFunction> NewFunction(const NewFunctionArgs& args);
678 
679   // For testing only. Creates a sloppy function without code.
680   Handle<JSFunction> NewFunctionForTest(Handle<String> name);
681 
682   // Function creation from SharedFunctionInfo.
683 
684   Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
685       Handle<Map> initial_map, Handle<SharedFunctionInfo> function_info,
686       Handle<Context> context, Handle<FeedbackCell> feedback_cell,
687       PretenureFlag pretenure = TENURED);
688 
689   Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
690       Handle<SharedFunctionInfo> function_info, Handle<Context> context,
691       Handle<FeedbackCell> feedback_cell, PretenureFlag pretenure = TENURED);
692 
693   Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
694       Handle<Map> initial_map, Handle<SharedFunctionInfo> function_info,
695       Handle<Context> context, PretenureFlag pretenure = TENURED);
696 
697   Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
698       Handle<SharedFunctionInfo> function_info, Handle<Context> context,
699       PretenureFlag pretenure = TENURED);
700 
701   // The choke-point for JSFunction creation. Handles allocation and
702   // initialization. All other utility methods call into this.
703   Handle<JSFunction> NewFunction(Handle<Map> map,
704                                  Handle<SharedFunctionInfo> info,
705                                  Handle<Context> context,
706                                  PretenureFlag pretenure = TENURED);
707 
708   // Create a serialized scope info.
709   Handle<ScopeInfo> NewScopeInfo(int length);
710 
711   Handle<ModuleInfo> NewModuleInfo();
712 
713   Handle<PreParsedScopeData> NewPreParsedScopeData();
714 
715   // Create an External object for V8's external API.
716   Handle<JSObject> NewExternal(void* value);
717 
718   // Creates a new CodeDataContainer for a Code object.
719   Handle<CodeDataContainer> NewCodeDataContainer(int flags);
720 
721   // Allocates a new code object (fully initialized). All header fields of the
722   // returned object are immutable and the code object is write protected.
723   // The reference to the Code object is stored in self_reference.
724   // This allows generated code to reference its own Code object
725   // by containing this handle.
726   Handle<Code> NewCode(const CodeDesc& desc, Code::Kind kind,
727                        Handle<Object> self_reference,
728                        int32_t builtin_index = Builtins::kNoBuiltinId,
729                        MaybeHandle<ByteArray> maybe_source_position_table =
730                            MaybeHandle<ByteArray>(),
731                        MaybeHandle<DeoptimizationData> maybe_deopt_data =
732                            MaybeHandle<DeoptimizationData>(),
733                        Movability movability = kMovable, uint32_t stub_key = 0,
734                        bool is_turbofanned = false, int stack_slots = 0,
735                        int safepoint_table_offset = 0,
736                        int handler_table_offset = 0);
737 
738   // Like NewCode, this function allocates a new code object (fully
739   // initialized). It may return an empty handle if the allocation does not
740   // succeed.
741   V8_WARN_UNUSED_RESULT MaybeHandle<Code> TryNewCode(
742       const CodeDesc& desc, Code::Kind kind, Handle<Object> self_reference,
743       int32_t builtin_index = Builtins::kNoBuiltinId,
744       MaybeHandle<ByteArray> maybe_source_position_table =
745           MaybeHandle<ByteArray>(),
746       MaybeHandle<DeoptimizationData> maybe_deopt_data =
747           MaybeHandle<DeoptimizationData>(),
748       Movability movability = kMovable, uint32_t stub_key = 0,
749       bool is_turbofanned = false, int stack_slots = 0,
750       int safepoint_table_offset = 0, int handler_table_offset = 0);
751 
752   // Allocates a new, empty code object for use by builtin deserialization. The
753   // given {size} argument specifies the size of the entire code object.
754   // Can only be used when code space is unprotected and requires manual
755   // initialization by the caller.
756   Handle<Code> NewCodeForDeserialization(uint32_t size);
757 
758 #ifdef V8_EMBEDDED_BUILTINS
759   // Allocates a new code object and initializes it as the trampoline to the
760   // given off-heap entry point.
761   Handle<Code> NewOffHeapTrampolineFor(Handle<Code> code,
762                                        Address off_heap_entry);
763 #endif
764 
765   Handle<Code> CopyCode(Handle<Code> code);
766 
767   Handle<BytecodeArray> CopyBytecodeArray(Handle<BytecodeArray>);
768 
769   // Interface for creating error objects.
770   Handle<Object> NewError(Handle<JSFunction> constructor,
771                           Handle<String> message);
772 
773   Handle<Object> NewInvalidStringLengthError();
774 
775   inline Handle<Object> NewURIError();
776 
777   Handle<Object> NewError(Handle<JSFunction> constructor,
778                           MessageTemplate::Template template_index,
779                           Handle<Object> arg0 = Handle<Object>(),
780                           Handle<Object> arg1 = Handle<Object>(),
781                           Handle<Object> arg2 = Handle<Object>());
782 
783 #define DECLARE_ERROR(NAME)                                          \
784   Handle<Object> New##NAME(MessageTemplate::Template template_index, \
785                            Handle<Object> arg0 = Handle<Object>(),   \
786                            Handle<Object> arg1 = Handle<Object>(),   \
787                            Handle<Object> arg2 = Handle<Object>());
788   DECLARE_ERROR(Error)
789   DECLARE_ERROR(EvalError)
790   DECLARE_ERROR(RangeError)
791   DECLARE_ERROR(ReferenceError)
792   DECLARE_ERROR(SyntaxError)
793   DECLARE_ERROR(TypeError)
794   DECLARE_ERROR(WasmCompileError)
795   DECLARE_ERROR(WasmLinkError)
796   DECLARE_ERROR(WasmRuntimeError)
797 #undef DECLARE_ERROR
798 
799   Handle<String> NumberToString(Handle<Object> number,
800                                 bool check_number_string_cache = true);
801 
802   inline Handle<String> Uint32ToString(uint32_t value);
803 
804 #define ROOT_ACCESSOR(type, name, camel_name) inline Handle<type> name();
805   ROOT_LIST(ROOT_ACCESSOR)
806 #undef ROOT_ACCESSOR
807 
808 #define STRUCT_MAP_ACCESSOR(NAME, Name, name) inline Handle<Map> name##_map();
809   STRUCT_LIST(STRUCT_MAP_ACCESSOR)
810 #undef STRUCT_MAP_ACCESSOR
811 
812 #define DATA_HANDLER_MAP_ACCESSOR(NAME, Name, Size, name) \
813   inline Handle<Map> name##_map();
814   DATA_HANDLER_LIST(DATA_HANDLER_MAP_ACCESSOR)
815 #undef DATA_HANDLER_MAP_ACCESSOR
816 
817 #define STRING_ACCESSOR(name, str) inline Handle<String> name();
818   INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
819 #undef STRING_ACCESSOR
820 
821 #define SYMBOL_ACCESSOR(name) inline Handle<Symbol> name();
822   PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
823 #undef SYMBOL_ACCESSOR
824 
825 #define SYMBOL_ACCESSOR(name, description) inline Handle<Symbol> name();
826   PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
827   WELL_KNOWN_SYMBOL_LIST(SYMBOL_ACCESSOR)
828 #undef SYMBOL_ACCESSOR
829 
830 #define ACCESSOR_INFO_ACCESSOR(accessor_name, AccessorName) \
831   inline Handle<AccessorInfo> accessor_name##_accessor();
832   ACCESSOR_INFO_LIST(ACCESSOR_INFO_ACCESSOR)
833 #undef ACCESSOR_INFO_ACCESSOR
834 
835   // Allocates a new SharedFunctionInfo object.
836   Handle<SharedFunctionInfo> NewSharedFunctionInfoForApiFunction(
837       MaybeHandle<String> maybe_name,
838       Handle<FunctionTemplateInfo> function_template_info, FunctionKind kind);
839 
840   Handle<SharedFunctionInfo> NewSharedFunctionInfoForBuiltin(
841       MaybeHandle<String> name, int builtin_index,
842       FunctionKind kind = kNormalFunction);
843 
844   Handle<SharedFunctionInfo> NewSharedFunctionInfoForLiteral(
845       FunctionLiteral* literal, Handle<Script> script, bool is_toplevel);
846 
IsFunctionModeWithPrototype(FunctionMode function_mode)847   static bool IsFunctionModeWithPrototype(FunctionMode function_mode) {
848     return (function_mode & kWithPrototypeBits) != 0;
849   }
850 
IsFunctionModeWithWritablePrototype(FunctionMode function_mode)851   static bool IsFunctionModeWithWritablePrototype(FunctionMode function_mode) {
852     return (function_mode & kWithWritablePrototypeBit) != 0;
853   }
854 
IsFunctionModeWithName(FunctionMode function_mode)855   static bool IsFunctionModeWithName(FunctionMode function_mode) {
856     return (function_mode & kWithNameBit) != 0;
857   }
858 
IsFunctionModeWithHomeObject(FunctionMode function_mode)859   static bool IsFunctionModeWithHomeObject(FunctionMode function_mode) {
860     return (function_mode & kWithHomeObjectBit) != 0;
861   }
862 
863   Handle<Map> CreateSloppyFunctionMap(
864       FunctionMode function_mode, MaybeHandle<JSFunction> maybe_empty_function);
865 
866   Handle<Map> CreateStrictFunctionMap(FunctionMode function_mode,
867                                       Handle<JSFunction> empty_function);
868 
869   Handle<Map> CreateClassFunctionMap(Handle<JSFunction> empty_function);
870 
871   // Allocates a new JSMessageObject object.
872   Handle<JSMessageObject> NewJSMessageObject(MessageTemplate::Template message,
873                                              Handle<Object> argument,
874                                              int start_position,
875                                              int end_position,
876                                              Handle<Object> script,
877                                              Handle<Object> stack_frames);
878 
879   Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
880 
881   Handle<CoverageInfo> NewCoverageInfo(const ZoneVector<SourceRange>& slots);
882 
883   // Return a map for given number of properties using the map cache in the
884   // native context.
885   Handle<Map> ObjectLiteralMapFromCache(Handle<Context> native_context,
886                                         int number_of_properties);
887 
888   Handle<LoadHandler> NewLoadHandler(int data_count);
889   Handle<StoreHandler> NewStoreHandler(int data_count);
890 
891   Handle<RegExpMatchInfo> NewRegExpMatchInfo();
892 
893   // Creates a new FixedArray that holds the data associated with the
894   // atom regexp and stores it in the regexp.
895   void SetRegExpAtomData(Handle<JSRegExp> regexp, JSRegExp::Type type,
896                          Handle<String> source, JSRegExp::Flags flags,
897                          Handle<Object> match_pattern);
898 
899   // Creates a new FixedArray that holds the data associated with the
900   // irregexp regexp and stores it in the regexp.
901   void SetRegExpIrregexpData(Handle<JSRegExp> regexp, JSRegExp::Type type,
902                              Handle<String> source, JSRegExp::Flags flags,
903                              int capture_count);
904 
905   // Returns the value for a known global constant (a property of the global
906   // object which is neither configurable nor writable) like 'undefined'.
907   // Returns a null handle when the given name is unknown.
908   Handle<Object> GlobalConstantFor(Handle<Name> name);
909 
910   // Converts the given boolean condition to JavaScript boolean value.
911   Handle<Object> ToBoolean(bool value);
912 
913   // Converts the given ToPrimitive hint to it's string representation.
914   Handle<String> ToPrimitiveHintString(ToPrimitiveHint hint);
915 
916   Handle<JSPromise> NewJSPromise(PretenureFlag pretenure = NOT_TENURED);
917 
918   Handle<CallHandlerInfo> NewCallHandlerInfo(bool has_no_side_effect = false);
919 
NewForTest(Handle<Map> map,PretenureFlag pretenure)920   HeapObject* NewForTest(Handle<Map> map, PretenureFlag pretenure) {
921     return New(map, pretenure);
922   }
923 
924  private:
isolate()925   Isolate* isolate() {
926     // Downcast to the privately inherited sub-class using c-style casts to
927     // avoid undefined behavior (as static_cast cannot cast across private
928     // bases).
929     return (Isolate*)this;  // NOLINT(readability/casting)
930   }
931 
932   HeapObject* AllocateRawWithImmortalMap(
933       int size, PretenureFlag pretenure, Map* map,
934       AllocationAlignment alignment = kWordAligned);
935   HeapObject* AllocateRawWithAllocationSite(
936       Handle<Map> map, PretenureFlag pretenure,
937       Handle<AllocationSite> allocation_site);
938 
939   // Allocate memory for an uninitialized array (e.g., a FixedArray or similar).
940   HeapObject* AllocateRawArray(int size, PretenureFlag pretenure);
941   HeapObject* AllocateRawFixedArray(int length, PretenureFlag pretenure);
942   HeapObject* AllocateRawWeakArrayList(int length, PretenureFlag pretenure);
943   Handle<FixedArray> NewFixedArrayWithFiller(Heap::RootListIndex map_root_index,
944                                              int length, Object* filler,
945                                              PretenureFlag pretenure);
946 
947   // Creates a heap object based on the map. The fields of the heap object are
948   // not initialized, it's the responsibility of the caller to do that.
949   HeapObject* New(Handle<Map> map, PretenureFlag pretenure);
950 
951   template <typename T>
952   Handle<T> CopyArrayWithMap(Handle<T> src, Handle<Map> map);
953   template <typename T>
954   Handle<T> CopyArrayAndGrow(Handle<T> src, int grow_by,
955                              PretenureFlag pretenure);
956 
957   template <bool is_one_byte, typename T>
958   Handle<String> AllocateInternalizedStringImpl(T t, int chars,
959                                                 uint32_t hash_field);
960 
961   Handle<SeqOneByteString> AllocateRawOneByteInternalizedString(
962       int length, uint32_t hash_field);
963 
964   Handle<String> AllocateTwoByteInternalizedString(Vector<const uc16> str,
965                                                    uint32_t hash_field);
966 
967   MaybeHandle<String> NewStringFromTwoByte(const uc16* string, int length,
968                                            PretenureFlag pretenure);
969 
970   // Attempt to find the number in a small cache.  If we finds it, return
971   // the string representation of the number.  Otherwise return undefined.
972   Handle<Object> GetNumberStringCache(Handle<Object> number);
973 
974   // Update the cache with a new number-string pair.
975   void SetNumberStringCache(Handle<Object> number, Handle<String> string);
976 
977   // Create a JSArray with no elements and no length.
978   Handle<JSArray> NewJSArray(ElementsKind elements_kind,
979                              PretenureFlag pretenure = NOT_TENURED);
980 
981   Handle<JSPromise> NewJSPromiseWithoutHook(
982       PretenureFlag pretenure = NOT_TENURED);
983 
984   Handle<SharedFunctionInfo> NewSharedFunctionInfo(
985       MaybeHandle<String> name, MaybeHandle<HeapObject> maybe_function_data,
986       int maybe_builtin_index, FunctionKind kind = kNormalFunction);
987 
988   void InitializeAllocationMemento(AllocationMemento* memento,
989                                    AllocationSite* allocation_site);
990 
991   // Initializes a JSObject based on its map.
992   void InitializeJSObjectFromMap(Handle<JSObject> obj,
993                                  Handle<Object> properties, Handle<Map> map);
994   // Initializes JSObject body starting at given offset.
995   void InitializeJSObjectBody(Handle<JSObject> obj, Handle<Map> map,
996                               int start_offset);
997 };
998 
999 // Utility class to simplify argument handling around JSFunction creation.
1000 class NewFunctionArgs final {
1001  public:
1002   static NewFunctionArgs ForWasm(
1003       Handle<String> name,
1004       Handle<WasmExportedFunctionData> exported_function_data, Handle<Map> map);
1005   static NewFunctionArgs ForBuiltin(Handle<String> name, Handle<Map> map,
1006                                     int builtin_id);
1007   static NewFunctionArgs ForFunctionWithoutCode(Handle<String> name,
1008                                                 Handle<Map> map,
1009                                                 LanguageMode language_mode);
1010   static NewFunctionArgs ForBuiltinWithPrototype(
1011       Handle<String> name, Handle<Object> prototype, InstanceType type,
1012       int instance_size, int inobject_properties, int builtin_id,
1013       MutableMode prototype_mutability);
1014   static NewFunctionArgs ForBuiltinWithoutPrototype(Handle<String> name,
1015                                                     int builtin_id,
1016                                                     LanguageMode language_mode);
1017 
1018   Handle<Map> GetMap(Isolate* isolate) const;
1019 
1020  private:
NewFunctionArgs()1021   NewFunctionArgs() {}  // Use the static factory constructors.
1022 
1023   void SetShouldCreateAndSetInitialMap();
1024   void SetShouldSetPrototype();
1025   void SetShouldSetLanguageMode();
1026 
1027   // Sentinel value.
1028   static const int kUninitialized = -1;
1029 
1030   Handle<String> name_;
1031   MaybeHandle<Map> maybe_map_;
1032   MaybeHandle<WasmExportedFunctionData> maybe_exported_function_data_;
1033 
1034   bool should_create_and_set_initial_map_ = false;
1035   InstanceType type_;
1036   int instance_size_ = kUninitialized;
1037   int inobject_properties_ = kUninitialized;
1038 
1039   bool should_set_prototype_ = false;
1040   MaybeHandle<Object> maybe_prototype_;
1041 
1042   bool should_set_language_mode_ = false;
1043   LanguageMode language_mode_;
1044 
1045   int maybe_builtin_id_ = kUninitialized;
1046 
1047   MutableMode prototype_mutability_;
1048 
1049   friend class Factory;
1050 };
1051 
1052 }  // namespace internal
1053 }  // namespace v8
1054 
1055 #endif  // V8_HEAP_FACTORY_H_
1056