deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / factory.h
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_FACTORY_H_
6 #define V8_FACTORY_H_
7
8 #include "src/isolate.h"
9
10 namespace v8 {
11 namespace internal {
12
13 class FeedbackVectorSpec;
14
15 // Interface for handle based allocation.
16 class Factory FINAL {
17  public:
18   Handle<Oddball> NewOddball(Handle<Map> map,
19                              const char* to_string,
20                              Handle<Object> to_number,
21                              byte kind);
22
23   // Allocates a fixed array initialized with undefined values.
24   Handle<FixedArray> NewFixedArray(
25       int size,
26       PretenureFlag pretenure = NOT_TENURED);
27
28   // Allocate a new fixed array with non-existing entries (the hole).
29   Handle<FixedArray> NewFixedArrayWithHoles(
30       int size,
31       PretenureFlag pretenure = NOT_TENURED);
32
33   // Allocates an uninitialized fixed array. It must be filled by the caller.
34   Handle<FixedArray> NewUninitializedFixedArray(int size);
35
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(
40       int size,
41       PretenureFlag pretenure = NOT_TENURED);
42
43   // Allocate a new fixed double array with hole values.
44   Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles(
45       int size,
46       PretenureFlag pretenure = NOT_TENURED);
47
48   Handle<ConstantPoolArray> NewConstantPoolArray(
49       const ConstantPoolArray::NumberOfEntries& small);
50
51   Handle<ConstantPoolArray> NewExtendedConstantPoolArray(
52       const ConstantPoolArray::NumberOfEntries& small,
53       const ConstantPoolArray::NumberOfEntries& extended);
54
55   Handle<OrderedHashSet> NewOrderedHashSet();
56   Handle<OrderedHashMap> NewOrderedHashMap();
57
58   // Create a new boxed value.
59   Handle<Box> NewBox(Handle<Object> value);
60
61   // Create a pre-tenured empty AccessorPair.
62   Handle<AccessorPair> NewAccessorPair();
63
64   // Create an empty TypeFeedbackInfo.
65   Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
66
67   // Finds the internalized copy for string in the string table.
68   // If not found, a new string is added to the table and returned.
69   Handle<String> InternalizeUtf8String(Vector<const char> str);
70   Handle<String> InternalizeUtf8String(const char* str) {
71     return InternalizeUtf8String(CStrVector(str));
72   }
73   Handle<String> InternalizeString(Handle<String> str);
74   Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
75   Handle<String> InternalizeOneByteString(
76       Handle<SeqOneByteString>, int from, int length);
77
78   Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
79
80   template<class StringTableKey>
81   Handle<String> InternalizeStringWithKey(StringTableKey* key);
82
83
84   // String creation functions.  Most of the string creation functions take
85   // a Heap::PretenureFlag argument to optionally request that they be
86   // allocated in the old generation.  The pretenure flag defaults to
87   // DONT_TENURE.
88   //
89   // Creates a new String object.  There are two String encodings: one-byte and
90   // two-byte.  One should choose between the three string factory functions
91   // based on the encoding of the string buffer that the string is
92   // initialized from.
93   //   - ...FromOneByte initializes the string from a buffer that is Latin1
94   //     encoded (it does not check that the buffer is Latin1 encoded) and
95   //     the result will be Latin1 encoded.
96   //   - ...FromUtf8 initializes the string from a buffer that is UTF-8
97   //     encoded.  If the characters are all ASCII characters, the result
98   //     will be Latin1 encoded, otherwise it will converted to two-byte.
99   //   - ...FromTwoByte initializes the string from a buffer that is two-byte
100   //     encoded.  If the characters are all Latin1 characters, the result
101   //     will be converted to Latin1, otherwise it will be left as two-byte.
102   //
103   // One-byte strings are pretenured when used as keys in the SourceCodeCache.
104   MUST_USE_RESULT MaybeHandle<String> NewStringFromOneByte(
105       Vector<const uint8_t> str,
106       PretenureFlag pretenure = NOT_TENURED);
107
108   template <size_t N>
109   inline Handle<String> NewStringFromStaticChars(
110       const char (&str)[N], PretenureFlag pretenure = NOT_TENURED) {
111     DCHECK(N == StrLength(str) + 1);
112     return NewStringFromOneByte(STATIC_CHAR_VECTOR(str), pretenure)
113         .ToHandleChecked();
114   }
115
116   inline Handle<String> NewStringFromAsciiChecked(
117       const char* str,
118       PretenureFlag pretenure = NOT_TENURED) {
119     return NewStringFromOneByte(
120         OneByteVector(str), pretenure).ToHandleChecked();
121   }
122
123
124   // Allocates and fully initializes a String.  There are two String encodings:
125   // one-byte and two-byte. One should choose between the threestring
126   // allocation functions based on the encoding of the string buffer used to
127   // initialized the string.
128   //   - ...FromOneByte initializes the string from a buffer that is Latin1
129   //     encoded (it does not check that the buffer is Latin1 encoded) and the
130   //     result will be Latin1 encoded.
131   //   - ...FromUTF8 initializes the string from a buffer that is UTF-8
132   //     encoded.  If the characters are all ASCII characters, the result
133   //     will be Latin1 encoded, otherwise it will converted to two-byte.
134   //   - ...FromTwoByte initializes the string from a buffer that is two-byte
135   //     encoded.  If the characters are all Latin1 characters, the
136   //     result will be converted to Latin1, otherwise it will be left as
137   //     two-byte.
138
139   // TODO(dcarney): remove this function.
140   MUST_USE_RESULT inline MaybeHandle<String> NewStringFromAscii(
141       Vector<const char> str,
142       PretenureFlag pretenure = NOT_TENURED) {
143     return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure);
144   }
145
146   // UTF8 strings are pretenured when used for regexp literal patterns and
147   // flags in the parser.
148   MUST_USE_RESULT MaybeHandle<String> NewStringFromUtf8(
149       Vector<const char> str,
150       PretenureFlag pretenure = NOT_TENURED);
151
152   MUST_USE_RESULT MaybeHandle<String> NewStringFromTwoByte(
153       Vector<const uc16> str,
154       PretenureFlag pretenure = NOT_TENURED);
155
156   // Allocates an internalized string in old space based on the character
157   // stream.
158   MUST_USE_RESULT Handle<String> NewInternalizedStringFromUtf8(
159       Vector<const char> str,
160       int chars,
161       uint32_t hash_field);
162
163   MUST_USE_RESULT Handle<String> NewOneByteInternalizedString(
164       Vector<const uint8_t> str, uint32_t hash_field);
165
166   MUST_USE_RESULT Handle<String> NewOneByteInternalizedSubString(
167       Handle<SeqOneByteString> string, int offset, int length,
168       uint32_t hash_field);
169
170   MUST_USE_RESULT Handle<String> NewTwoByteInternalizedString(
171         Vector<const uc16> str,
172         uint32_t hash_field);
173
174   MUST_USE_RESULT Handle<String> NewInternalizedStringImpl(
175       Handle<String> string, int chars, uint32_t hash_field);
176
177   // Compute the matching internalized string map for a string if possible.
178   // Empty handle is returned if string is in new space or not flattened.
179   MUST_USE_RESULT MaybeHandle<Map> InternalizedStringMapForString(
180       Handle<String> string);
181
182   // Allocates and partially initializes an one-byte or two-byte String. The
183   // characters of the string are uninitialized. Currently used in regexp code
184   // only, where they are pretenured.
185   MUST_USE_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString(
186       int length,
187       PretenureFlag pretenure = NOT_TENURED);
188   MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString(
189       int length,
190       PretenureFlag pretenure = NOT_TENURED);
191
192   // Creates a single character string where the character has given code.
193   // A cache is used for Latin1 codes.
194   Handle<String> LookupSingleCharacterStringFromCode(uint32_t code);
195
196   // Create a new cons string object which consists of a pair of strings.
197   MUST_USE_RESULT MaybeHandle<String> NewConsString(Handle<String> left,
198                                                     Handle<String> right);
199   MUST_USE_RESULT MaybeHandle<String> NewOneByteConsString(
200       int length, Handle<String> left, Handle<String> right);
201   MUST_USE_RESULT MaybeHandle<String> NewTwoByteConsString(
202       int length, Handle<String> left, Handle<String> right);
203   MUST_USE_RESULT MaybeHandle<String> NewRawConsString(Handle<Map> map,
204                                                        int length,
205                                                        Handle<String> left,
206                                                        Handle<String> right);
207
208   // Create a new string object which holds a proper substring of a string.
209   Handle<String> NewProperSubString(Handle<String> str,
210                                     int begin,
211                                     int end);
212
213   // Create a new string object which holds a substring of a string.
214   Handle<String> NewSubString(Handle<String> str, int begin, int end) {
215     if (begin == 0 && end == str->length()) return str;
216     return NewProperSubString(str, begin, end);
217   }
218
219   // Creates a new external String object.  There are two String encodings
220   // in the system: one-byte and two-byte.  Unlike other String types, it does
221   // not make sense to have a UTF-8 factory function for external strings,
222   // because we cannot change the underlying buffer.  Note that these strings
223   // are backed by a string resource that resides outside the V8 heap.
224   MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromOneByte(
225       const ExternalOneByteString::Resource* resource);
226   MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromTwoByte(
227       const ExternalTwoByteString::Resource* resource);
228
229   // Create a symbol.
230   Handle<Symbol> NewSymbol();
231   Handle<Symbol> NewPrivateSymbol();
232   Handle<Symbol> NewPrivateOwnSymbol();
233
234   // Create a global (but otherwise uninitialized) context.
235   Handle<Context> NewNativeContext();
236
237   // Create a script context.
238   Handle<Context> NewScriptContext(Handle<JSFunction> function,
239                                    Handle<ScopeInfo> scope_info);
240
241   // Create an empty script context table.
242   Handle<ScriptContextTable> NewScriptContextTable();
243
244   // Create a module context.
245   Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
246
247   // Create a function context.
248   Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
249
250   // Create a catch context.
251   Handle<Context> NewCatchContext(Handle<JSFunction> function,
252                                   Handle<Context> previous,
253                                   Handle<String> name,
254                                   Handle<Object> thrown_object);
255
256   // Create a 'with' context.
257   Handle<Context> NewWithContext(Handle<JSFunction> function,
258                                  Handle<Context> previous,
259                                  Handle<JSReceiver> extension);
260
261   // Create a block context.
262   Handle<Context> NewBlockContext(Handle<JSFunction> function,
263                                   Handle<Context> previous,
264                                   Handle<ScopeInfo> scope_info);
265
266   // Allocate a new struct.  The struct is pretenured (allocated directly in
267   // the old generation).
268   Handle<Struct> NewStruct(InstanceType type);
269
270   Handle<CodeCache> NewCodeCache();
271
272   Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
273       int aliased_context_slot);
274
275   Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
276
277   Handle<Script> NewScript(Handle<String> source);
278
279   // Foreign objects are pretenured when allocated by the bootstrapper.
280   Handle<Foreign> NewForeign(Address addr,
281                              PretenureFlag pretenure = NOT_TENURED);
282
283   // Allocate a new foreign object.  The foreign is pretenured (allocated
284   // directly in the old generation).
285   Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
286
287   Handle<ByteArray> NewByteArray(int length,
288                                  PretenureFlag pretenure = NOT_TENURED);
289
290   Handle<ExternalArray> NewExternalArray(
291       int length,
292       ExternalArrayType array_type,
293       void* external_pointer,
294       PretenureFlag pretenure = NOT_TENURED);
295
296   Handle<FixedTypedArrayBase> NewFixedTypedArray(
297       int length,
298       ExternalArrayType array_type,
299       PretenureFlag pretenure = NOT_TENURED);
300
301   Handle<Cell> NewCell(Handle<Object> value);
302
303   Handle<PropertyCell> NewPropertyCell();
304
305   Handle<WeakCell> NewWeakCell(Handle<HeapObject> value);
306
307   // Allocate a tenured AllocationSite. It's payload is null.
308   Handle<AllocationSite> NewAllocationSite();
309
310   Handle<Map> NewMap(
311       InstanceType type,
312       int instance_size,
313       ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
314
315   Handle<HeapObject> NewFillerObject(int size,
316                                      bool double_align,
317                                      AllocationSpace space);
318
319   Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
320
321   Handle<JSObject> CopyJSObject(Handle<JSObject> object);
322
323   Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
324                                                   Handle<AllocationSite> site);
325
326   Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
327                                            Handle<Map> map);
328
329   Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
330
331   // This method expects a COW array in new space, and creates a copy
332   // of it in old space.
333   Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
334
335   Handle<FixedDoubleArray> CopyFixedDoubleArray(
336       Handle<FixedDoubleArray> array);
337
338   Handle<ConstantPoolArray> CopyConstantPoolArray(
339       Handle<ConstantPoolArray> array);
340
341   // Numbers (e.g. literals) are pretenured by the parser.
342   // The return value may be a smi or a heap number.
343   Handle<Object> NewNumber(double value,
344                            PretenureFlag pretenure = NOT_TENURED);
345
346   Handle<Object> NewNumberFromInt(int32_t value,
347                                   PretenureFlag pretenure = NOT_TENURED);
348   Handle<Object> NewNumberFromUint(uint32_t value,
349                                   PretenureFlag pretenure = NOT_TENURED);
350   Handle<Object> NewNumberFromSize(size_t value,
351                                    PretenureFlag pretenure = NOT_TENURED) {
352     if (Smi::IsValid(static_cast<intptr_t>(value))) {
353       return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
354                             isolate());
355     }
356     return NewNumber(static_cast<double>(value), pretenure);
357   }
358   Handle<HeapNumber> NewHeapNumber(double value,
359                                    MutableMode mode = IMMUTABLE,
360                                    PretenureFlag pretenure = NOT_TENURED);
361
362   // These objects are used by the api to create env-independent data
363   // structures in the heap.
364   inline Handle<JSObject> NewNeanderObject() {
365     return NewJSObjectFromMap(neander_map());
366   }
367
368   Handle<JSWeakMap> NewJSWeakMap();
369
370   Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
371
372   // JS objects are pretenured when allocated by the bootstrapper and
373   // runtime.
374   Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
375                                PretenureFlag pretenure = NOT_TENURED);
376   // JSObject that should have a memento pointing to the allocation site.
377   Handle<JSObject> NewJSObjectWithMemento(Handle<JSFunction> constructor,
378                                           Handle<AllocationSite> site);
379
380   // Global objects are pretenured and initialized based on a constructor.
381   Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
382
383   // JS objects are pretenured when allocated by the bootstrapper and
384   // runtime.
385   Handle<JSObject> NewJSObjectFromMap(
386       Handle<Map> map,
387       PretenureFlag pretenure = NOT_TENURED,
388       bool allocate_properties = true,
389       Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
390
391   // JS modules are pretenured.
392   Handle<JSModule> NewJSModule(Handle<Context> context,
393                                Handle<ScopeInfo> scope_info);
394
395   // JS arrays are pretenured when allocated by the parser.
396
397   // Create a JSArray with no elements.
398   Handle<JSArray> NewJSArray(
399       ElementsKind elements_kind,
400       PretenureFlag pretenure = NOT_TENURED);
401
402   // Create a JSArray with a specified length and elements initialized
403   // according to the specified mode.
404   Handle<JSArray> NewJSArray(
405       ElementsKind elements_kind, int length, int capacity,
406       ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS,
407       PretenureFlag pretenure = NOT_TENURED);
408
409   Handle<JSArray> NewJSArray(
410       int capacity,
411       ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
412       PretenureFlag pretenure = NOT_TENURED) {
413     if (capacity != 0) {
414       elements_kind = GetHoleyElementsKind(elements_kind);
415     }
416     return NewJSArray(elements_kind, 0, capacity,
417                       INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
418   }
419
420   // Create a JSArray with the given elements.
421   Handle<JSArray> NewJSArrayWithElements(
422       Handle<FixedArrayBase> elements,
423       ElementsKind elements_kind,
424       int length,
425       PretenureFlag pretenure = NOT_TENURED);
426
427   Handle<JSArray> NewJSArrayWithElements(
428       Handle<FixedArrayBase> elements,
429       ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
430       PretenureFlag pretenure = NOT_TENURED) {
431     return NewJSArrayWithElements(
432         elements, elements_kind, elements->length(), pretenure);
433   }
434
435   void NewJSArrayStorage(
436       Handle<JSArray> array,
437       int length,
438       int capacity,
439       ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
440
441   Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
442
443   Handle<JSArrayBuffer> NewJSArrayBuffer();
444
445   Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
446
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);
451
452   Handle<JSDataView> NewJSDataView();
453   Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer,
454                                    size_t byte_offset, size_t byte_length);
455
456   // TODO(aandrey): Maybe these should take table, index and kind arguments.
457   Handle<JSMapIterator> NewJSMapIterator();
458   Handle<JSSetIterator> NewJSSetIterator();
459
460   // Allocates a Harmony proxy.
461   Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
462
463   // Allocates a Harmony function proxy.
464   Handle<JSProxy> NewJSFunctionProxy(Handle<Object> handler,
465                                      Handle<Object> call_trap,
466                                      Handle<Object> construct_trap,
467                                      Handle<Object> prototype);
468
469   // Reinitialize an JSGlobalProxy based on a constructor.  The object
470   // must have the same size as objects allocated using the
471   // constructor.  The object is reinitialized and behaves as an
472   // object that has been freshly allocated using the constructor.
473   void ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> global,
474                                  Handle<JSFunction> constructor);
475
476   Handle<JSGlobalProxy> NewUninitializedJSGlobalProxy();
477
478   // Change the type of the argument into a JS object/function and reinitialize.
479   void BecomeJSObject(Handle<JSProxy> object);
480   void BecomeJSFunction(Handle<JSProxy> object);
481
482   Handle<JSFunction> NewFunction(Handle<String> name,
483                                  Handle<Code> code,
484                                  Handle<Object> prototype,
485                                  bool read_only_prototype = false);
486   Handle<JSFunction> NewFunction(Handle<String> name);
487   Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
488                                                  Handle<Code> code);
489
490   Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
491       Handle<SharedFunctionInfo> function_info,
492       Handle<Context> context,
493       PretenureFlag pretenure = TENURED);
494
495   Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
496                                  Handle<Object> prototype, InstanceType type,
497                                  int instance_size,
498                                  bool read_only_prototype = false,
499                                  bool install_constructor = false);
500   Handle<JSFunction> NewFunction(Handle<String> name,
501                                  Handle<Code> code,
502                                  InstanceType type,
503                                  int instance_size);
504
505   // Create a serialized scope info.
506   Handle<ScopeInfo> NewScopeInfo(int length);
507
508   // Create an External object for V8's external API.
509   Handle<JSObject> NewExternal(void* value);
510
511   // The reference to the Code object is stored in self_reference.
512   // This allows generated code to reference its own Code object
513   // by containing this handle.
514   Handle<Code> NewCode(const CodeDesc& desc,
515                        Code::Flags flags,
516                        Handle<Object> self_reference,
517                        bool immovable = false,
518                        bool crankshafted = false,
519                        int prologue_offset = Code::kPrologueOffsetNotSet,
520                        bool is_debug = false);
521
522   Handle<Code> CopyCode(Handle<Code> code);
523
524   Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
525
526   // Interface for creating error objects.
527
528   Handle<Object> NewError(const char* maker, const char* message,
529                           Handle<JSArray> args);
530   Handle<String> EmergencyNewError(const char* message, Handle<JSArray> args);
531   Handle<Object> NewError(const char* maker, const char* message,
532                           Vector<Handle<Object> > args);
533   Handle<Object> NewError(const char* message, Vector<Handle<Object> > args);
534   Handle<Object> NewError(Handle<String> message);
535   Handle<Object> NewError(const char* constructor, Handle<String> message);
536
537   Handle<Object> NewTypeError(const char* message,
538                               Vector<Handle<Object> > args);
539   Handle<Object> NewTypeError(Handle<String> message);
540
541   Handle<Object> NewRangeError(const char* message,
542                                Vector<Handle<Object> > args);
543   Handle<Object> NewRangeError(Handle<String> message);
544
545   Handle<Object> NewInvalidStringLengthError() {
546     return NewRangeError("invalid_string_length",
547                          HandleVector<Object>(NULL, 0));
548   }
549
550   Handle<Object> NewSyntaxError(const char* message, Handle<JSArray> args);
551   Handle<Object> NewSyntaxError(Handle<String> message);
552
553   Handle<Object> NewReferenceError(const char* message,
554                                    Vector<Handle<Object> > args);
555   Handle<Object> NewReferenceError(const char* message, Handle<JSArray> args);
556   Handle<Object> NewReferenceError(Handle<String> message);
557
558   Handle<Object> NewEvalError(const char* message,
559                               Vector<Handle<Object> > args);
560
561   Handle<String> NumberToString(Handle<Object> number,
562                                 bool check_number_string_cache = true);
563
564   Handle<String> Uint32ToString(uint32_t value) {
565     return NumberToString(NewNumberFromUint(value));
566   }
567
568   Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
569
570 #define ROOT_ACCESSOR(type, name, camel_name)                         \
571   inline Handle<type> name() {                                        \
572     return Handle<type>(bit_cast<type**>(                             \
573         &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
574   }
575   ROOT_LIST(ROOT_ACCESSOR)
576 #undef ROOT_ACCESSOR
577
578 #define STRUCT_MAP_ACCESSOR(NAME, Name, name)                      \
579   inline Handle<Map> name##_map() {                                \
580     return Handle<Map>(bit_cast<Map**>(                            \
581         &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \
582   }
583   STRUCT_LIST(STRUCT_MAP_ACCESSOR)
584 #undef STRUCT_MAP_ACCESSOR
585
586 #define STRING_ACCESSOR(name, str)                              \
587   inline Handle<String> name() {                                \
588     return Handle<String>(bit_cast<String**>(                   \
589         &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
590   }
591   INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
592 #undef STRING_ACCESSOR
593
594 #define SYMBOL_ACCESSOR(name)                                   \
595   inline Handle<Symbol> name() {                                \
596     return Handle<Symbol>(bit_cast<Symbol**>(                   \
597         &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
598   }
599   PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
600 #undef SYMBOL_ACCESSOR
601
602 #define SYMBOL_ACCESSOR(name, varname, description)             \
603   inline Handle<Symbol> name() {                                \
604     return Handle<Symbol>(bit_cast<Symbol**>(                   \
605         &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
606   }
607   PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
608 #undef SYMBOL_ACCESSOR
609
610   inline void set_string_table(Handle<StringTable> table) {
611     isolate()->heap()->set_string_table(*table);
612   }
613
614   Handle<String> hidden_string() {
615     return Handle<String>(&isolate()->heap()->hidden_string_);
616   }
617
618   // Allocates a new SharedFunctionInfo object.
619   Handle<SharedFunctionInfo> NewSharedFunctionInfo(
620       Handle<String> name, int number_of_literals, FunctionKind kind,
621       Handle<Code> code, Handle<ScopeInfo> scope_info,
622       Handle<TypeFeedbackVector> feedback_vector);
623   Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name,
624                                                    MaybeHandle<Code> code);
625
626   // Allocate a new type feedback vector
627   template <typename Spec>
628   Handle<TypeFeedbackVector> NewTypeFeedbackVector(const Spec* spec);
629
630   // Allocates a new JSMessageObject object.
631   Handle<JSMessageObject> NewJSMessageObject(
632       Handle<String> type,
633       Handle<JSArray> arguments,
634       int start_position,
635       int end_position,
636       Handle<Object> script,
637       Handle<Object> stack_frames);
638
639   Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
640
641   // Return a map for given number of properties using the map cache in the
642   // native context.
643   Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
644                                         int number_of_properties,
645                                         bool* is_result_from_cache);
646
647   // Creates a new FixedArray that holds the data associated with the
648   // atom regexp and stores it in the regexp.
649   void SetRegExpAtomData(Handle<JSRegExp> regexp,
650                          JSRegExp::Type type,
651                          Handle<String> source,
652                          JSRegExp::Flags flags,
653                          Handle<Object> match_pattern);
654
655   // Creates a new FixedArray that holds the data associated with the
656   // irregexp regexp and stores it in the regexp.
657   void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
658                              JSRegExp::Type type,
659                              Handle<String> source,
660                              JSRegExp::Flags flags,
661                              int capture_count);
662
663   // Returns the value for a known global constant (a property of the global
664   // object which is neither configurable nor writable) like 'undefined'.
665   // Returns a null handle when the given name is unknown.
666   Handle<Object> GlobalConstantFor(Handle<String> name);
667
668   // Converts the given boolean condition to JavaScript boolean value.
669   Handle<Object> ToBoolean(bool value);
670
671  private:
672   Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
673
674   // Creates a heap object based on the map. The fields of the heap object are
675   // not initialized by New<>() functions. It's the responsibility of the caller
676   // to do that.
677   template<typename T>
678   Handle<T> New(Handle<Map> map, AllocationSpace space);
679
680   template<typename T>
681   Handle<T> New(Handle<Map> map,
682                 AllocationSpace space,
683                 Handle<AllocationSite> allocation_site);
684
685   // Creates a code object that is not yet fully initialized yet.
686   inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
687
688   // Attempt to find the number in a small cache.  If we finds it, return
689   // the string representation of the number.  Otherwise return undefined.
690   Handle<Object> GetNumberStringCache(Handle<Object> number);
691
692   // Update the cache with a new number-string pair.
693   void SetNumberStringCache(Handle<Object> number, Handle<String> string);
694
695   // Initializes a function with a shared part and prototype.
696   // Note: this code was factored out of NewFunction such that other parts of
697   // the VM could use it. Specifically, a function that creates instances of
698   // type JS_FUNCTION_TYPE benefit from the use of this function.
699   inline void InitializeFunction(Handle<JSFunction> function,
700                                  Handle<SharedFunctionInfo> info,
701                                  Handle<Context> context);
702
703   // Creates a function initialized with a shared part.
704   Handle<JSFunction> NewFunction(Handle<Map> map,
705                                  Handle<SharedFunctionInfo> info,
706                                  Handle<Context> context,
707                                  PretenureFlag pretenure = TENURED);
708
709   Handle<JSFunction> NewFunction(Handle<Map> map,
710                                  Handle<String> name,
711                                  MaybeHandle<Code> maybe_code);
712
713   // Reinitialize a JSProxy into an (empty) JS object of respective type and
714   // size, but keeping the original prototype.  The receiver must have at least
715   // the size of the new object.  The object is reinitialized and behaves as an
716   // object that has been freshly allocated.
717   void ReinitializeJSProxy(Handle<JSProxy> proxy, InstanceType type, int size);
718 };
719
720 } }  // namespace v8::internal
721
722 #endif  // V8_FACTORY_H_