1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "src/isolate.h"
13 // Interface for handle based allocation.
15 class Factory V8_FINAL {
17 Handle<Oddball> NewOddball(Handle<Map> map,
18 const char* to_string,
19 Handle<Object> to_number,
22 // Allocates a fixed array initialized with undefined values.
23 Handle<FixedArray> NewFixedArray(
25 PretenureFlag pretenure = NOT_TENURED);
27 // Allocate a new fixed array with non-existing entries (the hole).
28 Handle<FixedArray> NewFixedArrayWithHoles(
30 PretenureFlag pretenure = NOT_TENURED);
32 // Allocates an uninitialized fixed array. It must be filled by the caller.
33 Handle<FixedArray> NewUninitializedFixedArray(int size);
35 // Allocate a new uninitialized fixed double array.
36 // The function returns a pre-allocated empty fixed array for capacity = 0,
37 // so the return type must be the general fixed array class.
38 Handle<FixedArrayBase> NewFixedDoubleArray(
40 PretenureFlag pretenure = NOT_TENURED);
42 // Allocate a new fixed double array with hole values.
43 Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles(
45 PretenureFlag pretenure = NOT_TENURED);
47 Handle<ConstantPoolArray> NewConstantPoolArray(
48 const ConstantPoolArray::NumberOfEntries& small);
50 Handle<ConstantPoolArray> NewExtendedConstantPoolArray(
51 const ConstantPoolArray::NumberOfEntries& small,
52 const ConstantPoolArray::NumberOfEntries& extended);
54 Handle<OrderedHashSet> NewOrderedHashSet();
55 Handle<OrderedHashMap> NewOrderedHashMap();
57 // Create a new boxed value.
58 Handle<Box> NewBox(Handle<Object> value);
60 // Create a pre-tenured empty AccessorPair.
61 Handle<AccessorPair> NewAccessorPair();
63 // Create an empty TypeFeedbackInfo.
64 Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
66 // Finds the internalized copy for string in the string table.
67 // If not found, a new string is added to the table and returned.
68 Handle<String> InternalizeUtf8String(Vector<const char> str);
69 Handle<String> InternalizeUtf8String(const char* str) {
70 return InternalizeUtf8String(CStrVector(str));
72 Handle<String> InternalizeString(Handle<String> str);
73 Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
74 Handle<String> InternalizeOneByteString(
75 Handle<SeqOneByteString>, int from, int length);
77 Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
79 template<class StringTableKey>
80 Handle<String> InternalizeStringWithKey(StringTableKey* key);
83 // String creation functions. Most of the string creation functions take
84 // a Heap::PretenureFlag argument to optionally request that they be
85 // allocated in the old generation. The pretenure flag defaults to
88 // Creates a new String object. There are two String encodings: ASCII and
89 // two byte. One should choose between the three string factory functions
90 // based on the encoding of the string buffer that the string is
92 // - ...FromAscii initializes the string from a buffer that is ASCII
93 // encoded (it does not check that the buffer is ASCII encoded) and
94 // the result will be ASCII encoded.
95 // - ...FromUtf8 initializes the string from a buffer that is UTF-8
96 // encoded. If the characters are all single-byte characters, the
97 // result will be ASCII encoded, otherwise it will converted to two
99 // - ...FromTwoByte initializes the string from a buffer that is two
100 // byte encoded. If the characters are all single-byte characters,
101 // the result will be converted to ASCII, otherwise it will be left as
104 // ASCII 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);
110 inline Handle<String> NewStringFromStaticAscii(
111 const char (&str)[N],
112 PretenureFlag pretenure = NOT_TENURED) {
113 DCHECK(N == StrLength(str) + 1);
114 return NewStringFromOneByte(
115 STATIC_ASCII_VECTOR(str), pretenure).ToHandleChecked();
118 inline Handle<String> NewStringFromAsciiChecked(
120 PretenureFlag pretenure = NOT_TENURED) {
121 return NewStringFromOneByte(
122 OneByteVector(str), pretenure).ToHandleChecked();
126 // Allocates and fully initializes a String. There are two String
127 // encodings: ASCII and two byte. One should choose between the three string
128 // allocation functions based on the encoding of the string buffer used to
129 // initialized the string.
130 // - ...FromAscii initializes the string from a buffer that is ASCII
131 // encoded (it does not check that the buffer is ASCII encoded) and the
132 // result will be ASCII encoded.
133 // - ...FromUTF8 initializes the string from a buffer that is UTF-8
134 // encoded. If the characters are all single-byte characters, the
135 // result will be ASCII encoded, otherwise it will converted to two
137 // - ...FromTwoByte initializes the string from a buffer that is two-byte
138 // encoded. If the characters are all single-byte characters, the
139 // result will be converted to ASCII, otherwise it will be left as
142 // TODO(dcarney): remove this function.
143 MUST_USE_RESULT inline MaybeHandle<String> NewStringFromAscii(
144 Vector<const char> str,
145 PretenureFlag pretenure = NOT_TENURED) {
146 return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure);
149 // UTF8 strings are pretenured when used for regexp literal patterns and
150 // flags in the parser.
151 MUST_USE_RESULT MaybeHandle<String> NewStringFromUtf8(
152 Vector<const char> str,
153 PretenureFlag pretenure = NOT_TENURED);
155 MUST_USE_RESULT MaybeHandle<String> NewStringFromTwoByte(
156 Vector<const uc16> str,
157 PretenureFlag pretenure = NOT_TENURED);
159 // Allocates an internalized string in old space based on the character
161 MUST_USE_RESULT Handle<String> NewInternalizedStringFromUtf8(
162 Vector<const char> str,
164 uint32_t hash_field);
166 MUST_USE_RESULT Handle<String> NewOneByteInternalizedString(
167 Vector<const uint8_t> str,
168 uint32_t hash_field);
170 MUST_USE_RESULT Handle<String> NewTwoByteInternalizedString(
171 Vector<const uc16> str,
172 uint32_t hash_field);
174 MUST_USE_RESULT Handle<String> NewInternalizedStringImpl(
175 Handle<String> string, int chars, uint32_t hash_field);
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);
182 // Allocates and partially initializes an ASCII or TwoByte 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(
187 PretenureFlag pretenure = NOT_TENURED);
188 MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString(
190 PretenureFlag pretenure = NOT_TENURED);
192 // Creates a single character string where the character has given code.
193 // A cache is used for ASCII codes.
194 Handle<String> LookupSingleCharacterStringFromCode(uint32_t code);
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);
200 // Create a new string object which holds a proper substring of a string.
201 Handle<String> NewProperSubString(Handle<String> str,
205 // Create a new string object which holds a substring of a string.
206 Handle<String> NewSubString(Handle<String> str, int begin, int end) {
207 if (begin == 0 && end == str->length()) return str;
208 return NewProperSubString(str, begin, end);
211 // Creates a new external String object. There are two String encodings
212 // in the system: ASCII and two byte. Unlike other String types, it does
213 // not make sense to have a UTF-8 factory function for external strings,
214 // because we cannot change the underlying buffer. Note that these strings
215 // are backed by a string resource that resides outside the V8 heap.
216 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromAscii(
217 const ExternalAsciiString::Resource* resource);
218 MUST_USE_RESULT MaybeHandle<String> NewExternalStringFromTwoByte(
219 const ExternalTwoByteString::Resource* resource);
222 Handle<Symbol> NewSymbol();
223 Handle<Symbol> NewPrivateSymbol();
225 // Create a global (but otherwise uninitialized) context.
226 Handle<Context> NewNativeContext();
228 // Create a global context.
229 Handle<Context> NewGlobalContext(Handle<JSFunction> function,
230 Handle<ScopeInfo> scope_info);
232 // Create a module context.
233 Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
235 // Create a function context.
236 Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
238 // Create a catch context.
239 Handle<Context> NewCatchContext(Handle<JSFunction> function,
240 Handle<Context> previous,
242 Handle<Object> thrown_object);
244 // Create a 'with' context.
245 Handle<Context> NewWithContext(Handle<JSFunction> function,
246 Handle<Context> previous,
247 Handle<JSReceiver> extension);
249 // Create a block context.
250 Handle<Context> NewBlockContext(Handle<JSFunction> function,
251 Handle<Context> previous,
252 Handle<ScopeInfo> scope_info);
254 // Allocate a new struct. The struct is pretenured (allocated directly in
255 // the old generation).
256 Handle<Struct> NewStruct(InstanceType type);
258 Handle<CodeCache> NewCodeCache();
260 Handle<AliasedArgumentsEntry> NewAliasedArgumentsEntry(
261 int aliased_context_slot);
263 Handle<DeclaredAccessorDescriptor> NewDeclaredAccessorDescriptor();
265 Handle<DeclaredAccessorInfo> NewDeclaredAccessorInfo();
267 Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
269 Handle<Script> NewScript(Handle<String> source);
271 // Foreign objects are pretenured when allocated by the bootstrapper.
272 Handle<Foreign> NewForeign(Address addr,
273 PretenureFlag pretenure = NOT_TENURED);
275 // Allocate a new foreign object. The foreign is pretenured (allocated
276 // directly in the old generation).
277 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
279 Handle<ByteArray> NewByteArray(int length,
280 PretenureFlag pretenure = NOT_TENURED);
282 Handle<ExternalArray> NewExternalArray(
284 ExternalArrayType array_type,
285 void* external_pointer,
286 PretenureFlag pretenure = NOT_TENURED);
288 Handle<FixedTypedArrayBase> NewFixedTypedArray(
290 ExternalArrayType array_type,
291 PretenureFlag pretenure = NOT_TENURED);
293 Handle<Cell> NewCell(Handle<Object> value);
295 Handle<PropertyCell> NewPropertyCellWithHole();
297 Handle<PropertyCell> NewPropertyCell(Handle<Object> value);
299 // Allocate a tenured AllocationSite. It's payload is null.
300 Handle<AllocationSite> NewAllocationSite();
305 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
307 Handle<HeapObject> NewFillerObject(int size,
309 AllocationSpace space);
311 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
313 Handle<JSObject> CopyJSObject(Handle<JSObject> object);
315 Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
316 Handle<AllocationSite> site);
318 Handle<FixedArray> CopyFixedArrayWithMap(Handle<FixedArray> array,
321 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
323 // This method expects a COW array in new space, and creates a copy
324 // of it in old space.
325 Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
327 Handle<FixedDoubleArray> CopyFixedDoubleArray(
328 Handle<FixedDoubleArray> array);
330 Handle<ConstantPoolArray> CopyConstantPoolArray(
331 Handle<ConstantPoolArray> array);
333 // Numbers (e.g. literals) are pretenured by the parser.
334 // The return value may be a smi or a heap number.
335 Handle<Object> NewNumber(double value,
336 PretenureFlag pretenure = NOT_TENURED);
338 Handle<Object> NewNumberFromInt(int32_t value,
339 PretenureFlag pretenure = NOT_TENURED);
340 Handle<Object> NewNumberFromUint(uint32_t value,
341 PretenureFlag pretenure = NOT_TENURED);
342 Handle<Object> NewNumberFromSize(size_t value,
343 PretenureFlag pretenure = NOT_TENURED) {
344 if (Smi::IsValid(static_cast<intptr_t>(value))) {
345 return Handle<Object>(Smi::FromIntptr(static_cast<intptr_t>(value)),
348 return NewNumber(static_cast<double>(value), pretenure);
350 Handle<HeapNumber> NewHeapNumber(double value,
351 MutableMode mode = IMMUTABLE,
352 PretenureFlag pretenure = NOT_TENURED);
354 // These objects are used by the api to create env-independent data
355 // structures in the heap.
356 inline Handle<JSObject> NewNeanderObject() {
357 return NewJSObjectFromMap(neander_map());
360 Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
362 // JS objects are pretenured when allocated by the bootstrapper and
364 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
365 PretenureFlag pretenure = NOT_TENURED);
366 // JSObject that should have a memento pointing to the allocation site.
367 Handle<JSObject> NewJSObjectWithMemento(Handle<JSFunction> constructor,
368 Handle<AllocationSite> site);
370 // Global objects are pretenured and initialized based on a constructor.
371 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
373 // JS objects are pretenured when allocated by the bootstrapper and
375 Handle<JSObject> NewJSObjectFromMap(
377 PretenureFlag pretenure = NOT_TENURED,
378 bool allocate_properties = true,
379 Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
381 // JS modules are pretenured.
382 Handle<JSModule> NewJSModule(Handle<Context> context,
383 Handle<ScopeInfo> scope_info);
385 // JS arrays are pretenured when allocated by the parser.
387 // Create a JSArray with no elements.
388 Handle<JSArray> NewJSArray(
389 ElementsKind elements_kind,
390 PretenureFlag pretenure = NOT_TENURED);
392 // Create a JSArray with a specified length and elements initialized
393 // according to the specified mode.
394 Handle<JSArray> NewJSArray(
395 ElementsKind elements_kind, int length, int capacity,
396 ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS,
397 PretenureFlag pretenure = NOT_TENURED);
399 Handle<JSArray> NewJSArray(
401 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
402 PretenureFlag pretenure = NOT_TENURED) {
404 elements_kind = GetHoleyElementsKind(elements_kind);
406 return NewJSArray(elements_kind, 0, capacity,
407 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
410 // Create a JSArray with the given elements.
411 Handle<JSArray> NewJSArrayWithElements(
412 Handle<FixedArrayBase> elements,
413 ElementsKind elements_kind,
415 PretenureFlag pretenure = NOT_TENURED);
417 Handle<JSArray> NewJSArrayWithElements(
418 Handle<FixedArrayBase> elements,
419 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
420 PretenureFlag pretenure = NOT_TENURED) {
421 return NewJSArrayWithElements(
422 elements, elements_kind, elements->length(), pretenure);
425 void NewJSArrayStorage(
426 Handle<JSArray> array,
429 ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
431 Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
433 Handle<JSArrayBuffer> NewJSArrayBuffer();
435 Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
437 Handle<JSDataView> NewJSDataView();
439 // Allocates a Harmony proxy.
440 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
442 // Allocates a Harmony function proxy.
443 Handle<JSProxy> NewJSFunctionProxy(Handle<Object> handler,
444 Handle<Object> call_trap,
445 Handle<Object> construct_trap,
446 Handle<Object> prototype);
448 // Reinitialize a JSReceiver into an (empty) JS object of respective type and
449 // size, but keeping the original prototype. The receiver must have at least
450 // the size of the new object. The object is reinitialized and behaves as an
451 // object that has been freshly allocated.
452 void ReinitializeJSReceiver(
453 Handle<JSReceiver> object, InstanceType type, int size);
455 // Reinitialize an JSGlobalProxy based on a constructor. The object
456 // must have the same size as objects allocated using the
457 // constructor. The object is reinitialized and behaves as an
458 // object that has been freshly allocated using the constructor.
459 void ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> global,
460 Handle<JSFunction> constructor);
462 // Change the type of the argument into a JS object/function and reinitialize.
463 void BecomeJSObject(Handle<JSReceiver> object);
464 void BecomeJSFunction(Handle<JSReceiver> object);
466 Handle<JSFunction> NewFunction(Handle<String> name,
468 Handle<Object> prototype,
469 bool read_only_prototype = false);
470 Handle<JSFunction> NewFunction(Handle<String> name);
471 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
474 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
475 Handle<SharedFunctionInfo> function_info,
476 Handle<Context> context,
477 PretenureFlag pretenure = TENURED);
479 Handle<JSFunction> NewFunction(Handle<String> name,
481 Handle<Object> prototype,
484 bool read_only_prototype = false);
485 Handle<JSFunction> NewFunction(Handle<String> name,
490 // Create a serialized scope info.
491 Handle<ScopeInfo> NewScopeInfo(int length);
493 // Create an External object for V8's external API.
494 Handle<JSObject> NewExternal(void* value);
496 // The reference to the Code object is stored in self_reference.
497 // This allows generated code to reference its own Code object
498 // by containing this handle.
499 Handle<Code> NewCode(const CodeDesc& desc,
501 Handle<Object> self_reference,
502 bool immovable = false,
503 bool crankshafted = false,
504 int prologue_offset = Code::kPrologueOffsetNotSet,
505 bool is_debug = false);
507 Handle<Code> CopyCode(Handle<Code> code);
509 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
511 // Interface for creating error objects.
513 Handle<Object> NewError(const char* maker, const char* message,
514 Handle<JSArray> args);
515 Handle<String> EmergencyNewError(const char* message, Handle<JSArray> args);
516 Handle<Object> NewError(const char* maker, const char* message,
517 Vector< Handle<Object> > args);
518 Handle<Object> NewError(const char* message,
519 Vector< Handle<Object> > args);
520 Handle<Object> NewError(Handle<String> message);
521 Handle<Object> NewError(const char* constructor,
522 Handle<String> message);
524 Handle<Object> NewTypeError(const char* message,
525 Vector< Handle<Object> > args);
526 Handle<Object> NewTypeError(Handle<String> message);
528 Handle<Object> NewRangeError(const char* message,
529 Vector< Handle<Object> > args);
530 Handle<Object> NewRangeError(Handle<String> message);
532 Handle<Object> NewInvalidStringLengthError() {
533 return NewRangeError("invalid_string_length",
534 HandleVector<Object>(NULL, 0));
537 Handle<Object> NewSyntaxError(const char* message, Handle<JSArray> args);
538 Handle<Object> NewSyntaxError(Handle<String> message);
540 Handle<Object> NewReferenceError(const char* message,
541 Vector< Handle<Object> > args);
542 Handle<Object> NewReferenceError(const char* message, Handle<JSArray> args);
543 Handle<Object> NewReferenceError(Handle<String> message);
545 Handle<Object> NewEvalError(const char* message,
546 Vector< Handle<Object> > args);
548 Handle<String> NumberToString(Handle<Object> number,
549 bool check_number_string_cache = true);
551 Handle<String> Uint32ToString(uint32_t value) {
552 return NumberToString(NewNumberFromUint(value));
555 enum ApiInstanceType {
556 JavaScriptObjectType,
561 Handle<JSFunction> CreateApiFunction(
562 Handle<FunctionTemplateInfo> data,
563 Handle<Object> prototype,
564 ApiInstanceType type = JavaScriptObjectType);
566 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
568 // Installs interceptors on the instance. 'desc' is a function template,
569 // and instance is an object instance created by the function of this
570 // function template.
571 MUST_USE_RESULT MaybeHandle<FunctionTemplateInfo> ConfigureInstance(
572 Handle<FunctionTemplateInfo> desc, Handle<JSObject> instance);
574 #define ROOT_ACCESSOR(type, name, camel_name) \
575 inline Handle<type> name() { \
576 return Handle<type>(BitCast<type**>( \
577 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
579 ROOT_LIST(ROOT_ACCESSOR)
582 #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
583 inline Handle<Map> name##_map() { \
584 return Handle<Map>(BitCast<Map**>( \
585 &isolate()->heap()->roots_[Heap::k##Name##MapRootIndex])); \
587 STRUCT_LIST(STRUCT_MAP_ACCESSOR)
588 #undef STRUCT_MAP_ACCESSOR
590 #define STRING_ACCESSOR(name, str) \
591 inline Handle<String> name() { \
592 return Handle<String>(BitCast<String**>( \
593 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
595 INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
596 #undef STRING_ACCESSOR
598 inline void set_string_table(Handle<StringTable> table) {
599 isolate()->heap()->set_string_table(*table);
602 Handle<String> hidden_string() {
603 return Handle<String>(&isolate()->heap()->hidden_string_);
606 // Allocates a new SharedFunctionInfo object.
607 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
608 Handle<String> name, int number_of_literals, bool is_generator,
609 bool is_arrow, Handle<Code> code, Handle<ScopeInfo> scope_info,
610 Handle<FixedArray> feedback_vector);
611 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name,
612 MaybeHandle<Code> code);
614 // Allocate a new type feedback vector
615 Handle<FixedArray> NewTypeFeedbackVector(int slot_count);
617 // Allocates a new JSMessageObject object.
618 Handle<JSMessageObject> NewJSMessageObject(
620 Handle<JSArray> arguments,
623 Handle<Object> script,
624 Handle<Object> stack_frames);
626 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
628 // Return a map using the map cache in the native context.
629 // The key the an ordered set of property names.
630 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
631 Handle<FixedArray> keys);
633 // Creates a new FixedArray that holds the data associated with the
634 // atom regexp and stores it in the regexp.
635 void SetRegExpAtomData(Handle<JSRegExp> regexp,
637 Handle<String> source,
638 JSRegExp::Flags flags,
639 Handle<Object> match_pattern);
641 // Creates a new FixedArray that holds the data associated with the
642 // irregexp regexp and stores it in the regexp.
643 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
645 Handle<String> source,
646 JSRegExp::Flags flags,
649 // Returns the value for a known global constant (a property of the global
650 // object which is neither configurable nor writable) like 'undefined'.
651 // Returns a null handle when the given name is unknown.
652 Handle<Object> GlobalConstantFor(Handle<String> name);
654 // Converts the given boolean condition to JavaScript boolean value.
655 Handle<Object> ToBoolean(bool value);
658 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
660 // Creates a heap object based on the map. The fields of the heap object are
661 // not initialized by New<>() functions. It's the responsibility of the caller
664 Handle<T> New(Handle<Map> map, AllocationSpace space);
667 Handle<T> New(Handle<Map> map,
668 AllocationSpace space,
669 Handle<AllocationSite> allocation_site);
671 // Creates a code object that is not yet fully initialized yet.
672 inline Handle<Code> NewCodeRaw(int object_size, bool immovable);
674 // Create a new map cache.
675 Handle<MapCache> NewMapCache(int at_least_space_for);
677 // Update the map cache in the native context with (keys, map)
678 Handle<MapCache> AddToMapCache(Handle<Context> context,
679 Handle<FixedArray> keys,
682 // Attempt to find the number in a small cache. If we finds it, return
683 // the string representation of the number. Otherwise return undefined.
684 Handle<Object> GetNumberStringCache(Handle<Object> number);
686 // Update the cache with a new number-string pair.
687 void SetNumberStringCache(Handle<Object> number, Handle<String> string);
689 // Initializes a function with a shared part and prototype.
690 // Note: this code was factored out of NewFunction such that other parts of
691 // the VM could use it. Specifically, a function that creates instances of
692 // type JS_FUNCTION_TYPE benefit from the use of this function.
693 inline void InitializeFunction(Handle<JSFunction> function,
694 Handle<SharedFunctionInfo> info,
695 Handle<Context> context);
697 // Creates a function initialized with a shared part.
698 Handle<JSFunction> NewFunction(Handle<Map> map,
699 Handle<SharedFunctionInfo> info,
700 Handle<Context> context,
701 PretenureFlag pretenure = TENURED);
703 Handle<JSFunction> NewFunction(Handle<Map> map,
705 MaybeHandle<Code> maybe_code);
708 } } // namespace v8::internal
710 #endif // V8_FACTORY_H_