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