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