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 FeedbackVectorSpec;
16 // Interface for handle based allocation.
19 Handle<Oddball> NewOddball(Handle<Map> map,
20 const char* to_string,
21 Handle<Object> to_number,
24 // Allocates a fixed array initialized with undefined values.
25 Handle<FixedArray> NewFixedArray(
27 PretenureFlag pretenure = NOT_TENURED);
29 // Allocate a new fixed array with non-existing entries (the hole).
30 Handle<FixedArray> NewFixedArrayWithHoles(
32 PretenureFlag pretenure = NOT_TENURED);
34 // Allocates an uninitialized fixed array. It must be filled by the caller.
35 Handle<FixedArray> NewUninitializedFixedArray(int size);
37 // Allocate a new uninitialized fixed double array.
38 // The function returns a pre-allocated empty fixed array for capacity = 0,
39 // so the return type must be the general fixed array class.
40 Handle<FixedArrayBase> NewFixedDoubleArray(
42 PretenureFlag pretenure = NOT_TENURED);
44 // Allocate a new fixed double array with hole values.
45 Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles(
47 PretenureFlag pretenure = NOT_TENURED);
49 Handle<OrderedHashSet> NewOrderedHashSet();
50 Handle<OrderedHashMap> NewOrderedHashMap();
52 // Create a new boxed value.
53 Handle<Box> NewBox(Handle<Object> value);
55 // Create a new PrototypeInfo struct.
56 Handle<PrototypeInfo> NewPrototypeInfo();
58 // Create a pre-tenured empty AccessorPair.
59 Handle<AccessorPair> NewAccessorPair();
61 // Create an empty TypeFeedbackInfo.
62 Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
64 // Finds the internalized copy for string in the string table.
65 // If not found, a new string is added to the table and returned.
66 Handle<String> InternalizeUtf8String(Vector<const char> str);
67 Handle<String> InternalizeUtf8String(const char* str) {
68 return InternalizeUtf8String(CStrVector(str));
70 Handle<String> InternalizeString(Handle<String> str);
71 Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
72 Handle<String> InternalizeOneByteString(
73 Handle<SeqOneByteString>, int from, int length);
75 Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
77 template<class StringTableKey>
78 Handle<String> InternalizeStringWithKey(StringTableKey* key);
81 // String creation functions. Most of the string creation functions take
82 // a Heap::PretenureFlag argument to optionally request that they be
83 // allocated in the old generation. The pretenure flag defaults to
86 // Creates a new String object. There are two String encodings: one-byte and
87 // two-byte. One should choose between the three string factory functions
88 // based on the encoding of the string buffer that the string is
90 // - ...FromOneByte initializes the string from a buffer that is Latin1
91 // encoded (it does not check that the buffer is Latin1 encoded) and
92 // the result will be Latin1 encoded.
93 // - ...FromUtf8 initializes the string from a buffer that is UTF-8
94 // encoded. If the characters are all ASCII characters, the result
95 // will be Latin1 encoded, otherwise it will converted to two-byte.
96 // - ...FromTwoByte initializes the string from a buffer that is two-byte
97 // encoded. If the characters are all Latin1 characters, the result
98 // will be converted to Latin1, otherwise it will be left as two-byte.
100 // One-byte strings are pretenured when used as keys in the SourceCodeCache.
101 MUST_USE_RESULT MaybeHandle<String> NewStringFromOneByte(
102 Vector<const uint8_t> str,
103 PretenureFlag pretenure = NOT_TENURED);
106 inline Handle<String> NewStringFromStaticChars(
107 const char (&str)[N], PretenureFlag pretenure = NOT_TENURED) {
108 DCHECK(N == StrLength(str) + 1);
109 return NewStringFromOneByte(STATIC_CHAR_VECTOR(str), pretenure)
113 inline Handle<String> NewStringFromAsciiChecked(
115 PretenureFlag pretenure = NOT_TENURED) {
116 return NewStringFromOneByte(
117 OneByteVector(str), pretenure).ToHandleChecked();
121 // Allocates and fully initializes a String. There are two String encodings:
122 // one-byte and two-byte. One should choose between the threestring
123 // allocation functions based on the encoding of the string buffer used to
124 // initialized the string.
125 // - ...FromOneByte initializes the string from a buffer that is Latin1
126 // encoded (it does not check that the buffer is Latin1 encoded) and the
127 // result will be Latin1 encoded.
128 // - ...FromUTF8 initializes the string from a buffer that is UTF-8
129 // encoded. If the characters are all ASCII characters, the result
130 // will be Latin1 encoded, otherwise it will converted to two-byte.
131 // - ...FromTwoByte initializes the string from a buffer that is two-byte
132 // encoded. If the characters are all Latin1 characters, the
133 // result will be converted to Latin1, otherwise it will be left as
136 // TODO(dcarney): remove this function.
137 MUST_USE_RESULT inline MaybeHandle<String> NewStringFromAscii(
138 Vector<const char> str,
139 PretenureFlag pretenure = NOT_TENURED) {
140 return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure);
143 // UTF8 strings are pretenured when used for regexp literal patterns and
144 // flags in the parser.
145 MUST_USE_RESULT MaybeHandle<String> NewStringFromUtf8(
146 Vector<const char> str,
147 PretenureFlag pretenure = NOT_TENURED);
149 MUST_USE_RESULT MaybeHandle<String> NewStringFromTwoByte(
150 Vector<const uc16> str,
151 PretenureFlag pretenure = NOT_TENURED);
153 // Allocates an internalized string in old space based on the character
155 MUST_USE_RESULT Handle<String> NewInternalizedStringFromUtf8(
156 Vector<const char> str,
158 uint32_t hash_field);
160 MUST_USE_RESULT Handle<String> NewOneByteInternalizedString(
161 Vector<const uint8_t> str, uint32_t hash_field);
163 MUST_USE_RESULT Handle<String> NewOneByteInternalizedSubString(
164 Handle<SeqOneByteString> string, int offset, int length,
165 uint32_t hash_field);
167 MUST_USE_RESULT Handle<String> NewTwoByteInternalizedString(
168 Vector<const uc16> str,
169 uint32_t hash_field);
171 MUST_USE_RESULT Handle<String> NewInternalizedStringImpl(
172 Handle<String> string, int chars, uint32_t hash_field);
174 // Compute the matching internalized string map for a string if possible.
175 // Empty handle is returned if string is in new space or not flattened.
176 MUST_USE_RESULT MaybeHandle<Map> InternalizedStringMapForString(
177 Handle<String> string);
179 // Allocates and partially initializes an one-byte or two-byte String. The
180 // characters of the string are uninitialized. Currently used in regexp code
181 // only, where they are pretenured.
182 MUST_USE_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString(
184 PretenureFlag pretenure = NOT_TENURED);
185 MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString(
187 PretenureFlag pretenure = NOT_TENURED);
189 // Creates a single character string where the character has given code.
190 // A cache is used for Latin1 codes.
191 Handle<String> LookupSingleCharacterStringFromCode(uint32_t code);
193 // Create a new cons string object which consists of a pair of strings.
194 MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left,
195 Handle<String> right);
196 MUST_USE_RESULT MaybeHandle<String> NewOneByteConsString(
197 int length, Handle<String> left, Handle<String> right);
198 MUST_USE_RESULT MaybeHandle<String> NewTwoByteConsString(
199 int length, Handle<String> left, Handle<String> right);
200 MUST_USE_RESULT MaybeHandle<String> NewRawConsString(Handle<Map> map,
203 Handle<String> right);
205 // Create a new string object which holds a proper substring of a string.
206 Handle<String> NewProperSubString(Handle<String> str,
210 // Create a new string object which holds a substring of a string.
211 Handle<String> NewSubString(Handle<String> str, int begin, int end) {
212 if (begin == 0 && end == str->length()) return str;
213 return NewProperSubString(str, begin, end);
216 // Creates a new external String object. There are two String encodings
217 // in the system: one-byte and two-byte. Unlike other String types, it does
218 // not make sense to have a UTF-8 factory function for external strings,
219 // because we cannot change the underlying buffer. Note that these strings
220 // are backed by a string resource that resides outside the V8 heap.
221 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromOneByte(
222 const ExternalOneByteString::Resource* resource);
223 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromTwoByte(
224 const ExternalTwoByteString::Resource* resource);
227 Handle<Symbol> NewSymbol();
228 Handle<Symbol> NewPrivateSymbol();
229 Handle<Symbol> NewPrivateOwnSymbol(Handle<Object> name);
231 // Create a global (but otherwise uninitialized) context.
232 Handle<Context> NewNativeContext();
234 // Create a script context.
235 Handle<Context> NewScriptContext(Handle<JSFunction> function,
236 Handle<ScopeInfo> scope_info);
238 // Create an empty script context table.
239 Handle<ScriptContextTable> NewScriptContextTable();
241 // Create a module context.
242 Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
244 // Create a function context.
245 Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
247 // Create a catch context.
248 Handle<Context> NewCatchContext(Handle<JSFunction> function,
249 Handle<Context> previous,
251 Handle<Object> thrown_object);
253 // Create a 'with' context.
254 Handle<Context> NewWithContext(Handle<JSFunction> function,
255 Handle<Context> previous,
256 Handle<JSReceiver> extension);
258 // Create a block context.
259 Handle<Context> NewBlockContext(Handle<JSFunction> function,
260 Handle<Context> previous,
261 Handle<ScopeInfo> scope_info);
263 // Allocate a new struct. The struct is pretenured (allocated directly in
264 // the old generation).
265 Handle<Struct> NewStruct(InstanceType type);
267 Handle<CodeCache> NewCodeCache();
269 Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
270 int aliased_context_slot);
272 Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
274 Handle<Script> NewScript(Handle<String> source);
276 // Foreign objects are pretenured when allocated by the bootstrapper.
277 Handle<Foreign> NewForeign(Address addr,
278 PretenureFlag pretenure = NOT_TENURED);
280 // Allocate a new foreign object. The foreign is pretenured (allocated
281 // directly in the old generation).
282 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
284 Handle<ByteArray> NewByteArray(int length,
285 PretenureFlag pretenure = NOT_TENURED);
287 Handle<ExternalArray> NewExternalArray(
289 ExternalArrayType array_type,
290 void* external_pointer,
291 PretenureFlag pretenure = NOT_TENURED);
293 Handle<FixedTypedArrayBase> NewFixedTypedArray(
294 int length, ExternalArrayType array_type, bool initialize,
295 PretenureFlag pretenure = NOT_TENURED);
297 Handle<Cell> NewCell(Handle<Object> value);
299 Handle<PropertyCell> NewPropertyCell();
301 Handle<WeakCell> NewWeakCell(Handle<HeapObject> value);
303 // Allocate a tenured AllocationSite. It's payload is null.
304 Handle<AllocationSite> NewAllocationSite();
309 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
311 Handle<HeapObject> NewFillerObject(int size,
313 AllocationSpace space);
315 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
317 Handle<JSObject> CopyJSObject(Handle<JSObject> object);
319 Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
320 Handle<AllocationSite> site);
322 Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
325 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
327 // This method expects a COW array in new space, and creates a copy
328 // of it in old space.
329 Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
331 Handle<FixedDoubleArray> CopyFixedDoubleArray(
332 Handle<FixedDoubleArray> array);
334 // Numbers (e.g. literals) are pretenured by the parser.
335 // The return value may be a smi or a heap number.
336 Handle<Object> NewNumber(double value,
337 PretenureFlag pretenure = NOT_TENURED);
339 Handle<Object> NewNumberFromInt(int32_t value,
340 PretenureFlag pretenure = NOT_TENURED);
341 Handle<Object> NewNumberFromUint(uint32_t value,
342 PretenureFlag pretenure = NOT_TENURED);
343 Handle<Object> NewNumberFromSize(size_t value,
344 PretenureFlag pretenure = NOT_TENURED) {
345 if (Smi::IsValid(static_cast<intptr_t>(value))) {
346 return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
349 return NewNumber(static_cast<double>(value), pretenure);
351 Handle<HeapNumber> NewHeapNumber(double value,
352 MutableMode mode = IMMUTABLE,
353 PretenureFlag pretenure = NOT_TENURED);
354 Handle<Float32x4> NewFloat32x4(float w, float x, float y, float z,
355 PretenureFlag pretenure = NOT_TENURED);
357 // These objects are used by the api to create env-independent data
358 // structures in the heap.
359 inline Handle<JSObject> NewNeanderObject() {
360 return NewJSObjectFromMap(neander_map());
363 Handle<JSWeakMap> NewJSWeakMap();
365 Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
367 // JS objects are pretenured when allocated by the bootstrapper and
369 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
370 PretenureFlag pretenure = NOT_TENURED);
371 // JSObject that should have a memento pointing to the allocation site.
372 Handle<JSObject> NewJSObjectWithMemento(Handle<JSFunction> constructor,
373 Handle<AllocationSite> site);
375 // Global objects are pretenured and initialized based on a constructor.
376 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
378 // JS objects are pretenured when allocated by the bootstrapper and
380 Handle<JSObject> NewJSObjectFromMap(
382 PretenureFlag pretenure = NOT_TENURED,
383 bool allocate_properties = true,
384 Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
386 // JS modules are pretenured.
387 Handle<JSModule> NewJSModule(Handle<Context> context,
388 Handle<ScopeInfo> scope_info);
390 // JS arrays are pretenured when allocated by the parser.
392 // Create a JSArray with no elements.
393 Handle<JSArray> NewJSArray(
394 ElementsKind elements_kind,
395 ObjectStrength 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 ObjectStrength strength = WEAK,
403 ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS,
404 PretenureFlag pretenure = NOT_TENURED);
406 Handle<JSArray> NewJSArray(
408 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
409 ObjectStrength strength = WEAK,
410 PretenureFlag pretenure = NOT_TENURED) {
412 elements_kind = GetHoleyElementsKind(elements_kind);
414 return NewJSArray(elements_kind, 0, capacity, strength,
415 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
418 // Create a JSArray with the given elements.
419 Handle<JSArray> NewJSArrayWithElements(
420 Handle<FixedArrayBase> elements,
421 ElementsKind elements_kind,
423 ObjectStrength strength = WEAK,
424 PretenureFlag pretenure = NOT_TENURED);
426 Handle<JSArray> NewJSArrayWithElements(
427 Handle<FixedArrayBase> elements,
428 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
429 ObjectStrength strength = WEAK,
430 PretenureFlag pretenure = NOT_TENURED) {
431 return NewJSArrayWithElements(elements, elements_kind, elements->length(),
432 strength, pretenure);
435 void NewJSArrayStorage(
436 Handle<JSArray> array,
439 ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
441 Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
443 Handle<JSArrayBuffer> NewJSArrayBuffer(
444 SharedFlag shared = SharedFlag::kNotShared);
446 Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
448 Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind);
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);
455 // Creates a new on-heap JSTypedArray.
456 Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
457 size_t number_of_elements);
459 Handle<JSDataView> NewJSDataView();
460 Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer,
461 size_t byte_offset, size_t byte_length);
463 Handle<JSMap> NewJSMap();
464 Handle<JSSet> NewJSSet();
466 // TODO(aandrey): Maybe these should take table, index and kind arguments.
467 Handle<JSMapIterator> NewJSMapIterator();
468 Handle<JSSetIterator> NewJSSetIterator();
470 // Allocates a Harmony proxy.
471 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
473 // Allocates a Harmony function proxy.
474 Handle<JSProxy> NewJSFunctionProxy(Handle<Object> handler,
475 Handle<Object> call_trap,
476 Handle<Object> construct_trap,
477 Handle<Object> prototype);
479 // Reinitialize an JSGlobalProxy based on a constructor. The object
480 // must have the same size as objects allocated using the
481 // constructor. The object is reinitialized and behaves as an
482 // object that has been freshly allocated using the constructor.
483 void ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> global,
484 Handle<JSFunction> constructor);
486 Handle<JSGlobalProxy> NewUninitializedJSGlobalProxy();
488 // Change the type of the argument into a JS object/function and reinitialize.
489 void BecomeJSObject(Handle<JSProxy> object);
490 void BecomeJSFunction(Handle<JSProxy> object);
492 Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
493 Handle<Object> prototype,
494 bool read_only_prototype = false,
495 bool is_strict = false);
496 Handle<JSFunction> NewFunction(Handle<String> name);
497 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
499 bool is_strict = false);
501 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
502 Handle<SharedFunctionInfo> function_info,
503 Handle<Context> context,
504 PretenureFlag pretenure = TENURED);
506 Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
507 Handle<Object> prototype, InstanceType type,
509 bool read_only_prototype = false,
510 bool install_constructor = false,
511 bool is_strict = false);
512 Handle<JSFunction> NewFunction(Handle<String> name,
517 // Create a serialized scope info.
518 Handle<ScopeInfo> NewScopeInfo(int length);
520 // Create an External object for V8's external API.
521 Handle<JSObject> NewExternal(void* value);
523 // The reference to the Code object is stored in self_reference.
524 // This allows generated code to reference its own Code object
525 // by containing this handle.
526 Handle<Code> NewCode(const CodeDesc& desc,
528 Handle<Object> self_reference,
529 bool immovable = false,
530 bool crankshafted = false,
531 int prologue_offset = Code::kPrologueOffsetNotSet,
532 bool is_debug = false);
534 Handle<Code> CopyCode(Handle<Code> code);
536 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
538 // Interface for creating error objects.
540 Handle<Object> NewError(const char* maker, const char* message,
541 Handle<JSArray> args);
542 Handle<String> EmergencyNewError(const char* message, Handle<JSArray> args);
544 Handle<Object> NewError(const char* constructor, Handle<String> message);
546 Handle<Object> NewInvalidStringLengthError() {
547 return NewRangeError(MessageTemplate::kInvalidStringLength);
550 Handle<Object> NewError(const char* maker,
551 MessageTemplate::Template template_index,
552 Handle<Object> arg0 = Handle<Object>(),
553 Handle<Object> arg1 = Handle<Object>(),
554 Handle<Object> arg2 = Handle<Object>());
556 Handle<Object> NewError(MessageTemplate::Template template_index,
557 Handle<Object> arg0 = Handle<Object>(),
558 Handle<Object> arg1 = Handle<Object>(),
559 Handle<Object> arg2 = Handle<Object>());
561 Handle<Object> NewTypeError(MessageTemplate::Template template_index,
562 Handle<Object> arg0 = Handle<Object>(),
563 Handle<Object> arg1 = Handle<Object>(),
564 Handle<Object> arg2 = Handle<Object>());
566 Handle<Object> NewSyntaxError(MessageTemplate::Template template_index,
567 Handle<Object> arg0 = Handle<Object>(),
568 Handle<Object> arg1 = Handle<Object>(),
569 Handle<Object> arg2 = Handle<Object>());
571 Handle<Object> NewReferenceError(MessageTemplate::Template template_index,
572 Handle<Object> arg0 = Handle<Object>(),
573 Handle<Object> arg1 = Handle<Object>(),
574 Handle<Object> arg2 = Handle<Object>());
576 Handle<Object> NewRangeError(MessageTemplate::Template template_index,
577 Handle<Object> arg0 = Handle<Object>(),
578 Handle<Object> arg1 = Handle<Object>(),
579 Handle<Object> arg2 = Handle<Object>());
581 Handle<Object> NewEvalError(MessageTemplate::Template template_index,
582 Handle<Object> arg0 = Handle<Object>(),
583 Handle<Object> arg1 = Handle<Object>(),
584 Handle<Object> arg2 = Handle<Object>());
586 Handle<String> NumberToString(Handle<Object> number,
587 bool check_number_string_cache = true);
589 Handle<String> Uint32ToString(uint32_t value) {
590 return NumberToString(NewNumberFromUint(value));
593 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
595 #define ROOT_ACCESSOR(type, name, camel_name) \
596 inline Handle<type> name() { \
597 return Handle<type>(bit_cast<type**>( \
598 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
600 ROOT_LIST(ROOT_ACCESSOR)
603 #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
604 inline Handle<Map> name##_map() { \
605 return Handle<Map>(bit_cast<Map**>( \
606 &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \
608 STRUCT_LIST(STRUCT_MAP_ACCESSOR)
609 #undef STRUCT_MAP_ACCESSOR
611 #define STRING_ACCESSOR(name, str) \
612 inline Handle<String> name() { \
613 return Handle<String>(bit_cast<String**>( \
614 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
616 INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
617 #undef STRING_ACCESSOR
619 #define SYMBOL_ACCESSOR(name) \
620 inline Handle<Symbol> name() { \
621 return Handle<Symbol>(bit_cast<Symbol**>( \
622 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
624 PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
625 #undef SYMBOL_ACCESSOR
627 #define SYMBOL_ACCESSOR(name, varname, description) \
628 inline Handle<Symbol> name() { \
629 return Handle<Symbol>(bit_cast<Symbol**>( \
630 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
632 PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
633 #undef SYMBOL_ACCESSOR
635 inline void set_string_table(Handle<StringTable> table) {
636 isolate()->heap()->set_string_table(*table);
639 inline void set_weak_stack_trace_list(Handle<WeakFixedArray> list) {
640 isolate()->heap()->set_weak_stack_trace_list(*list);
643 Handle<String> hidden_string() {
644 return Handle<String>(&isolate()->heap()->hidden_string_);
647 // Allocates a new SharedFunctionInfo object.
648 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
649 Handle<String> name, int number_of_literals, FunctionKind kind,
650 Handle<Code> code, Handle<ScopeInfo> scope_info,
651 Handle<TypeFeedbackVector> feedback_vector);
652 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name,
653 MaybeHandle<Code> code);
655 // Allocate a new type feedback vector
656 template <typename Spec>
657 Handle<TypeFeedbackVector> NewTypeFeedbackVector(const Spec* spec);
659 // Allocates a new JSMessageObject object.
660 Handle<JSMessageObject> NewJSMessageObject(MessageTemplate::Template message,
661 Handle<Object> argument,
664 Handle<Object> script,
665 Handle<Object> stack_frames);
667 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
669 // Return a map for given number of properties using the map cache in the
671 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
672 int number_of_properties,
674 bool* is_result_from_cache);
676 // Creates a new FixedArray that holds the data associated with the
677 // atom regexp and stores it in the regexp.
678 void SetRegExpAtomData(Handle<JSRegExp> regexp,
680 Handle<String> source,
681 JSRegExp::Flags flags,
682 Handle<Object> match_pattern);
684 // Creates a new FixedArray that holds the data associated with the
685 // irregexp regexp and stores it in the regexp.
686 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
688 Handle<String> source,
689 JSRegExp::Flags flags,
692 // Returns the value for a known global constant (a property of the global
693 // object which is neither configurable nor writable) like 'undefined'.
694 // Returns a null handle when the given name is unknown.
695 Handle<Object> GlobalConstantFor(Handle<Name> name);
697 // Converts the given boolean condition to JavaScript boolean value.
698 Handle<Object> ToBoolean(bool value);
701 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
703 // Creates a heap object based on the map. The fields of the heap object are
704 // not initialized by New<>() functions. It's the responsibility of the caller
707 Handle<T> New(Handle<Map> map, AllocationSpace space);
710 Handle<T> New(Handle<Map> map,
711 AllocationSpace space,
712 Handle<AllocationSite> allocation_site);
714 // Creates a code object that is not yet fully initialized yet.
715 inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
717 // Attempt to find the number in a small cache. If we finds it, return
718 // the string representation of the number. Otherwise return undefined.
719 Handle<Object> GetNumberStringCache(Handle<Object> number);
721 // Update the cache with a new number-string pair.
722 void SetNumberStringCache(Handle<Object> number, Handle<String> string);
724 // Initializes a function with a shared part and prototype.
725 // Note: this code was factored out of NewFunction such that other parts of
726 // the VM could use it. Specifically, a function that creates instances of
727 // type JS_FUNCTION_TYPE benefit from the use of this function.
728 inline void InitializeFunction(Handle<JSFunction> function,
729 Handle<SharedFunctionInfo> info,
730 Handle<Context> context);
732 // Creates a function initialized with a shared part.
733 Handle<JSFunction> NewFunction(Handle<Map> map,
734 Handle<SharedFunctionInfo> info,
735 Handle<Context> context,
736 PretenureFlag pretenure = TENURED);
738 Handle<JSFunction> NewFunction(Handle<Map> map,
740 MaybeHandle<Code> maybe_code);
742 // Reinitialize a JSProxy into an (empty) JS object of respective type and
743 // size, but keeping the original prototype. The receiver must have at least
744 // the size of the new object. The object is reinitialized and behaves as an
745 // object that has been freshly allocated.
746 void ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, int size);
749 } } // namespace v8::internal
751 #endif // V8_FACTORY_H_