[presubmit] Enable readability/namespace linter checking.
[platform/upstream/v8.git] / 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 #include "src/messages.h"
10
11 namespace v8 {
12 namespace internal {
13
14 class StaticFeedbackVectorSpec;
15
16 // Interface for handle based allocation.
17 class Factory final {
18  public:
19   Handle<Oddball> NewOddball(Handle<Map> map, const char* to_string,
20                              Handle<Object> to_number, const char* type_of,
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<OrderedHashSet> NewOrderedHashSet();
49   Handle<OrderedHashMap> NewOrderedHashMap();
50
51   // Create a new boxed value.
52   Handle<Box> NewBox(Handle<Object> value);
53
54   // Create a new PrototypeInfo struct.
55   Handle<PrototypeInfo> NewPrototypeInfo();
56
57   // Create a new SloppyBlockWithEvalContextExtension struct.
58   Handle<SloppyBlockWithEvalContextExtension>
59   NewSloppyBlockWithEvalContextExtension(Handle<ScopeInfo> scope_info,
60                                          Handle<JSObject> extension);
61
62   // Create a pre-tenured empty AccessorPair.
63   Handle<AccessorPair> NewAccessorPair();
64
65   // Create an empty TypeFeedbackInfo.
66   Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
67
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));
73   }
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);
78
79   Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
80
81   template<class StringTableKey>
82   Handle<String> InternalizeStringWithKey(StringTableKey* key);
83
84
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
88   // DONT_TENURE.
89   //
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
93   // initialized from.
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.
103   //
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);
108
109   template <size_t N>
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)
114         .ToHandleChecked();
115   }
116
117   inline Handle<String> NewStringFromAsciiChecked(
118       const char* str,
119       PretenureFlag pretenure = NOT_TENURED) {
120     return NewStringFromOneByte(
121         OneByteVector(str), pretenure).ToHandleChecked();
122   }
123
124
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
138   //     two-byte.
139
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);
145   }
146
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);
152
153   MUST_USE_RESULT MaybeHandle<String> NewStringFromTwoByte(
154       Vector<const uc16> str,
155       PretenureFlag pretenure = NOT_TENURED);
156
157   // Allocates an internalized string in old space based on the character
158   // stream.
159   Handle<String> NewInternalizedStringFromUtf8(Vector<const char> str,
160                                                int chars, uint32_t hash_field);
161
162   Handle<String> NewOneByteInternalizedString(Vector<const uint8_t> str,
163                                               uint32_t hash_field);
164
165   Handle<String> NewOneByteInternalizedSubString(
166       Handle<SeqOneByteString> string, int offset, int length,
167       uint32_t hash_field);
168
169   Handle<String> NewTwoByteInternalizedString(Vector<const uc16> str,
170                                               uint32_t hash_field);
171
172   Handle<String> NewInternalizedStringImpl(Handle<String> string, int chars,
173                                            uint32_t hash_field);
174
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);
179
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(
184       int length,
185       PretenureFlag pretenure = NOT_TENURED);
186   MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString(
187       int length,
188       PretenureFlag pretenure = NOT_TENURED);
189
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);
193
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);
197
198   // Create a new string object which holds a proper substring of a string.
199   Handle<String> NewProperSubString(Handle<String> str,
200                                     int begin,
201                                     int end);
202
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);
207   }
208
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);
218
219   // Create a symbol.
220   Handle<Symbol> NewSymbol();
221   Handle<Symbol> NewPrivateSymbol(Handle<Object> name);
222
223   // Create a global (but otherwise uninitialized) context.
224   Handle<Context> NewNativeContext();
225
226   // Create a script context.
227   Handle<Context> NewScriptContext(Handle<JSFunction> function,
228                                    Handle<ScopeInfo> scope_info);
229
230   // Create an empty script context table.
231   Handle<ScriptContextTable> NewScriptContextTable();
232
233   // Create a module context.
234   Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
235
236   // Create a function context.
237   Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
238
239   // Create a catch context.
240   Handle<Context> NewCatchContext(Handle<JSFunction> function,
241                                   Handle<Context> previous,
242                                   Handle<String> name,
243                                   Handle<Object> thrown_object);
244
245   // Create a 'with' context.
246   Handle<Context> NewWithContext(Handle<JSFunction> function,
247                                  Handle<Context> previous,
248                                  Handle<JSReceiver> extension);
249
250   // Create a block context.
251   Handle<Context> NewBlockContext(Handle<JSFunction> function,
252                                   Handle<Context> previous,
253                                   Handle<ScopeInfo> scope_info);
254
255   // Allocate a new struct.  The struct is pretenured (allocated directly in
256   // the old generation).
257   Handle<Struct> NewStruct(InstanceType type);
258
259   Handle<CodeCache> NewCodeCache();
260
261   Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
262       int aliased_context_slot);
263
264   Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
265
266   Handle<Script> NewScript(Handle<String> source);
267
268   // Foreign objects are pretenured when allocated by the bootstrapper.
269   Handle<Foreign> NewForeign(Address addr,
270                              PretenureFlag pretenure = NOT_TENURED);
271
272   // Allocate a new foreign object.  The foreign is pretenured (allocated
273   // directly in the old generation).
274   Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
275
276   Handle<ByteArray> NewByteArray(int length,
277                                  PretenureFlag pretenure = NOT_TENURED);
278
279   Handle<BytecodeArray> NewBytecodeArray(int length, const byte* raw_bytecodes,
280                                          int frame_size, int parameter_count,
281                                          Handle<FixedArray> constant_pool);
282
283   Handle<FixedTypedArrayBase> NewFixedTypedArrayWithExternalPointer(
284       int length, ExternalArrayType array_type, void* external_pointer,
285       PretenureFlag pretenure = NOT_TENURED);
286
287   Handle<FixedTypedArrayBase> NewFixedTypedArray(
288       int length, ExternalArrayType array_type, bool initialize,
289       PretenureFlag pretenure = NOT_TENURED);
290
291   Handle<Cell> NewCell(Handle<Object> value);
292
293   Handle<PropertyCell> NewPropertyCell();
294
295   Handle<WeakCell> NewWeakCell(Handle<HeapObject> value);
296
297   // Allocate a tenured AllocationSite. It's payload is null.
298   Handle<AllocationSite> NewAllocationSite();
299
300   Handle<Map> NewMap(
301       InstanceType type,
302       int instance_size,
303       ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
304
305   Handle<HeapObject> NewFillerObject(int size,
306                                      bool double_align,
307                                      AllocationSpace space);
308
309   Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
310
311   Handle<JSObject> CopyJSObject(Handle<JSObject> object);
312
313   Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
314                                                   Handle<AllocationSite> site);
315
316   Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
317                                            Handle<Map> map);
318
319   Handle<FixedArray> CopyFixedArrayAndGrow(
320       Handle<FixedArray> array, int grow_by,
321       PretenureFlag pretenure = NOT_TENURED);
322
323   Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
324
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);
328
329   Handle<FixedDoubleArray> CopyFixedDoubleArray(
330       Handle<FixedDoubleArray> array);
331
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);
336
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)),
345                             isolate());
346     }
347     return NewNumber(static_cast<double>(value), pretenure);
348   }
349   Handle<HeapNumber> NewHeapNumber(double value,
350                                    MutableMode mode = IMMUTABLE,
351                                    PretenureFlag pretenure = NOT_TENURED);
352
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
358
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());
363   }
364
365   Handle<JSWeakMap> NewJSWeakMap();
366
367   Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
368
369   // JS objects are pretenured when allocated by the bootstrapper and
370   // runtime.
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);
376
377   // Global objects are pretenured and initialized based on a constructor.
378   Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
379
380   // JS objects are pretenured when allocated by the bootstrapper and
381   // runtime.
382   Handle<JSObject> NewJSObjectFromMap(
383       Handle<Map> map,
384       PretenureFlag pretenure = NOT_TENURED,
385       Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
386
387   // JS modules are pretenured.
388   Handle<JSModule> NewJSModule(Handle<Context> context,
389                                Handle<ScopeInfo> scope_info);
390
391   // JS arrays are pretenured when allocated by the parser.
392
393   // Create a JSArray with no elements.
394   Handle<JSArray> NewJSArray(ElementsKind elements_kind,
395                              Strength strength = Strength::WEAK,
396                              PretenureFlag pretenure = NOT_TENURED);
397
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);
405
406   Handle<JSArray> NewJSArray(
407       int capacity, ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
408       Strength strength = Strength::WEAK,
409       PretenureFlag pretenure = NOT_TENURED) {
410     if (capacity != 0) {
411       elements_kind = GetHoleyElementsKind(elements_kind);
412     }
413     return NewJSArray(elements_kind, 0, capacity, strength,
414                       INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
415   }
416
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);
422
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);
430   }
431
432   void NewJSArrayStorage(
433       Handle<JSArray> array,
434       int length,
435       int capacity,
436       ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
437
438   Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
439
440   Handle<JSArrayBuffer> NewJSArrayBuffer(
441       SharedFlag shared = SharedFlag::kNotShared,
442       PretenureFlag pretenure = NOT_TENURED);
443
444   Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
445                                        PretenureFlag pretenure = NOT_TENURED);
446
447   Handle<JSTypedArray> NewJSTypedArray(ElementsKind elements_kind,
448                                        PretenureFlag pretenure = NOT_TENURED);
449
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);
455
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);
460
461   Handle<JSDataView> NewJSDataView();
462   Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer,
463                                    size_t byte_offset, size_t byte_length);
464
465   Handle<JSMap> NewJSMap();
466   Handle<JSSet> NewJSSet();
467
468   // TODO(aandrey): Maybe these should take table, index and kind arguments.
469   Handle<JSMapIterator> NewJSMapIterator();
470   Handle<JSSetIterator> NewJSSetIterator();
471
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);
476
477   // Allocates a Harmony proxy.
478   Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
479
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);
485
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);
492
493   Handle<JSGlobalProxy> NewUninitializedJSGlobalProxy();
494
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);
498
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,
505                                                  Handle<Code> code,
506                                                  bool is_strict = false);
507
508   Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
509       Handle<SharedFunctionInfo> function_info,
510       Handle<Context> context,
511       PretenureFlag pretenure = TENURED);
512
513   Handle<JSFunction> NewFunction(Handle<String> name, Handle<Code> code,
514                                  Handle<Object> prototype, InstanceType type,
515                                  int instance_size,
516                                  bool read_only_prototype = false,
517                                  bool install_constructor = false,
518                                  bool is_strict = false);
519   Handle<JSFunction> NewFunction(Handle<String> name,
520                                  Handle<Code> code,
521                                  InstanceType type,
522                                  int instance_size);
523
524   // Create a serialized scope info.
525   Handle<ScopeInfo> NewScopeInfo(int length);
526
527   // Create an External object for V8's external API.
528   Handle<JSObject> NewExternal(void* value);
529
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,
534                        Code::Flags flags,
535                        Handle<Object> self_reference,
536                        bool immovable = false,
537                        bool crankshafted = false,
538                        int prologue_offset = Code::kPrologueOffsetNotSet,
539                        bool is_debug = false);
540
541   Handle<Code> CopyCode(Handle<Code> code);
542
543   Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
544
545   // Interface for creating error objects.
546   Handle<Object> NewError(Handle<JSFunction> constructor,
547                           Handle<String> message);
548
549   Handle<Object> NewInvalidStringLengthError() {
550     return NewRangeError(MessageTemplate::kInvalidStringLength);
551   }
552
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>());
558
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>());
564   DECLARE_ERROR(Error)
565   DECLARE_ERROR(EvalError)
566   DECLARE_ERROR(RangeError)
567   DECLARE_ERROR(ReferenceError)
568   DECLARE_ERROR(SyntaxError)
569   DECLARE_ERROR(TypeError)
570 #undef DEFINE_ERROR
571
572   Handle<String> NumberToString(Handle<Object> number,
573                                 bool check_number_string_cache = true);
574
575   Handle<String> Uint32ToString(uint32_t value) {
576     return NumberToString(NewNumberFromUint(value));
577   }
578
579   Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
580
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])); \
585   }
586   ROOT_LIST(ROOT_ACCESSOR)
587 #undef ROOT_ACCESSOR
588
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])); \
593   }
594   STRUCT_LIST(STRUCT_MAP_ACCESSOR)
595 #undef STRUCT_MAP_ACCESSOR
596
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])); \
601   }
602   INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
603 #undef STRING_ACCESSOR
604
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])); \
609   }
610   PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
611 #undef SYMBOL_ACCESSOR
612
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])); \
617   }
618   PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
619 #undef SYMBOL_ACCESSOR
620
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);
628
629   // Allocate a new type feedback vector
630   template <typename Spec>
631   Handle<TypeFeedbackVector> NewTypeFeedbackVector(const Spec* spec);
632
633   // Allocates a new JSMessageObject object.
634   Handle<JSMessageObject> NewJSMessageObject(MessageTemplate::Template message,
635                                              Handle<Object> argument,
636                                              int start_position,
637                                              int end_position,
638                                              Handle<Object> script,
639                                              Handle<Object> stack_frames);
640
641   Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
642
643   // Return a map for given number of properties using the map cache in the
644   // native context.
645   Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
646                                         int number_of_properties,
647                                         bool is_strong,
648                                         bool* is_result_from_cache);
649
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,
653                          JSRegExp::Type type,
654                          Handle<String> source,
655                          JSRegExp::Flags flags,
656                          Handle<Object> match_pattern);
657
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,
661                              JSRegExp::Type type,
662                              Handle<String> source,
663                              JSRegExp::Flags flags,
664                              int capture_count);
665
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);
670
671   // Converts the given boolean condition to JavaScript boolean value.
672   Handle<Object> ToBoolean(bool value);
673
674  private:
675   Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
676
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
679   // to do that.
680   template<typename T>
681   Handle<T> New(Handle<Map> map, AllocationSpace space);
682
683   template<typename T>
684   Handle<T> New(Handle<Map> map,
685                 AllocationSpace space,
686                 Handle<AllocationSite> allocation_site);
687
688   // Creates a code object that is not yet fully initialized yet.
689   inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
690
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);
694
695   // Update the cache with a new number-string pair.
696   void SetNumberStringCache(Handle<Object> number, Handle<String> string);
697
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);
705
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);
711
712   Handle<JSFunction> NewFunction(Handle<Map> map,
713                                  Handle<String> name,
714                                  MaybeHandle<Code> maybe_code);
715
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);
721 };
722
723 }  // namespace internal
724 }  // namespace v8
725
726 #endif  // V8_FACTORY_H_