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.
8 #include "src/isolate.h"
9 #include "src/messages.h"
14 class StaticFeedbackVectorSpec;
16 // Interface for handle based allocation.
19 Handle<Oddball> NewOddball(Handle<Map> map, const char* to_string,
20 Handle<Object> to_number, const char* type_of,
23 // Allocates a fixed array initialized with undefined values.
24 Handle<FixedArray> NewFixedArray(
26 PretenureFlag pretenure = NOT_TENURED);
28 // Allocate a new fixed array with non-existing entries (the hole).
29 Handle<FixedArray> NewFixedArrayWithHoles(
31 PretenureFlag pretenure = NOT_TENURED);
33 // Allocates an uninitialized fixed array. It must be filled by the caller.
34 Handle<FixedArray> NewUninitializedFixedArray(int size);
36 // Allocate a new uninitialized fixed double array.
37 // The function returns a pre-allocated empty fixed array for capacity = 0,
38 // so the return type must be the general fixed array class.
39 Handle<FixedArrayBase> NewFixedDoubleArray(
41 PretenureFlag pretenure = NOT_TENURED);
43 // Allocate a new fixed double array with hole values.
44 Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles(
46 PretenureFlag pretenure = NOT_TENURED);
48 Handle<OrderedHashSet> NewOrderedHashSet();
49 Handle<OrderedHashMap> NewOrderedHashMap();
51 // Create a new boxed value.
52 Handle<Box> NewBox(Handle<Object> value);
54 // Create a new PrototypeInfo struct.
55 Handle<PrototypeInfo> NewPrototypeInfo();
57 // Create a new SloppyBlockWithEvalContextExtension struct.
58 Handle<SloppyBlockWithEvalContextExtension>
59 NewSloppyBlockWithEvalContextExtension(Handle<ScopeInfo> scope_info,
60 Handle<JSObject> extension);
62 // Create a pre-tenured empty AccessorPair.
63 Handle<AccessorPair> NewAccessorPair();
65 // Create an empty TypeFeedbackInfo.
66 Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
68 // Finds the internalized copy for string in the string table.
69 // If not found, a new string is added to the table and returned.
70 Handle<String> InternalizeUtf8String(Vector<const char> str);
71 Handle<String> InternalizeUtf8String(const char* str) {
72 return InternalizeUtf8String(CStrVector(str));
74 Handle<String> InternalizeString(Handle<String> str);
75 Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
76 Handle<String> InternalizeOneByteString(
77 Handle<SeqOneByteString>, int from, int length);
79 Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
81 template<class StringTableKey>
82 Handle<String> InternalizeStringWithKey(StringTableKey* key);
85 // String creation functions. Most of the string creation functions take
86 // a Heap::PretenureFlag argument to optionally request that they be
87 // allocated in the old generation. The pretenure flag defaults to
90 // Creates a new String object. There are two String encodings: one-byte and
91 // two-byte. One should choose between the three string factory functions
92 // based on the encoding of the string buffer that the string is
94 // - ...FromOneByte initializes the string from a buffer that is Latin1
95 // encoded (it does not check that the buffer is Latin1 encoded) and
96 // the result will be Latin1 encoded.
97 // - ...FromUtf8 initializes the string from a buffer that is UTF-8
98 // encoded. If the characters are all ASCII characters, the result
99 // will be Latin1 encoded, otherwise it will converted to two-byte.
100 // - ...FromTwoByte initializes the string from a buffer that is two-byte
101 // encoded. If the characters are all Latin1 characters, the result
102 // will be converted to Latin1, otherwise it will be left as two-byte.
104 // One-byte strings are pretenured when used as keys in the SourceCodeCache.
105 MUST_USE_RESULT MaybeHandle<String> NewStringFromOneByte(
106 Vector<const uint8_t> str,
107 PretenureFlag pretenure = NOT_TENURED);
110 inline Handle<String> NewStringFromStaticChars(
111 const char (&str)[N], PretenureFlag pretenure = NOT_TENURED) {
112 DCHECK(N == StrLength(str) + 1);
113 return NewStringFromOneByte(STATIC_CHAR_VECTOR(str), pretenure)
117 inline Handle<String> NewStringFromAsciiChecked(
119 PretenureFlag pretenure = NOT_TENURED) {
120 return NewStringFromOneByte(
121 OneByteVector(str), pretenure).ToHandleChecked();
125 // Allocates and fully initializes a String. There are two String encodings:
126 // one-byte and two-byte. One should choose between the threestring
127 // allocation functions based on the encoding of the string buffer used to
128 // initialized the string.
129 // - ...FromOneByte initializes the string from a buffer that is Latin1
130 // encoded (it does not check that the buffer is Latin1 encoded) and the
131 // result will be Latin1 encoded.
132 // - ...FromUTF8 initializes the string from a buffer that is UTF-8
133 // encoded. If the characters are all ASCII characters, the result
134 // will be Latin1 encoded, otherwise it will converted to two-byte.
135 // - ...FromTwoByte initializes the string from a buffer that is two-byte
136 // encoded. If the characters are all Latin1 characters, the
137 // result will be converted to Latin1, otherwise it will be left as
140 // TODO(dcarney): remove this function.
141 MUST_USE_RESULT inline MaybeHandle<String> NewStringFromAscii(
142 Vector<const char> str,
143 PretenureFlag pretenure = NOT_TENURED) {
144 return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure);
147 // UTF8 strings are pretenured when used for regexp literal patterns and
148 // flags in the parser.
149 MUST_USE_RESULT MaybeHandle<String> NewStringFromUtf8(
150 Vector<const char> str,
151 PretenureFlag pretenure = NOT_TENURED);
153 MUST_USE_RESULT MaybeHandle<String> NewStringFromTwoByte(
154 Vector<const uc16> str,
155 PretenureFlag pretenure = NOT_TENURED);
157 // Allocates an internalized string in old space based on the character
159 Handle<String> NewInternalizedStringFromUtf8(Vector<const char> str,
160 int chars, uint32_t hash_field);
162 Handle<String> NewOneByteInternalizedString(Vector<const uint8_t> str,
163 uint32_t hash_field);
165 Handle<String> NewOneByteInternalizedSubString(
166 Handle<SeqOneByteString> string, int offset, int length,
167 uint32_t hash_field);
169 Handle<String> NewTwoByteInternalizedString(Vector<const uc16> str,
170 uint32_t hash_field);
172 Handle<String> NewInternalizedStringImpl(Handle<String> string, int chars,
173 uint32_t hash_field);
175 // Compute the matching internalized string map for a string if possible.
176 // Empty handle is returned if string is in new space or not flattened.
177 MUST_USE_RESULT MaybeHandle<Map> InternalizedStringMapForString(
178 Handle<String> string);
180 // Allocates and partially initializes an one-byte or two-byte String. The
181 // characters of the string are uninitialized. Currently used in regexp code
182 // only, where they are pretenured.
183 MUST_USE_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString(
185 PretenureFlag pretenure = NOT_TENURED);
186 MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString(
188 PretenureFlag pretenure = NOT_TENURED);
190 // Creates a single character string where the character has given code.
191 // A cache is used for Latin1 codes.
192 Handle<String> LookupSingleCharacterStringFromCode(uint32_t code);
194 // Create a new cons string object which consists of a pair of strings.
195 MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left,
196 Handle<String> right);
198 // Create a new string object which holds a proper substring of a string.
199 Handle<String> NewProperSubString(Handle<String> str,
203 // Create a new string object which holds a substring of a string.
204 Handle<String> NewSubString(Handle<String> str, int begin, int end) {
205 if (begin == 0 && end == str->length()) return str;
206 return NewProperSubString(str, begin, end);
209 // Creates a new external String object. There are two String encodings
210 // in the system: one-byte and two-byte. Unlike other String types, it does
211 // not make sense to have a UTF-8 factory function for external strings,
212 // because we cannot change the underlying buffer. Note that these strings
213 // are backed by a string resource that resides outside the V8 heap.
214 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromOneByte(
215 const ExternalOneByteString::Resource* resource);
216 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromTwoByte(
217 const ExternalTwoByteString::Resource* resource);
220 Handle<Symbol> NewSymbol();
221 Handle<Symbol> NewPrivateSymbol(Handle<Object> name);
223 // Create a global (but otherwise uninitialized) context.
224 Handle<Context> NewNativeContext();
226 // Create a script context.
227 Handle<Context> NewScriptContext(Handle<JSFunction> function,
228 Handle<ScopeInfo> scope_info);
230 // Create an empty script context table.
231 Handle<ScriptContextTable> NewScriptContextTable();
233 // Create a module context.
234 Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
236 // Create a function context.
237 Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
239 // Create a catch context.
240 Handle<Context> NewCatchContext(Handle<JSFunction> function,
241 Handle<Context> previous,
243 Handle<Object> thrown_object);
245 // Create a 'with' context.
246 Handle<Context> NewWithContext(Handle<JSFunction> function,
247 Handle<Context> previous,
248 Handle<JSReceiver> extension);
250 // Create a block context.
251 Handle<Context> NewBlockContext(Handle<JSFunction> function,
252 Handle<Context> previous,
253 Handle<ScopeInfo> scope_info);
255 // Allocate a new struct. The struct is pretenured (allocated directly in
256 // the old generation).
257 Handle<Struct> NewStruct(InstanceType type);
259 Handle<CodeCache> NewCodeCache();
261 Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
262 int aliased_context_slot);
264 Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
266 Handle<Script> NewScript(Handle<String> source);
268 // Foreign objects are pretenured when allocated by the bootstrapper.
269 Handle<Foreign> NewForeign(Address addr,
270 PretenureFlag pretenure = NOT_TENURED);
272 // Allocate a new foreign object. The foreign is pretenured (allocated
273 // directly in the old generation).
274 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
276 Handle<ByteArray> NewByteArray(int length,
277 PretenureFlag pretenure = NOT_TENURED);
279 Handle<BytecodeArray> NewBytecodeArray(int length, const byte* raw_bytecodes,
280 int frame_size, int parameter_count,
281 Handle<FixedArray> constant_pool);
283 Handle<FixedTypedArrayBase> NewFixedTypedArrayWithExternalPointer(
284 int length, ExternalArrayType array_type, void* external_pointer,
285 PretenureFlag pretenure = NOT_TENURED);
287 Handle<FixedTypedArrayBase> NewFixedTypedArray(
288 int length, ExternalArrayType array_type, bool initialize,
289 PretenureFlag pretenure = NOT_TENURED);
291 Handle<Cell> NewCell(Handle<Object> value);
293 Handle<PropertyCell> NewPropertyCell();
295 Handle<WeakCell> NewWeakCell(Handle<HeapObject> value);
297 // Allocate a tenured AllocationSite. It's payload is null.
298 Handle<AllocationSite> NewAllocationSite();
303 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
305 Handle<HeapObject> NewFillerObject(int size,
307 AllocationSpace space);
309 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
311 Handle<JSObject> CopyJSObject(Handle<JSObject> object);
313 Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
314 Handle<AllocationSite> site);
316 Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
319 Handle<FixedArray> CopyFixedArrayAndGrow(
320 Handle<FixedArray> array, int grow_by,
321 PretenureFlag pretenure = NOT_TENURED);
323 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
325 // This method expects a COW array in new space, and creates a copy
326 // of it in old space.
327 Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
329 Handle<FixedDoubleArray> CopyFixedDoubleArray(
330 Handle<FixedDoubleArray> array);
332 // Numbers (e.g. literals) are pretenured by the parser.
333 // The return value may be a smi or a heap number.
334 Handle<Object> NewNumber(double value,
335 PretenureFlag pretenure = NOT_TENURED);
337 Handle<Object> NewNumberFromInt(int32_t value,
338 PretenureFlag pretenure = NOT_TENURED);
339 Handle<Object> NewNumberFromUint(uint32_t value,
340 PretenureFlag pretenure = NOT_TENURED);
341 Handle<Object> NewNumberFromSize(size_t value,
342 PretenureFlag pretenure = NOT_TENURED) {
343 if (Smi::IsValid(static_cast<intptr_t>(value))) {
344 return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
347 return NewNumber(static_cast<double>(value), pretenure);
349 Handle<HeapNumber> NewHeapNumber(double value,
350 MutableMode mode = IMMUTABLE,
351 PretenureFlag pretenure = NOT_TENURED);
353 #define SIMD128_NEW_DECL(TYPE, Type, type, lane_count, lane_type) \
354 Handle<Type> New##Type(lane_type lanes[lane_count], \
355 PretenureFlag pretenure = NOT_TENURED);
356 SIMD128_TYPES(SIMD128_NEW_DECL)
357 #undef SIMD128_NEW_DECL
359 // These objects are used by the api to create env-independent data
360 // structures in the heap.
361 inline Handle<JSObject> NewNeanderObject() {
362 return NewJSObjectFromMap(neander_map());
365 Handle<JSWeakMap> NewJSWeakMap();
367 Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
369 // JS objects are pretenured when allocated by the bootstrapper and
371 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
372 PretenureFlag pretenure = NOT_TENURED);
373 // JSObject that should have a memento pointing to the allocation site.
374 Handle<JSObject> NewJSObjectWithMemento(Handle<JSFunction> constructor,
375 Handle<AllocationSite> site);
377 // Global objects are pretenured and initialized based on a constructor.
378 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
380 // JS objects are pretenured when allocated by the bootstrapper and
382 Handle<JSObject> NewJSObjectFromMap(
384 PretenureFlag pretenure = NOT_TENURED,
385 Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
387 // JS modules are pretenured.
388 Handle<JSModule> NewJSModule(Handle<Context> context,
389 Handle<ScopeInfo> scope_info);
391 // JS arrays are pretenured when allocated by the parser.
393 // Create a JSArray with no elements.
394 Handle<JSArray> NewJSArray(ElementsKind elements_kind,
395 Strength strength = Strength::WEAK,
396 PretenureFlag pretenure = NOT_TENURED);
398 // Create a JSArray with a specified length and elements initialized
399 // according to the specified mode.
400 Handle<JSArray> NewJSArray(
401 ElementsKind elements_kind, int length, int capacity,
402 Strength strength = Strength::WEAK,
403 ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS,
404 PretenureFlag pretenure = NOT_TENURED);
406 Handle<JSArray> NewJSArray(
407 int capacity, ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
408 Strength strength = Strength::WEAK,
409 PretenureFlag pretenure = NOT_TENURED) {
411 elements_kind = GetHoleyElementsKind(elements_kind);
413 return NewJSArray(elements_kind, 0, capacity, strength,
414 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
417 // Create a JSArray with the given elements.
418 Handle<JSArray> NewJSArrayWithElements(Handle<FixedArrayBase> elements,
419 ElementsKind elements_kind, int length,
420 Strength strength = Strength::WEAK,
421 PretenureFlag pretenure = NOT_TENURED);
423 Handle<JSArray> NewJSArrayWithElements(
424 Handle<FixedArrayBase> elements,
425 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
426 Strength strength = Strength::WEAK,
427 PretenureFlag pretenure = NOT_TENURED) {
428 return NewJSArrayWithElements(elements, elements_kind, elements->length(),
429 strength, pretenure);
432 void NewJSArrayStorage(
433 Handle<JSArray> array,
436 ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
438 Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
440 Handle<JSArrayBuffer> NewJSArrayBuffer(
441 SharedFlag shared = SharedFlag::kNotShared,
442 PretenureFlag pretenure = NOT_TENURED);
444 Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
445 PretenureFlag pretenure = NOT_TENURED);
447 Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
448 PretenureFlag pretenure = NOT_TENURED);
450 // Creates a new JSTypedArray with the specified buffer.
451 Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
452 Handle<JSArrayBuffer> buffer,
453 size_t byte_offset, size_t length,
454 PretenureFlag pretenure = NOT_TENURED);
456 // Creates a new on-heap JSTypedArray.
457 Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
458 size_t number_of_elements,
459 PretenureFlag pretenure = NOT_TENURED);
461 Handle<JSDataView> NewJSDataView();
462 Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer,
463 size_t byte_offset, size_t byte_length);
465 Handle<JSMap> NewJSMap();
466 Handle<JSSet> NewJSSet();
468 // TODO(aandrey): Maybe these should take table, index and kind arguments.
469 Handle<JSMapIterator> NewJSMapIterator();
470 Handle<JSSetIterator> NewJSSetIterator();
472 // Creates a new JSIteratorResult object with the arguments {value} and
473 // {done}. Implemented according to ES6 section 7.4.7 CreateIterResultObject.
474 Handle<JSIteratorResult> NewJSIteratorResult(Handle<Object> value,
475 Handle<Object> done);
477 // Allocates a Harmony proxy.
478 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
480 // Allocates a Harmony function proxy.
481 Handle<JSProxy> NewJSFunctionProxy(Handle<Object> handler,
482 Handle<JSReceiver> call_trap,
483 Handle<Object> construct_trap,
484 Handle<Object> prototype);
486 // Reinitialize an JSGlobalProxy based on a constructor. The object
487 // must have the same size as objects allocated using the
488 // constructor. The object is reinitialized and behaves as an
489 // object that has been freshly allocated using the constructor.
490 void ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> global,
491 Handle<JSFunction> constructor);
493 Handle<JSGlobalProxy> NewUninitializedJSGlobalProxy();
495 // Change the type of the argument into a JS object/function and reinitialize.
496 void BecomeJSObject(Handle<JSProxy> object);
497 void BecomeJSFunction(Handle<JSProxy> object);
499 Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
500 Handle<Object> prototype,
501 bool read_only_prototype = false,
502 bool is_strict = false);
503 Handle<JSFunction> NewFunction(Handle<String> name);
504 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
506 bool is_strict = false);
508 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
509 Handle<SharedFunctionInfo> function_info,
510 Handle<Context> context,
511 PretenureFlag pretenure = TENURED);
513 Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
514 Handle<Object> prototype, InstanceType type,
516 bool read_only_prototype = false,
517 bool install_constructor = false,
518 bool is_strict = false);
519 Handle<JSFunction> NewFunction(Handle<String> name,
524 // Create a serialized scope info.
525 Handle<ScopeInfo> NewScopeInfo(int length);
527 // Create an External object for V8's external API.
528 Handle<JSObject> NewExternal(void* value);
530 // The reference to the Code object is stored in self_reference.
531 // This allows generated code to reference its own Code object
532 // by containing this handle.
533 Handle<Code> NewCode(const CodeDesc& desc,
535 Handle<Object> self_reference,
536 bool immovable = false,
537 bool crankshafted = false,
538 int prologue_offset = Code::kPrologueOffsetNotSet,
539 bool is_debug = false);
541 Handle<Code> CopyCode(Handle<Code> code);
543 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
545 // Interface for creating error objects.
546 Handle<Object> NewError(Handle<JSFunction> constructor,
547 Handle<String> message);
549 Handle<Object> NewInvalidStringLengthError() {
550 return NewRangeError(MessageTemplate::kInvalidStringLength);
553 Handle<Object> NewError(Handle<JSFunction> constructor,
554 MessageTemplate::Template template_index,
555 Handle<Object> arg0 = Handle<Object>(),
556 Handle<Object> arg1 = Handle<Object>(),
557 Handle<Object> arg2 = Handle<Object>());
559 #define DECLARE_ERROR(NAME) \
560 Handle<Object> New##NAME(MessageTemplate::Template template_index, \
561 Handle<Object> arg0 = Handle<Object>(), \
562 Handle<Object> arg1 = Handle<Object>(), \
563 Handle<Object> arg2 = Handle<Object>());
565 DECLARE_ERROR(EvalError)
566 DECLARE_ERROR(RangeError)
567 DECLARE_ERROR(ReferenceError)
568 DECLARE_ERROR(SyntaxError)
569 DECLARE_ERROR(TypeError)
572 Handle<String> NumberToString(Handle<Object> number,
573 bool check_number_string_cache = true);
575 Handle<String> Uint32ToString(uint32_t value) {
576 return NumberToString(NewNumberFromUint(value));
579 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
581 #define ROOT_ACCESSOR(type, name, camel_name) \
582 inline Handle<type> name() { \
583 return Handle<type>(bit_cast<type**>( \
584 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
586 ROOT_LIST(ROOT_ACCESSOR)
589 #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
590 inline Handle<Map> name##_map() { \
591 return Handle<Map>(bit_cast<Map**>( \
592 &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \
594 STRUCT_LIST(STRUCT_MAP_ACCESSOR)
595 #undef STRUCT_MAP_ACCESSOR
597 #define STRING_ACCESSOR(name, str) \
598 inline Handle<String> name() { \
599 return Handle<String>(bit_cast<String**>( \
600 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
602 INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
603 #undef STRING_ACCESSOR
605 #define SYMBOL_ACCESSOR(name) \
606 inline Handle<Symbol> name() { \
607 return Handle<Symbol>(bit_cast<Symbol**>( \
608 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
610 PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
611 #undef SYMBOL_ACCESSOR
613 #define SYMBOL_ACCESSOR(name, description) \
614 inline Handle<Symbol> name() { \
615 return Handle<Symbol>(bit_cast<Symbol**>( \
616 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
618 PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
619 #undef SYMBOL_ACCESSOR
621 // Allocates a new SharedFunctionInfo object.
622 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
623 Handle<String> name, int number_of_literals, FunctionKind kind,
624 Handle<Code> code, Handle<ScopeInfo> scope_info,
625 Handle<TypeFeedbackVector> feedback_vector);
626 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name,
627 MaybeHandle<Code> code);
629 // Allocate a new type feedback vector
630 template <typename Spec>
631 Handle<TypeFeedbackVector> NewTypeFeedbackVector(const Spec* spec);
633 // Allocates a new JSMessageObject object.
634 Handle<JSMessageObject> NewJSMessageObject(MessageTemplate::Template message,
635 Handle<Object> argument,
638 Handle<Object> script,
639 Handle<Object> stack_frames);
641 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
643 // Return a map for given number of properties using the map cache in the
645 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
646 int number_of_properties,
648 bool* is_result_from_cache);
650 // Creates a new FixedArray that holds the data associated with the
651 // atom regexp and stores it in the regexp.
652 void SetRegExpAtomData(Handle<JSRegExp> regexp,
654 Handle<String> source,
655 JSRegExp::Flags flags,
656 Handle<Object> match_pattern);
658 // Creates a new FixedArray that holds the data associated with the
659 // irregexp regexp and stores it in the regexp.
660 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
662 Handle<String> source,
663 JSRegExp::Flags flags,
666 // Returns the value for a known global constant (a property of the global
667 // object which is neither configurable nor writable) like 'undefined'.
668 // Returns a null handle when the given name is unknown.
669 Handle<Object> GlobalConstantFor(Handle<Name> name);
671 // Converts the given boolean condition to JavaScript boolean value.
672 Handle<Object> ToBoolean(bool value);
675 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
677 // Creates a heap object based on the map. The fields of the heap object are
678 // not initialized by New<>() functions. It's the responsibility of the caller
681 Handle<T> New(Handle<Map> map, AllocationSpace space);
684 Handle<T> New(Handle<Map> map,
685 AllocationSpace space,
686 Handle<AllocationSite> allocation_site);
688 // Creates a code object that is not yet fully initialized yet.
689 inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
691 // Attempt to find the number in a small cache. If we finds it, return
692 // the string representation of the number. Otherwise return undefined.
693 Handle<Object> GetNumberStringCache(Handle<Object> number);
695 // Update the cache with a new number-string pair.
696 void SetNumberStringCache(Handle<Object> number, Handle<String> string);
698 // Initializes a function with a shared part and prototype.
699 // Note: this code was factored out of NewFunction such that other parts of
700 // the VM could use it. Specifically, a function that creates instances of
701 // type JS_FUNCTION_TYPE benefit from the use of this function.
702 inline void InitializeFunction(Handle<JSFunction> function,
703 Handle<SharedFunctionInfo> info,
704 Handle<Context> context);
706 // Creates a function initialized with a shared part.
707 Handle<JSFunction> NewFunction(Handle<Map> map,
708 Handle<SharedFunctionInfo> info,
709 Handle<Context> context,
710 PretenureFlag pretenure = TENURED);
712 Handle<JSFunction> NewFunction(Handle<Map> map,
714 MaybeHandle<Code> maybe_code);
716 // Reinitialize a JSProxy into an (empty) JS object of respective type and
717 // size, but keeping the original prototype. The receiver must have at least
718 // the size of the new object. The object is reinitialized and behaves as an
719 // object that has been freshly allocated.
720 void ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, int size);
723 } } // namespace v8::internal
725 #endif // V8_FACTORY_H_