Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / v8 / src / factory.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_FACTORY_H_
29 #define V8_FACTORY_H_
30
31 #include "globals.h"
32 #include "handles.h"
33 #include "heap.h"
34
35 namespace v8 {
36 namespace internal {
37
38 // Interface for handle based allocation.
39
40 class Factory {
41  public:
42   // Allocate a new boxed value.
43   Handle<Box> NewBox(
44       Handle<Object> value,
45       PretenureFlag pretenure = NOT_TENURED);
46
47   // Allocates a fixed array initialized with undefined values.
48   Handle<FixedArray> NewFixedArray(
49       int size,
50       PretenureFlag pretenure = NOT_TENURED);
51
52   // Allocate a new fixed array with non-existing entries (the hole).
53   Handle<FixedArray> NewFixedArrayWithHoles(
54       int size,
55       PretenureFlag pretenure = NOT_TENURED);
56
57   // Allocates an uninitialized fixed array. It must be filled by the caller.
58   Handle<FixedArray> NewUninitializedFixedArray(int size);
59
60   // Allocate a new uninitialized fixed double array.
61   Handle<FixedDoubleArray> NewFixedDoubleArray(
62       int size,
63       PretenureFlag pretenure = NOT_TENURED);
64
65   Handle<ConstantPoolArray> NewConstantPoolArray(
66       int number_of_int64_entries,
67       int number_of_code_ptr_entries,
68       int number_of_heap_ptr_entries,
69       int number_of_int32_entries);
70
71   Handle<SeededNumberDictionary> NewSeededNumberDictionary(
72       int at_least_space_for);
73
74   Handle<UnseededNumberDictionary> NewUnseededNumberDictionary(
75       int at_least_space_for);
76
77   Handle<NameDictionary> NewNameDictionary(int at_least_space_for);
78
79   Handle<ObjectHashSet> NewObjectHashSet(int at_least_space_for);
80
81   Handle<ObjectHashTable> NewObjectHashTable(
82       int at_least_space_for,
83       MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY);
84
85   Handle<WeakHashTable> NewWeakHashTable(int at_least_space_for);
86
87   Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors,
88                                              int slack = 0);
89   Handle<DeoptimizationInputData> NewDeoptimizationInputData(
90       int deopt_entry_count,
91       PretenureFlag pretenure);
92   Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
93       int deopt_entry_count,
94       PretenureFlag pretenure);
95   // Allocates a pre-tenured empty AccessorPair.
96   Handle<AccessorPair> NewAccessorPair();
97
98   Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
99
100   Handle<String> InternalizeUtf8String(Vector<const char> str);
101   Handle<String> InternalizeUtf8String(const char* str) {
102     return InternalizeUtf8String(CStrVector(str));
103   }
104   Handle<String> InternalizeString(Handle<String> str);
105   Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
106   Handle<String> InternalizeOneByteString(
107       Handle<SeqOneByteString>, int from, int length);
108
109   Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
110
111   template<class StringTableKey>
112   Handle<String> InternalizeStringWithKey(StringTableKey* key);
113
114
115   // String creation functions.  Most of the string creation functions take
116   // a Heap::PretenureFlag argument to optionally request that they be
117   // allocated in the old generation.  The pretenure flag defaults to
118   // DONT_TENURE.
119   //
120   // Creates a new String object.  There are two String encodings: ASCII and
121   // two byte.  One should choose between the three string factory functions
122   // based on the encoding of the string buffer that the string is
123   // initialized from.
124   //   - ...FromAscii initializes the string from a buffer that is ASCII
125   //     encoded (it does not check that the buffer is ASCII encoded) and
126   //     the result will be ASCII encoded.
127   //   - ...FromUtf8 initializes the string from a buffer that is UTF-8
128   //     encoded.  If the characters are all single-byte characters, the
129   //     result will be ASCII encoded, otherwise it will converted to two
130   //     byte.
131   //   - ...FromTwoByte initializes the string from a buffer that is two
132   //     byte encoded.  If the characters are all single-byte characters,
133   //     the result will be converted to ASCII, otherwise it will be left as
134   //     two byte.
135   //
136   // ASCII strings are pretenured when used as keys in the SourceCodeCache.
137   Handle<String> NewStringFromOneByte(
138       Vector<const uint8_t> str,
139       PretenureFlag pretenure = NOT_TENURED);
140   // TODO(dcarney): remove this function.
141   inline Handle<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   Handle<String> NewStringFromUtf8(
150       Vector<const char> str,
151       PretenureFlag pretenure = NOT_TENURED);
152
153   Handle<String> NewStringFromTwoByte(
154       Vector<const uc16> str,
155       PretenureFlag pretenure = NOT_TENURED);
156
157   // Allocates and partially initializes an ASCII or TwoByte String. The
158   // characters of the string are uninitialized. Currently used in regexp code
159   // only, where they are pretenured.
160   Handle<SeqOneByteString> NewRawOneByteString(
161       int length,
162       PretenureFlag pretenure = NOT_TENURED);
163   Handle<SeqTwoByteString> NewRawTwoByteString(
164       int length,
165       PretenureFlag pretenure = NOT_TENURED);
166
167   // Create a new cons string object which consists of a pair of strings.
168   Handle<String> NewConsString(Handle<String> left,
169                                Handle<String> right);
170
171   Handle<ConsString> NewRawConsString(String::Encoding encoding);
172
173   // Create a new sequential string containing the concatenation of the inputs.
174   Handle<String> NewFlatConcatString(Handle<String> first,
175                                      Handle<String> second);
176
177   // Create a new string object which holds a proper substring of a string.
178   Handle<String> NewProperSubString(Handle<String> str,
179                                     int begin,
180                                     int end);
181
182   // Create a new string object which holds a substring of a string.
183   Handle<String> NewSubString(Handle<String> str, int begin, int end) {
184     if (begin == 0 && end == str->length()) return str;
185     return NewProperSubString(str, begin, end);
186   }
187
188   Handle<SlicedString> NewRawSlicedString(String::Encoding encoding);
189
190   // Creates a new external String object.  There are two String encodings
191   // in the system: ASCII and two byte.  Unlike other String types, it does
192   // not make sense to have a UTF-8 factory function for external strings,
193   // because we cannot change the underlying buffer.
194   Handle<String> NewExternalStringFromAscii(
195       const ExternalAsciiString::Resource* resource);
196   Handle<String> NewExternalStringFromTwoByte(
197       const ExternalTwoByteString::Resource* resource);
198
199   // Create a symbol.
200   Handle<Symbol> NewSymbol();
201   Handle<Symbol> NewPrivateSymbol();
202
203   // Create a global (but otherwise uninitialized) context.
204   Handle<Context> NewNativeContext();
205
206   // Create a global context.
207   Handle<Context> NewGlobalContext(Handle<JSFunction> function,
208                                    Handle<ScopeInfo> scope_info);
209
210   // Create a module context.
211   Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
212
213   // Create a function context.
214   Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
215
216   // Create a catch context.
217   Handle<Context> NewCatchContext(Handle<JSFunction> function,
218                                   Handle<Context> previous,
219                                   Handle<String> name,
220                                   Handle<Object> thrown_object);
221
222   // Create a 'with' context.
223   Handle<Context> NewWithContext(Handle<JSFunction> function,
224                                  Handle<Context> previous,
225                                  Handle<JSObject> extension);
226
227   // Create a block context.
228   Handle<Context> NewBlockContext(Handle<JSFunction> function,
229                                   Handle<Context> previous,
230                                   Handle<ScopeInfo> scope_info);
231
232   // Allocate a new struct.  The struct is pretenured (allocated directly in
233   // the old generation).
234   Handle<Struct> NewStruct(InstanceType type);
235
236   Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
237       int aliased_context_slot);
238
239   Handle<DeclaredAccessorDescriptor> NewDeclaredAccessorDescriptor();
240
241   Handle<DeclaredAccessorInfo> NewDeclaredAccessorInfo();
242
243   Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
244
245   Handle<Script> NewScript(Handle<String> source);
246
247   // Foreign objects are pretenured when allocated by the bootstrapper.
248   Handle<Foreign> NewForeign(Address addr,
249                              PretenureFlag pretenure = NOT_TENURED);
250
251   // Allocate a new foreign object.  The foreign is pretenured (allocated
252   // directly in the old generation).
253   Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
254
255   Handle<ByteArray> NewByteArray(int length,
256                                  PretenureFlag pretenure = NOT_TENURED);
257
258   Handle<ExternalArray> NewExternalArray(
259       int length,
260       ExternalArrayType array_type,
261       void* external_pointer,
262       PretenureFlag pretenure = NOT_TENURED);
263
264   Handle<FixedTypedArrayBase> NewFixedTypedArray(
265       int length,
266       ExternalArrayType array_type,
267       PretenureFlag pretenure = NOT_TENURED);
268
269   Handle<Cell> NewCell(Handle<Object> value);
270
271   Handle<PropertyCell> NewPropertyCellWithHole();
272
273   Handle<PropertyCell> NewPropertyCell(Handle<Object> value);
274
275   Handle<AllocationSite> NewAllocationSite();
276
277   Handle<Map> NewMap(
278       InstanceType type,
279       int instance_size,
280       ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
281
282   Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
283
284   Handle<Map> CopyWithPreallocatedFieldDescriptors(Handle<Map> map);
285
286   // Copy the map adding more inobject properties if possible without
287   // overflowing the instance size.
288   Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
289   Handle<Map> CopyMap(Handle<Map> map);
290
291   Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
292
293   // This method expects a COW array in new space, and creates a copy
294   // of it in old space.
295   Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
296
297   Handle<FixedArray> CopySizeFixedArray(Handle<FixedArray> array,
298                                         int new_length,
299                                         PretenureFlag pretenure = NOT_TENURED);
300
301   Handle<FixedDoubleArray> CopyFixedDoubleArray(
302       Handle<FixedDoubleArray> array);
303
304   Handle<ConstantPoolArray> CopyConstantPoolArray(
305       Handle<ConstantPoolArray> array);
306
307   // Numbers (e.g. literals) are pretenured by the parser.
308   Handle<Object> NewNumber(double value,
309                            PretenureFlag pretenure = NOT_TENURED);
310
311   Handle<Object> NewNumberFromInt(int32_t value,
312                                   PretenureFlag pretenure = NOT_TENURED);
313   Handle<Object> NewNumberFromUint(uint32_t value,
314                                   PretenureFlag pretenure = NOT_TENURED);
315   inline Handle<Object> NewNumberFromSize(size_t value,
316                                    PretenureFlag pretenure = NOT_TENURED);
317   Handle<HeapNumber> NewHeapNumber(double value,
318                                    PretenureFlag pretenure = NOT_TENURED);
319
320   Handle<Float32x4> NewFloat32x4(float32x4_value_t value,
321                                  PretenureFlag pretenure = NOT_TENURED);
322
323   Handle<Int32x4> NewInt32x4(int32x4_value_t value,
324                                PretenureFlag pretenure = NOT_TENURED);
325
326   // These objects are used by the api to create env-independent data
327   // structures in the heap.
328   Handle<JSObject> NewNeanderObject();
329
330   Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
331
332   // JS objects are pretenured when allocated by the bootstrapper and
333   // runtime.
334   Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
335                                PretenureFlag pretenure = NOT_TENURED);
336   // JSObject that should have a memento pointing to the allocation site.
337   Handle<JSObject> NewJSObjectWithMemento(Handle<JSFunction> constructor,
338                                           Handle<AllocationSite> site);
339
340   // Global objects are pretenured and initialized based on a constructor.
341   Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
342
343   // JS objects are pretenured when allocated by the bootstrapper and
344   // runtime.
345   Handle<JSObject> NewJSObjectFromMap(
346       Handle<Map> map,
347       PretenureFlag pretenure = NOT_TENURED,
348       bool allocate_properties = true,
349       Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
350
351   Handle<JSObject> NewJSObjectFromMapForDeoptimizer(
352       Handle<Map> map, PretenureFlag pretenure = NOT_TENURED);
353
354   // JS modules are pretenured.
355   Handle<JSModule> NewJSModule(Handle<Context> context,
356                                Handle<ScopeInfo> scope_info);
357
358   // JS arrays are pretenured when allocated by the parser.
359   Handle<JSArray> NewJSArray(
360       ElementsKind elements_kind,
361       int length,
362       int capacity,
363       PretenureFlag pretenure = NOT_TENURED);
364
365   Handle<JSArray> NewJSArray(
366       int capacity,
367       ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
368       PretenureFlag pretenure = NOT_TENURED) {
369     return NewJSArray(elements_kind, 0, capacity, pretenure);
370   }
371
372   Handle<JSArray> NewJSArrayWithElements(
373       Handle<FixedArrayBase> elements,
374       ElementsKind elements_kind,
375       int length,
376       PretenureFlag pretenure = NOT_TENURED);
377
378   Handle<JSArray> NewJSArrayWithElements(
379       Handle<FixedArrayBase> elements,
380       ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
381       PretenureFlag pretenure = NOT_TENURED) {
382     return NewJSArrayWithElements(
383         elements, elements_kind, elements->length(), pretenure);
384   }
385
386   void NewJSArrayStorage(
387       Handle<JSArray> array,
388       int length,
389       int capacity,
390       ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
391
392   Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
393
394   Handle<JSArrayBuffer> NewJSArrayBuffer();
395
396   Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
397
398   Handle<JSDataView> NewJSDataView();
399
400   Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
401
402   // Change the type of the argument into a JS object/function and reinitialize.
403   void BecomeJSObject(Handle<JSReceiver> object);
404   void BecomeJSFunction(Handle<JSReceiver> object);
405
406   Handle<JSFunction> NewFunction(Handle<String> name,
407                                  Handle<Object> prototype);
408
409   Handle<JSFunction> NewFunctionWithoutPrototype(
410       Handle<String> name,
411       StrictMode strict_mode);
412
413   Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
414
415   Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
416       Handle<SharedFunctionInfo> function_info,
417       Handle<Map> function_map,
418       PretenureFlag pretenure);
419
420   Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
421       Handle<SharedFunctionInfo> function_info,
422       Handle<Context> context,
423       PretenureFlag pretenure = TENURED);
424
425   Handle<ScopeInfo> NewScopeInfo(int length);
426
427   Handle<JSObject> NewExternal(void* value);
428
429   Handle<Code> NewCode(const CodeDesc& desc,
430                        Code::Flags flags,
431                        Handle<Object> self_reference,
432                        bool immovable = false,
433                        bool crankshafted = false,
434                        int prologue_offset = Code::kPrologueOffsetNotSet);
435
436   Handle<Code> CopyCode(Handle<Code> code);
437
438   Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
439
440   Handle<Object> ToObject(Handle<Object> object);
441   Handle<Object> ToObject(Handle<Object> object,
442                           Handle<Context> native_context);
443
444   // Interface for creating error objects.
445
446   Handle<Object> NewError(const char* maker, const char* message,
447                           Handle<JSArray> args);
448   Handle<String> EmergencyNewError(const char* message, Handle<JSArray> args);
449   Handle<Object> NewError(const char* maker, const char* message,
450                           Vector< Handle<Object> > args);
451   Handle<Object> NewError(const char* message,
452                           Vector< Handle<Object> > args);
453   Handle<Object> NewError(Handle<String> message);
454   Handle<Object> NewError(const char* constructor,
455                           Handle<String> message);
456
457   Handle<Object> NewTypeError(const char* message,
458                               Vector< Handle<Object> > args);
459   Handle<Object> NewTypeError(Handle<String> message);
460
461   Handle<Object> NewRangeError(const char* message,
462                                Vector< Handle<Object> > args);
463   Handle<Object> NewRangeError(Handle<String> message);
464
465   Handle<Object> NewSyntaxError(const char* message, Handle<JSArray> args);
466   Handle<Object> NewSyntaxError(Handle<String> message);
467
468   Handle<Object> NewReferenceError(const char* message,
469                                    Vector< Handle<Object> > args);
470   Handle<Object> NewReferenceError(const char* message, Handle<JSArray> args);
471   Handle<Object> NewReferenceError(Handle<String> message);
472
473   Handle<Object> NewEvalError(const char* message,
474                               Vector< Handle<Object> > args);
475
476
477   Handle<JSFunction> NewFunction(Handle<String> name,
478                                  InstanceType type,
479                                  int instance_size,
480                                  Handle<Code> code,
481                                  bool force_initial_map);
482
483   Handle<JSFunction> NewFunction(Handle<Map> function_map,
484       Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
485
486
487   Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
488                                               InstanceType type,
489                                               int instance_size,
490                                               Handle<JSObject> prototype,
491                                               Handle<Code> code,
492                                               bool force_initial_map);
493
494   Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
495                                                  Handle<Code> code);
496
497   Handle<String> NumberToString(Handle<Object> number);
498   Handle<String> Uint32ToString(uint32_t value);
499
500   enum ApiInstanceType {
501     JavaScriptObject,
502     InnerGlobalObject,
503     OuterGlobalObject
504   };
505
506   Handle<JSFunction> CreateApiFunction(
507       Handle<FunctionTemplateInfo> data,
508       ApiInstanceType type = JavaScriptObject);
509
510   Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
511
512   // Installs interceptors on the instance.  'desc' is a function template,
513   // and instance is an object instance created by the function of this
514   // function template.
515   void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
516                          Handle<JSObject> instance,
517                          bool* pending_exception);
518
519 #define ROOT_ACCESSOR(type, name, camel_name)                                  \
520   inline Handle<type> name() {                                                 \
521     return Handle<type>(BitCast<type**>(                                       \
522         &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex]));          \
523   }
524   ROOT_LIST(ROOT_ACCESSOR)
525 #undef ROOT_ACCESSOR
526
527 #define STRUCT_MAP_ACCESSOR(NAME, Name, name)                                  \
528   inline Handle<Map> name##_map() {                                            \
529     return Handle<Map>(BitCast<Map**>(                                         \
530         &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex]));             \
531     }
532   STRUCT_LIST(STRUCT_MAP_ACCESSOR)
533 #undef STRUCT_MAP_ACCESSOR
534
535 #define STRING_ACCESSOR(name, str)                                             \
536   inline Handle<String> name() {                                               \
537     return Handle<String>(BitCast<String**>(                                   \
538         &isolate()->heap()->roots_[Heap::k##name##RootIndex]));                \
539   }
540   INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
541 #undef STRING_ACCESSOR
542
543   Handle<String> hidden_string() {
544     return Handle<String>(&isolate()->heap()->hidden_string_);
545   }
546
547   Handle<SharedFunctionInfo> NewSharedFunctionInfo(
548       Handle<String> name,
549       int number_of_literals,
550       bool is_generator,
551       Handle<Code> code,
552       Handle<ScopeInfo> scope_info);
553   Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
554
555   Handle<JSMessageObject> NewJSMessageObject(
556       Handle<String> type,
557       Handle<JSArray> arguments,
558       int start_position,
559       int end_position,
560       Handle<Object> script,
561       Handle<Object> stack_frames);
562
563   Handle<SeededNumberDictionary> DictionaryAtNumberPut(
564       Handle<SeededNumberDictionary>,
565       uint32_t key,
566       Handle<Object> value);
567
568   Handle<UnseededNumberDictionary> DictionaryAtNumberPut(
569       Handle<UnseededNumberDictionary>,
570       uint32_t key,
571       Handle<Object> value);
572
573 #ifdef ENABLE_DEBUGGER_SUPPORT
574   Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
575 #endif
576
577   // Return a map using the map cache in the native context.
578   // The key the an ordered set of property names.
579   Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
580                                         Handle<FixedArray> keys);
581
582   // Creates a new FixedArray that holds the data associated with the
583   // atom regexp and stores it in the regexp.
584   void SetRegExpAtomData(Handle<JSRegExp> regexp,
585                          JSRegExp::Type type,
586                          Handle<String> source,
587                          JSRegExp::Flags flags,
588                          Handle<Object> match_pattern);
589
590   // Creates a new FixedArray that holds the data associated with the
591   // irregexp regexp and stores it in the regexp.
592   void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
593                              JSRegExp::Type type,
594                              Handle<String> source,
595                              JSRegExp::Flags flags,
596                              int capture_count);
597
598   // Returns the value for a known global constant (a property of the global
599   // object which is neither configurable nor writable) like 'undefined'.
600   // Returns a null handle when the given name is unknown.
601   Handle<Object> GlobalConstantFor(Handle<String> name);
602
603   // Converts the given boolean condition to JavaScript boolean value.
604   Handle<Object> ToBoolean(bool value);
605
606  private:
607   Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
608
609   Handle<JSFunction> NewFunctionHelper(Handle<String> name,
610                                        Handle<Object> prototype);
611
612   Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
613       Handle<String> name,
614       StrictMode strict_mode);
615
616   // Create a new map cache.
617   Handle<MapCache> NewMapCache(int at_least_space_for);
618
619   // Update the map cache in the native context with (keys, map)
620   Handle<MapCache> AddToMapCache(Handle<Context> context,
621                                  Handle<FixedArray> keys,
622                                  Handle<Map> map);
623 };
624
625
626 Handle<Object> Factory::NewNumberFromSize(size_t value,
627                                           PretenureFlag pretenure) {
628   if (Smi::IsValid(static_cast<intptr_t>(value))) {
629     return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
630                           isolate());
631   } else {
632     return NewNumber(static_cast<double>(value), pretenure);
633   }
634 }
635
636
637 } }  // namespace v8::internal
638
639 #endif  // V8_FACTORY_H_