blob: 0f028e5c5968e77a046d65a508fd5cfe10583468 [file] [log] [blame]
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001// Copyright 2011 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +00002// 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"
Steve Block44f0eee2011-05-26 01:26:41 +010032#include "handles.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000033#include "heap.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000034
35namespace v8 {
36namespace internal {
37
Steve Blocka7e24c12009-10-30 11:49:00 +000038// Interface for handle based allocation.
39
Steve Block44f0eee2011-05-26 01:26:41 +010040class Factory {
Steve Blocka7e24c12009-10-30 11:49:00 +000041 public:
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000042 // Allocate a new uninitialized fixed array.
Steve Block44f0eee2011-05-26 01:26:41 +010043 Handle<FixedArray> NewFixedArray(
Steve Blocka7e24c12009-10-30 11:49:00 +000044 int size,
45 PretenureFlag pretenure = NOT_TENURED);
46
47 // Allocate a new fixed array with non-existing entries (the hole).
Steve Block44f0eee2011-05-26 01:26:41 +010048 Handle<FixedArray> NewFixedArrayWithHoles(
Steve Block6ded16b2010-05-10 14:33:55 +010049 int size,
50 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +000051
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000052 // Allocate a new uninitialized fixed double array.
Ben Murdoch592a9fc2012-03-05 11:04:45 +000053 Handle<FixedDoubleArray> NewFixedDoubleArray(
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000054 int size,
55 PretenureFlag pretenure = NOT_TENURED);
56
Ben Murdoch592a9fc2012-03-05 11:04:45 +000057 Handle<NumberDictionary> NewNumberDictionary(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +000058
Steve Block44f0eee2011-05-26 01:26:41 +010059 Handle<StringDictionary> NewStringDictionary(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +000060
Ben Murdoch592a9fc2012-03-05 11:04:45 +000061 Handle<ObjectHashSet> NewObjectHashSet(int at_least_space_for);
62
Ben Murdoch69a99ed2011-11-30 16:03:39 +000063 Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for);
64
Steve Block44f0eee2011-05-26 01:26:41 +010065 Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors);
66 Handle<DeoptimizationInputData> NewDeoptimizationInputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010067 int deopt_entry_count,
68 PretenureFlag pretenure);
Steve Block44f0eee2011-05-26 01:26:41 +010069 Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010070 int deopt_entry_count,
71 PretenureFlag pretenure);
Steve Blocka7e24c12009-10-30 11:49:00 +000072
Steve Block44f0eee2011-05-26 01:26:41 +010073 Handle<String> LookupSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000074 Handle<String> LookupSymbol(Handle<String> str);
Steve Block44f0eee2011-05-26 01:26:41 +010075 Handle<String> LookupAsciiSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000076 Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>,
77 int from,
78 int length);
Steve Block44f0eee2011-05-26 01:26:41 +010079 Handle<String> LookupTwoByteSymbol(Vector<const uc16> str);
80 Handle<String> LookupAsciiSymbol(const char* str) {
Steve Blocka7e24c12009-10-30 11:49:00 +000081 return LookupSymbol(CStrVector(str));
82 }
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: ASCII 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 // - ...FromAscii initializes the string from a buffer that is ASCII
95 // encoded (it does not check that the buffer is ASCII encoded) and
96 // the result will be ASCII encoded.
97 // - ...FromUtf8 initializes the string from a buffer that is UTF-8
98 // encoded. If the characters are all single-byte characters, the
99 // result will be ASCII encoded, otherwise it will converted to two
100 // byte.
101 // - ...FromTwoByte initializes the string from a buffer that is two
102 // byte encoded. If the characters are all single-byte characters,
103 // the result will be converted to ASCII, otherwise it will be left as
104 // two byte.
105 //
106 // ASCII strings are pretenured when used as keys in the SourceCodeCache.
Steve Block44f0eee2011-05-26 01:26:41 +0100107 Handle<String> NewStringFromAscii(
Steve Blocka7e24c12009-10-30 11:49:00 +0000108 Vector<const char> str,
109 PretenureFlag pretenure = NOT_TENURED);
110
111 // UTF8 strings are pretenured when used for regexp literal patterns and
112 // flags in the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100113 Handle<String> NewStringFromUtf8(
Steve Blocka7e24c12009-10-30 11:49:00 +0000114 Vector<const char> str,
115 PretenureFlag pretenure = NOT_TENURED);
116
Steve Block44f0eee2011-05-26 01:26:41 +0100117 Handle<String> NewStringFromTwoByte(
Leon Clarkeac952652010-07-15 11:15:24 +0100118 Vector<const uc16> str,
Steve Blocka7e24c12009-10-30 11:49:00 +0000119 PretenureFlag pretenure = NOT_TENURED);
120
Leon Clarkeac952652010-07-15 11:15:24 +0100121 // Allocates and partially initializes an ASCII or TwoByte String. The
122 // characters of the string are uninitialized. Currently used in regexp code
123 // only, where they are pretenured.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000124 Handle<SeqAsciiString> NewRawAsciiString(
Leon Clarkeac952652010-07-15 11:15:24 +0100125 int length,
126 PretenureFlag pretenure = NOT_TENURED);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000127 Handle<SeqTwoByteString> NewRawTwoByteString(
Steve Blocka7e24c12009-10-30 11:49:00 +0000128 int length,
129 PretenureFlag pretenure = NOT_TENURED);
130
131 // Create a new cons string object which consists of a pair of strings.
Steve Block44f0eee2011-05-26 01:26:41 +0100132 Handle<String> NewConsString(Handle<String> first,
133 Handle<String> second);
Steve Blocka7e24c12009-10-30 11:49:00 +0000134
Steve Blockd0582a62009-12-15 09:54:21 +0000135 // Create a new string object which holds a substring of a string.
Steve Block44f0eee2011-05-26 01:26:41 +0100136 Handle<String> NewSubString(Handle<String> str,
137 int begin,
138 int end);
Steve Blocka7e24c12009-10-30 11:49:00 +0000139
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000140 // Create a new string object which holds a proper substring of a string.
141 Handle<String> NewProperSubString(Handle<String> str,
142 int begin,
143 int end);
144
Steve Blocka7e24c12009-10-30 11:49:00 +0000145 // Creates a new external String object. There are two String encodings
146 // in the system: ASCII and two byte. Unlike other String types, it does
147 // not make sense to have a UTF-8 factory function for external strings,
148 // because we cannot change the underlying buffer.
Steve Block44f0eee2011-05-26 01:26:41 +0100149 Handle<String> NewExternalStringFromAscii(
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000150 const ExternalAsciiString::Resource* resource);
Steve Block44f0eee2011-05-26 01:26:41 +0100151 Handle<String> NewExternalStringFromTwoByte(
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000152 const ExternalTwoByteString::Resource* resource);
Steve Blocka7e24c12009-10-30 11:49:00 +0000153
154 // Create a global (but otherwise uninitialized) context.
Steve Block44f0eee2011-05-26 01:26:41 +0100155 Handle<Context> NewGlobalContext();
Steve Blocka7e24c12009-10-30 11:49:00 +0000156
157 // Create a function context.
Steve Block44f0eee2011-05-26 01:26:41 +0100158 Handle<Context> NewFunctionContext(int length,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000159 Handle<JSFunction> function);
160
161 // Create a catch context.
162 Handle<Context> NewCatchContext(Handle<JSFunction> function,
163 Handle<Context> previous,
164 Handle<String> name,
165 Handle<Object> thrown_object);
Steve Blocka7e24c12009-10-30 11:49:00 +0000166
167 // Create a 'with' context.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000168 Handle<Context> NewWithContext(Handle<JSFunction> function,
169 Handle<Context> previous,
170 Handle<JSObject> extension);
Steve Blocka7e24c12009-10-30 11:49:00 +0000171
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000172 // Create a 'block' context.
173 Handle<Context> NewBlockContext(Handle<JSFunction> function,
174 Handle<Context> previous,
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000175 Handle<ScopeInfo> scope_info);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000176
Steve Blocka7e24c12009-10-30 11:49:00 +0000177 // Return the Symbol matching the passed in string.
Steve Block44f0eee2011-05-26 01:26:41 +0100178 Handle<String> SymbolFromString(Handle<String> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000179
180 // Allocate a new struct. The struct is pretenured (allocated directly in
181 // the old generation).
Steve Block44f0eee2011-05-26 01:26:41 +0100182 Handle<Struct> NewStruct(InstanceType type);
Steve Blocka7e24c12009-10-30 11:49:00 +0000183
Steve Block44f0eee2011-05-26 01:26:41 +0100184 Handle<AccessorInfo> NewAccessorInfo();
Steve Blocka7e24c12009-10-30 11:49:00 +0000185
Steve Block44f0eee2011-05-26 01:26:41 +0100186 Handle<Script> NewScript(Handle<String> source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000187
Ben Murdoch257744e2011-11-30 15:57:28 +0000188 // Foreign objects are pretenured when allocated by the bootstrapper.
189 Handle<Foreign> NewForeign(Address addr,
190 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000191
Ben Murdoch257744e2011-11-30 15:57:28 +0000192 // Allocate a new foreign object. The foreign is pretenured (allocated
193 // directly in the old generation).
194 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
Steve Blocka7e24c12009-10-30 11:49:00 +0000195
Steve Block44f0eee2011-05-26 01:26:41 +0100196 Handle<ByteArray> NewByteArray(int length,
197 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000198
Steve Block44f0eee2011-05-26 01:26:41 +0100199 Handle<ExternalArray> NewExternalArray(
Steve Block3ce2e202009-11-05 08:53:23 +0000200 int length,
201 ExternalArrayType array_type,
202 void* external_pointer,
203 PretenureFlag pretenure = NOT_TENURED);
204
Steve Block44f0eee2011-05-26 01:26:41 +0100205 Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
Ben Murdochb0fe1622011-05-05 13:52:32 +0100206 Handle<Object> value);
207
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000208 Handle<Map> NewMap(InstanceType type,
209 int instance_size,
210 ElementsKind elements_kind = FAST_ELEMENTS);
Steve Blocka7e24c12009-10-30 11:49:00 +0000211
Steve Block44f0eee2011-05-26 01:26:41 +0100212 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000213
Steve Block44f0eee2011-05-26 01:26:41 +0100214 Handle<Map> CopyMapDropDescriptors(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000215
216 // Copy the map adding more inobject properties if possible without
217 // overflowing the instance size.
Steve Block44f0eee2011-05-26 01:26:41 +0100218 Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
Steve Blocka7e24c12009-10-30 11:49:00 +0000219
Steve Block44f0eee2011-05-26 01:26:41 +0100220 Handle<Map> CopyMapDropTransitions(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000221
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000222 Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
223 ElementsKind elements_kind);
Steve Block1e0659c2011-05-24 12:43:12 +0100224
Steve Block44f0eee2011-05-26 01:26:41 +0100225 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
Steve Blocka7e24c12009-10-30 11:49:00 +0000226
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000227 Handle<FixedDoubleArray> CopyFixedDoubleArray(
228 Handle<FixedDoubleArray> array);
229
Steve Blocka7e24c12009-10-30 11:49:00 +0000230 // Numbers (eg, literals) are pretenured by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100231 Handle<Object> NewNumber(double value,
232 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000233
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000234 Handle<Object> NewNumberFromInt(int32_t value,
235 PretenureFlag pretenure = NOT_TENURED);
236 Handle<Object> NewNumberFromUint(uint32_t value,
237 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000238
239 // These objects are used by the api to create env-independent data
240 // structures in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100241 Handle<JSObject> NewNeanderObject();
Steve Blocka7e24c12009-10-30 11:49:00 +0000242
Steve Block44f0eee2011-05-26 01:26:41 +0100243 Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000244
245 // JS objects are pretenured when allocated by the bootstrapper and
246 // runtime.
Steve Block44f0eee2011-05-26 01:26:41 +0100247 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
248 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000249
250 // Global objects are pretenured.
Steve Block44f0eee2011-05-26 01:26:41 +0100251 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
Steve Blocka7e24c12009-10-30 11:49:00 +0000252
253 // JS objects are pretenured when allocated by the bootstrapper and
254 // runtime.
Steve Block44f0eee2011-05-26 01:26:41 +0100255 Handle<JSObject> NewJSObjectFromMap(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000256
257 // JS arrays are pretenured when allocated by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100258 Handle<JSArray> NewJSArray(int capacity,
259 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000260
Steve Block44f0eee2011-05-26 01:26:41 +0100261 Handle<JSArray> NewJSArrayWithElements(
Steve Blocka7e24c12009-10-30 11:49:00 +0000262 Handle<FixedArray> elements,
263 PretenureFlag pretenure = NOT_TENURED);
264
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000265 void SetContent(Handle<JSArray> array, Handle<FixedArray> elements);
266
267 void EnsureCanContainNonSmiElements(Handle<JSArray> array);
268
Ben Murdoch257744e2011-11-30 15:57:28 +0000269 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
270
Ben Murdoch589d6972011-11-30 16:04:58 +0000271 // Change the type of the argument into a JS object/function and reinitialize.
272 void BecomeJSObject(Handle<JSReceiver> object);
273 void BecomeJSFunction(Handle<JSReceiver> object);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000274
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000275 void SetIdentityHash(Handle<JSObject> object, Object* hash);
276
Steve Block44f0eee2011-05-26 01:26:41 +0100277 Handle<JSFunction> NewFunction(Handle<String> name,
278 Handle<Object> prototype);
Steve Blocka7e24c12009-10-30 11:49:00 +0000279
Steve Block44f0eee2011-05-26 01:26:41 +0100280 Handle<JSFunction> NewFunctionWithoutPrototype(
281 Handle<String> name,
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000282 LanguageMode language_mode);
Steve Block6ded16b2010-05-10 14:33:55 +0100283
Steve Block44f0eee2011-05-26 01:26:41 +0100284 Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
Steve Blocka7e24c12009-10-30 11:49:00 +0000285
Steve Block44f0eee2011-05-26 01:26:41 +0100286 Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100287 Handle<SharedFunctionInfo> function_info,
288 Handle<Map> function_map,
289 PretenureFlag pretenure);
290
Steve Block44f0eee2011-05-26 01:26:41 +0100291 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100292 Handle<SharedFunctionInfo> function_info,
Leon Clarkee46be812010-01-19 14:06:41 +0000293 Handle<Context> context,
294 PretenureFlag pretenure = TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000295
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000296 Handle<ScopeInfo> NewScopeInfo(int length);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000297
Steve Block44f0eee2011-05-26 01:26:41 +0100298 Handle<Code> NewCode(const CodeDesc& desc,
299 Code::Flags flags,
300 Handle<Object> self_reference,
301 bool immovable = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000302
Steve Block44f0eee2011-05-26 01:26:41 +0100303 Handle<Code> CopyCode(Handle<Code> code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000304
Steve Block44f0eee2011-05-26 01:26:41 +0100305 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
Steve Block6ded16b2010-05-10 14:33:55 +0100306
Steve Block44f0eee2011-05-26 01:26:41 +0100307 Handle<Object> ToObject(Handle<Object> object);
308 Handle<Object> ToObject(Handle<Object> object,
309 Handle<Context> global_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000310
311 // Interface for creating error objects.
312
Steve Block44f0eee2011-05-26 01:26:41 +0100313 Handle<Object> NewError(const char* maker, const char* type,
314 Handle<JSArray> args);
315 Handle<Object> NewError(const char* maker, const char* type,
316 Vector< Handle<Object> > args);
317 Handle<Object> NewError(const char* type,
318 Vector< Handle<Object> > args);
319 Handle<Object> NewError(Handle<String> message);
320 Handle<Object> NewError(const char* constructor,
321 Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000322
Steve Block44f0eee2011-05-26 01:26:41 +0100323 Handle<Object> NewTypeError(const char* type,
324 Vector< Handle<Object> > args);
325 Handle<Object> NewTypeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000326
Steve Block44f0eee2011-05-26 01:26:41 +0100327 Handle<Object> NewRangeError(const char* type,
328 Vector< Handle<Object> > args);
329 Handle<Object> NewRangeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000330
Steve Block44f0eee2011-05-26 01:26:41 +0100331 Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
332 Handle<Object> NewSyntaxError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000333
Steve Block44f0eee2011-05-26 01:26:41 +0100334 Handle<Object> NewReferenceError(const char* type,
335 Vector< Handle<Object> > args);
336 Handle<Object> NewReferenceError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000337
Steve Block44f0eee2011-05-26 01:26:41 +0100338 Handle<Object> NewEvalError(const char* type,
339 Vector< Handle<Object> > args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000340
341
Steve Block44f0eee2011-05-26 01:26:41 +0100342 Handle<JSFunction> NewFunction(Handle<String> name,
343 InstanceType type,
344 int instance_size,
345 Handle<Code> code,
346 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000347
Steve Block44f0eee2011-05-26 01:26:41 +0100348 Handle<JSFunction> NewFunction(Handle<Map> function_map,
Steve Blocka7e24c12009-10-30 11:49:00 +0000349 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
350
351
Steve Block44f0eee2011-05-26 01:26:41 +0100352 Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
353 InstanceType type,
354 int instance_size,
355 Handle<JSObject> prototype,
356 Handle<Code> code,
357 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000358
Steve Block44f0eee2011-05-26 01:26:41 +0100359 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
360 Handle<Code> code);
Steve Block6ded16b2010-05-10 14:33:55 +0100361
Ben Murdoch257744e2011-11-30 15:57:28 +0000362 Handle<DescriptorArray> CopyAppendForeignDescriptor(
Steve Blocka7e24c12009-10-30 11:49:00 +0000363 Handle<DescriptorArray> array,
364 Handle<String> key,
365 Handle<Object> value,
366 PropertyAttributes attributes);
367
Steve Block44f0eee2011-05-26 01:26:41 +0100368 Handle<String> NumberToString(Handle<Object> number);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000369 Handle<String> Uint32ToString(uint32_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000370
371 enum ApiInstanceType {
372 JavaScriptObject,
373 InnerGlobalObject,
374 OuterGlobalObject
375 };
376
Steve Block44f0eee2011-05-26 01:26:41 +0100377 Handle<JSFunction> CreateApiFunction(
Steve Blocka7e24c12009-10-30 11:49:00 +0000378 Handle<FunctionTemplateInfo> data,
379 ApiInstanceType type = JavaScriptObject);
380
Steve Block44f0eee2011-05-26 01:26:41 +0100381 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000382
383 // Installs interceptors on the instance. 'desc' is a function template,
384 // and instance is an object instance created by the function of this
385 // function template.
Steve Block44f0eee2011-05-26 01:26:41 +0100386 void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
387 Handle<JSObject> instance,
388 bool* pending_exception);
Steve Blocka7e24c12009-10-30 11:49:00 +0000389
390#define ROOT_ACCESSOR(type, name, camel_name) \
Steve Block44f0eee2011-05-26 01:26:41 +0100391 inline Handle<type> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100392 return Handle<type>(BitCast<type**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100393 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000394 }
395 ROOT_LIST(ROOT_ACCESSOR)
396#undef ROOT_ACCESSOR_ACCESSOR
397
Steve Block44f0eee2011-05-26 01:26:41 +0100398#define SYMBOL_ACCESSOR(name, str) \
399 inline Handle<String> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100400 return Handle<String>(BitCast<String**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100401 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000402 }
403 SYMBOL_LIST(SYMBOL_ACCESSOR)
404#undef SYMBOL_ACCESSOR
405
Steve Block44f0eee2011-05-26 01:26:41 +0100406 Handle<String> hidden_symbol() {
407 return Handle<String>(&isolate()->heap()->hidden_symbol_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000408 }
409
Steve Block44f0eee2011-05-26 01:26:41 +0100410 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100411 Handle<String> name,
412 int number_of_literals,
413 Handle<Code> code,
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000414 Handle<ScopeInfo> scope_info);
Steve Block44f0eee2011-05-26 01:26:41 +0100415 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000416
Steve Block44f0eee2011-05-26 01:26:41 +0100417 Handle<JSMessageObject> NewJSMessageObject(
Steve Block1e0659c2011-05-24 12:43:12 +0100418 Handle<String> type,
419 Handle<JSArray> arguments,
420 int start_position,
421 int end_position,
422 Handle<Object> script,
423 Handle<Object> stack_trace,
424 Handle<Object> stack_frames);
425
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000426 Handle<NumberDictionary> DictionaryAtNumberPut(
427 Handle<NumberDictionary>,
Steve Blocka7e24c12009-10-30 11:49:00 +0000428 uint32_t key,
429 Handle<Object> value);
430
431#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100432 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000433#endif
434
435 // Return a map using the map cache in the global context.
436 // The key the an ordered set of property names.
Steve Block44f0eee2011-05-26 01:26:41 +0100437 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
438 Handle<FixedArray> keys);
Steve Blocka7e24c12009-10-30 11:49:00 +0000439
440 // Creates a new FixedArray that holds the data associated with the
441 // atom regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100442 void SetRegExpAtomData(Handle<JSRegExp> regexp,
443 JSRegExp::Type type,
444 Handle<String> source,
445 JSRegExp::Flags flags,
446 Handle<Object> match_pattern);
Steve Blocka7e24c12009-10-30 11:49:00 +0000447
448 // Creates a new FixedArray that holds the data associated with the
449 // irregexp regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100450 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
451 JSRegExp::Type type,
452 Handle<String> source,
453 JSRegExp::Flags flags,
454 int capture_count);
Steve Blocka7e24c12009-10-30 11:49:00 +0000455
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000456 // Returns the value for a known global constant (a property of the global
457 // object which is neither configurable nor writable) like 'undefined'.
458 // Returns a null handle when the given name is unknown.
459 Handle<Object> GlobalConstantFor(Handle<String> name);
460
461 // Converts the given boolean condition to JavaScript boolean value.
462 Handle<Object> ToBoolean(bool value);
463
Steve Blocka7e24c12009-10-30 11:49:00 +0000464 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100465 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000466
Steve Block44f0eee2011-05-26 01:26:41 +0100467 Handle<JSFunction> NewFunctionHelper(Handle<String> name,
468 Handle<Object> prototype);
Steve Block6ded16b2010-05-10 14:33:55 +0100469
Steve Block44f0eee2011-05-26 01:26:41 +0100470 Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
471 Handle<String> name,
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000472 LanguageMode language_mode);
Steve Block44f0eee2011-05-26 01:26:41 +0100473
474 Handle<DescriptorArray> CopyAppendCallbackDescriptors(
Steve Blocka7e24c12009-10-30 11:49:00 +0000475 Handle<DescriptorArray> array,
476 Handle<Object> descriptors);
477
Steve Blocka7e24c12009-10-30 11:49:00 +0000478 // Create a new map cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100479 Handle<MapCache> NewMapCache(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +0000480
481 // Update the map cache in the global context with (keys, map)
Steve Block44f0eee2011-05-26 01:26:41 +0100482 Handle<MapCache> AddToMapCache(Handle<Context> context,
483 Handle<FixedArray> keys,
484 Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000485};
486
487
488} } // namespace v8::internal
489
490#endif // V8_FACTORY_H_