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