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(Handle<Object> name);
230 // Create a global (but otherwise uninitialized) context.
231 Handle<Context> NewNativeContext();
233 // Create a script context.
234 Handle<Context> NewScriptContext(Handle<JSFunction> function,
235 Handle<ScopeInfo> scope_info);
237 // Create an empty script context table.
238 Handle<ScriptContextTable> NewScriptContextTable();
240 // Create a module context.
241 Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
243 // Create a function context.
244 Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
246 // Create a catch context.
247 Handle<Context> NewCatchContext(Handle<JSFunction> function,
248 Handle<Context> previous,
250 Handle<Object> thrown_object);
252 // Create a 'with' context.
253 Handle<Context> NewWithContext(Handle<JSFunction> function,
254 Handle<Context> previous,
255 Handle<JSReceiver> extension);
257 // Create a block context.
258 Handle<Context> NewBlockContext(Handle<JSFunction> function,
259 Handle<Context> previous,
260 Handle<ScopeInfo> scope_info);
262 // Allocate a new struct. The struct is pretenured (allocated directly in
263 // the old generation).
264 Handle<Struct> NewStruct(InstanceType type);
266 Handle<CodeCache> NewCodeCache();
268 Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
269 int aliased_context_slot);
271 Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
273 Handle<Script> NewScript(Handle<String> source);
275 // Foreign objects are pretenured when allocated by the bootstrapper.
276 Handle<Foreign> NewForeign(Address addr,
277 PretenureFlag pretenure = NOT_TENURED);
279 // Allocate a new foreign object. The foreign is pretenured (allocated
280 // directly in the old generation).
281 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
283 Handle<ByteArray> NewByteArray(int length,
284 PretenureFlag pretenure = NOT_TENURED);
286 Handle<BytecodeArray> NewBytecodeArray(int length, const byte* raw_bytecodes,
289 Handle<ExternalArray> NewExternalArray(
291 ExternalArrayType array_type,
292 void* external_pointer,
293 PretenureFlag pretenure = NOT_TENURED);
295 Handle<FixedTypedArrayBase> NewFixedTypedArray(
296 int length, ExternalArrayType array_type, bool initialize,
297 PretenureFlag pretenure = NOT_TENURED);
299 Handle<Cell> NewCell(Handle<Object> value);
301 Handle<PropertyCell> NewPropertyCell();
303 Handle<WeakCell> NewWeakCell(Handle<HeapObject> value);
305 // Allocate a tenured AllocationSite. It's payload is null.
306 Handle<AllocationSite> NewAllocationSite();
311 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
313 Handle<HeapObject> NewFillerObject(int size,
315 AllocationSpace space);
317 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
319 Handle<JSObject> CopyJSObject(Handle<JSObject> object);
321 Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
322 Handle<AllocationSite> site);
324 Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
327 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
329 // This method expects a COW array in new space, and creates a copy
330 // of it in old space.
331 Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
333 Handle<FixedDoubleArray> CopyFixedDoubleArray(
334 Handle<FixedDoubleArray> array);
336 // Numbers (e.g. literals) are pretenured by the parser.
337 // The return value may be a smi or a heap number.
338 Handle<Object> NewNumber(double value,
339 PretenureFlag pretenure = NOT_TENURED);
341 Handle<Object> NewNumberFromInt(int32_t value,
342 PretenureFlag pretenure = NOT_TENURED);
343 Handle<Object> NewNumberFromUint(uint32_t value,
344 PretenureFlag pretenure = NOT_TENURED);
345 Handle<Object> NewNumberFromSize(size_t value,
346 PretenureFlag pretenure = NOT_TENURED) {
347 if (Smi::IsValid(static_cast<intptr_t>(value))) {
348 return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
351 return NewNumber(static_cast<double>(value), pretenure);
353 Handle<HeapNumber> NewHeapNumber(double value,
354 MutableMode mode = IMMUTABLE,
355 PretenureFlag pretenure = NOT_TENURED);
356 Handle<Float32x4> NewFloat32x4(float w, float x, float y, float z,
357 PretenureFlag pretenure = NOT_TENURED);
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);
443 Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
445 Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind);
447 // Creates a new JSTypedArray with the specified buffer.
448 Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
449 Handle<JSArrayBuffer> buffer,
450 size_t byte_offset, size_t length);
452 // Creates a new on-heap JSTypedArray.
453 Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
454 size_t number_of_elements);
456 Handle<JSDataView> NewJSDataView();
457 Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer,
458 size_t byte_offset, size_t byte_length);
460 Handle<JSMap> NewJSMap();
461 Handle<JSSet> NewJSSet();
463 // TODO(aandrey): Maybe these should take table, index and kind arguments.
464 Handle<JSMapIterator> NewJSMapIterator();
465 Handle<JSSetIterator> NewJSSetIterator();
467 // Allocates a Harmony proxy.
468 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
470 // Allocates a Harmony function proxy.
471 Handle<JSProxy> NewJSFunctionProxy(Handle<Object> handler,
472 Handle<Object> call_trap,
473 Handle<Object> construct_trap,
474 Handle<Object> prototype);
476 // Reinitialize an JSGlobalProxy based on a constructor. The object
477 // must have the same size as objects allocated using the
478 // constructor. The object is reinitialized and behaves as an
479 // object that has been freshly allocated using the constructor.
480 void ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> global,
481 Handle<JSFunction> constructor);
483 Handle<JSGlobalProxy> NewUninitializedJSGlobalProxy();
485 // Change the type of the argument into a JS object/function and reinitialize.
486 void BecomeJSObject(Handle<JSProxy> object);
487 void BecomeJSFunction(Handle<JSProxy> object);
489 Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
490 Handle<Object> prototype,
491 bool read_only_prototype = false,
492 bool is_strict = false);
493 Handle<JSFunction> NewFunction(Handle<String> name);
494 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
496 bool is_strict = false);
498 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
499 Handle<SharedFunctionInfo> function_info,
500 Handle<Context> context,
501 PretenureFlag pretenure = TENURED);
503 Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
504 Handle<Object> prototype, InstanceType type,
506 bool read_only_prototype = false,
507 bool install_constructor = false,
508 bool is_strict = false);
509 Handle<JSFunction> NewFunction(Handle<String> name,
514 // Create a serialized scope info.
515 Handle<ScopeInfo> NewScopeInfo(int length);
517 // Create an External object for V8's external API.
518 Handle<JSObject> NewExternal(void* value);
520 // The reference to the Code object is stored in self_reference.
521 // This allows generated code to reference its own Code object
522 // by containing this handle.
523 Handle<Code> NewCode(const CodeDesc& desc,
525 Handle<Object> self_reference,
526 bool immovable = false,
527 bool crankshafted = false,
528 int prologue_offset = Code::kPrologueOffsetNotSet,
529 bool is_debug = false);
531 Handle<Code> CopyCode(Handle<Code> code);
533 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
535 // Interface for creating error objects.
537 Handle<Object> NewError(const char* maker, const char* message,
538 Handle<JSArray> args);
539 Handle<String> EmergencyNewError(const char* message, Handle<JSArray> args);
541 Handle<Object> NewError(const char* constructor, Handle<String> message);
543 Handle<Object> NewInvalidStringLengthError() {
544 return NewRangeError(MessageTemplate::kInvalidStringLength);
547 Handle<Object> NewError(const char* maker,
548 MessageTemplate::Template template_index,
549 Handle<Object> arg0 = Handle<Object>(),
550 Handle<Object> arg1 = Handle<Object>(),
551 Handle<Object> arg2 = Handle<Object>());
553 Handle<Object> NewError(MessageTemplate::Template template_index,
554 Handle<Object> arg0 = Handle<Object>(),
555 Handle<Object> arg1 = Handle<Object>(),
556 Handle<Object> arg2 = Handle<Object>());
558 Handle<Object> NewTypeError(MessageTemplate::Template template_index,
559 Handle<Object> arg0 = Handle<Object>(),
560 Handle<Object> arg1 = Handle<Object>(),
561 Handle<Object> arg2 = Handle<Object>());
563 Handle<Object> NewSyntaxError(MessageTemplate::Template template_index,
564 Handle<Object> arg0 = Handle<Object>(),
565 Handle<Object> arg1 = Handle<Object>(),
566 Handle<Object> arg2 = Handle<Object>());
568 Handle<Object> NewReferenceError(MessageTemplate::Template template_index,
569 Handle<Object> arg0 = Handle<Object>(),
570 Handle<Object> arg1 = Handle<Object>(),
571 Handle<Object> arg2 = Handle<Object>());
573 Handle<Object> NewRangeError(MessageTemplate::Template template_index,
574 Handle<Object> arg0 = Handle<Object>(),
575 Handle<Object> arg1 = Handle<Object>(),
576 Handle<Object> arg2 = Handle<Object>());
578 Handle<Object> NewEvalError(MessageTemplate::Template template_index,
579 Handle<Object> arg0 = Handle<Object>(),
580 Handle<Object> arg1 = Handle<Object>(),
581 Handle<Object> arg2 = Handle<Object>());
583 Handle<String> NumberToString(Handle<Object> number,
584 bool check_number_string_cache = true);
586 Handle<String> Uint32ToString(uint32_t value) {
587 return NumberToString(NewNumberFromUint(value));
590 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
592 #define ROOT_ACCESSOR(type, name, camel_name) \
593 inline Handle<type> name() { \
594 return Handle<type>(bit_cast<type**>( \
595 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
597 ROOT_LIST(ROOT_ACCESSOR)
600 #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
601 inline Handle<Map> name##_map() { \
602 return Handle<Map>(bit_cast<Map**>( \
603 &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \
605 STRUCT_LIST(STRUCT_MAP_ACCESSOR)
606 #undef STRUCT_MAP_ACCESSOR
608 #define STRING_ACCESSOR(name, str) \
609 inline Handle<String> name() { \
610 return Handle<String>(bit_cast<String**>( \
611 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
613 INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
614 #undef STRING_ACCESSOR
616 #define SYMBOL_ACCESSOR(name) \
617 inline Handle<Symbol> name() { \
618 return Handle<Symbol>(bit_cast<Symbol**>( \
619 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
621 PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
622 #undef SYMBOL_ACCESSOR
624 #define SYMBOL_ACCESSOR(name, varname, description) \
625 inline Handle<Symbol> name() { \
626 return Handle<Symbol>(bit_cast<Symbol**>( \
627 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
629 PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
630 #undef SYMBOL_ACCESSOR
632 inline void set_string_table(Handle<StringTable> table) {
633 isolate()->heap()->set_string_table(*table);
636 inline void set_weak_stack_trace_list(Handle<WeakFixedArray> list) {
637 isolate()->heap()->set_weak_stack_trace_list(*list);
640 Handle<String> hidden_string() {
641 return Handle<String>(&isolate()->heap()->hidden_string_);
644 // Allocates a new SharedFunctionInfo object.
645 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
646 Handle<String> name, int number_of_literals, FunctionKind kind,
647 Handle<Code> code, Handle<ScopeInfo> scope_info,
648 Handle<TypeFeedbackVector> feedback_vector);
649 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name,
650 MaybeHandle<Code> code);
652 // Allocate a new type feedback vector
653 template <typename Spec>
654 Handle<TypeFeedbackVector> NewTypeFeedbackVector(const Spec* spec);
656 // Allocates a new JSMessageObject object.
657 Handle<JSMessageObject> NewJSMessageObject(MessageTemplate::Template message,
658 Handle<Object> argument,
661 Handle<Object> script,
662 Handle<Object> stack_frames);
664 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
666 // Return a map for given number of properties using the map cache in the
668 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
669 int number_of_properties,
671 bool* is_result_from_cache);
673 // Creates a new FixedArray that holds the data associated with the
674 // atom regexp and stores it in the regexp.
675 void SetRegExpAtomData(Handle<JSRegExp> regexp,
677 Handle<String> source,
678 JSRegExp::Flags flags,
679 Handle<Object> match_pattern);
681 // Creates a new FixedArray that holds the data associated with the
682 // irregexp regexp and stores it in the regexp.
683 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
685 Handle<String> source,
686 JSRegExp::Flags flags,
689 // Returns the value for a known global constant (a property of the global
690 // object which is neither configurable nor writable) like 'undefined'.
691 // Returns a null handle when the given name is unknown.
692 Handle<Object> GlobalConstantFor(Handle<Name> name);
694 // Converts the given boolean condition to JavaScript boolean value.
695 Handle<Object> ToBoolean(bool value);
698 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
700 // Creates a heap object based on the map. The fields of the heap object are
701 // not initialized by New<>() functions. It's the responsibility of the caller
704 Handle<T> New(Handle<Map> map, AllocationSpace space);
707 Handle<T> New(Handle<Map> map,
708 AllocationSpace space,
709 Handle<AllocationSite> allocation_site);
711 // Creates a code object that is not yet fully initialized yet.
712 inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
714 // Attempt to find the number in a small cache. If we finds it, return
715 // the string representation of the number. Otherwise return undefined.
716 Handle<Object> GetNumberStringCache(Handle<Object> number);
718 // Update the cache with a new number-string pair.
719 void SetNumberStringCache(Handle<Object> number, Handle<String> string);
721 // Initializes a function with a shared part and prototype.
722 // Note: this code was factored out of NewFunction such that other parts of
723 // the VM could use it. Specifically, a function that creates instances of
724 // type JS_FUNCTION_TYPE benefit from the use of this function.
725 inline void InitializeFunction(Handle<JSFunction> function,
726 Handle<SharedFunctionInfo> info,
727 Handle<Context> context);
729 // Creates a function initialized with a shared part.
730 Handle<JSFunction> NewFunction(Handle<Map> map,
731 Handle<SharedFunctionInfo> info,
732 Handle<Context> context,
733 PretenureFlag pretenure = TENURED);
735 Handle<JSFunction> NewFunction(Handle<Map> map,
737 MaybeHandle<Code> maybe_code);
739 // Reinitialize a JSProxy into an (empty) JS object of respective type and
740 // size, but keeping the original prototype. The receiver must have at least
741 // the size of the new object. The object is reinitialized and behaves as an
742 // object that has been freshly allocated.
743 void ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, int size);
746 } } // namespace v8::internal
748 #endif // V8_FACTORY_H_