blob: a69b05b38f00fc385b665bba6eea1ea039b3fb24 [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.
53 Handle<FixedArray> NewFixedDoubleArray(
54 int size,
55 PretenureFlag pretenure = NOT_TENURED);
56
Steve Block44f0eee2011-05-26 01:26:41 +010057 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 Murdoch69a99ed2011-11-30 16:03:39 +000061 Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for);
62
Steve Block44f0eee2011-05-26 01:26:41 +010063 Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors);
64 Handle<DeoptimizationInputData> NewDeoptimizationInputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010065 int deopt_entry_count,
66 PretenureFlag pretenure);
Steve Block44f0eee2011-05-26 01:26:41 +010067 Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010068 int deopt_entry_count,
69 PretenureFlag pretenure);
Steve Blocka7e24c12009-10-30 11:49:00 +000070
Steve Block44f0eee2011-05-26 01:26:41 +010071 Handle<String> LookupSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000072 Handle<String> LookupSymbol(Handle<String> str);
Steve Block44f0eee2011-05-26 01:26:41 +010073 Handle<String> LookupAsciiSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000074 Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>,
75 int from,
76 int length);
Steve Block44f0eee2011-05-26 01:26:41 +010077 Handle<String> LookupTwoByteSymbol(Vector<const uc16> str);
78 Handle<String> LookupAsciiSymbol(const char* str) {
Steve Blocka7e24c12009-10-30 11:49:00 +000079 return LookupSymbol(CStrVector(str));
80 }
81
82
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
86 // DONT_TENURE.
87 //
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
91 // initialized from.
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
98 // byte.
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
102 // two byte.
103 //
104 // ASCII strings are pretenured when used as keys in the SourceCodeCache.
Steve Block44f0eee2011-05-26 01:26:41 +0100105 Handle<String> NewStringFromAscii(
Steve Blocka7e24c12009-10-30 11:49:00 +0000106 Vector<const char> str,
107 PretenureFlag pretenure = NOT_TENURED);
108
109 // UTF8 strings are pretenured when used for regexp literal patterns and
110 // flags in the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100111 Handle<String> NewStringFromUtf8(
Steve Blocka7e24c12009-10-30 11:49:00 +0000112 Vector<const char> str,
113 PretenureFlag pretenure = NOT_TENURED);
114
Steve Block44f0eee2011-05-26 01:26:41 +0100115 Handle<String> NewStringFromTwoByte(
Leon Clarkeac952652010-07-15 11:15:24 +0100116 Vector<const uc16> str,
Steve Blocka7e24c12009-10-30 11:49:00 +0000117 PretenureFlag pretenure = NOT_TENURED);
118
Leon Clarkeac952652010-07-15 11:15:24 +0100119 // Allocates and partially initializes an ASCII or TwoByte String. The
120 // characters of the string are uninitialized. Currently used in regexp code
121 // only, where they are pretenured.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000122 Handle<SeqAsciiString> NewRawAsciiString(
Leon Clarkeac952652010-07-15 11:15:24 +0100123 int length,
124 PretenureFlag pretenure = NOT_TENURED);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000125 Handle<SeqTwoByteString> NewRawTwoByteString(
Steve Blocka7e24c12009-10-30 11:49:00 +0000126 int length,
127 PretenureFlag pretenure = NOT_TENURED);
128
129 // Create a new cons string object which consists of a pair of strings.
Steve Block44f0eee2011-05-26 01:26:41 +0100130 Handle<String> NewConsString(Handle<String> first,
131 Handle<String> second);
Steve Blocka7e24c12009-10-30 11:49:00 +0000132
Steve Blockd0582a62009-12-15 09:54:21 +0000133 // Create a new string object which holds a substring of a string.
Steve Block44f0eee2011-05-26 01:26:41 +0100134 Handle<String> NewSubString(Handle<String> str,
135 int begin,
136 int end);
Steve Blocka7e24c12009-10-30 11:49:00 +0000137
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000138 // Create a new string object which holds a proper substring of a string.
139 Handle<String> NewProperSubString(Handle<String> str,
140 int begin,
141 int end);
142
Steve Blocka7e24c12009-10-30 11:49:00 +0000143 // Creates a new external String object. There are two String encodings
144 // in the system: ASCII and two byte. Unlike other String types, it does
145 // not make sense to have a UTF-8 factory function for external strings,
146 // because we cannot change the underlying buffer.
Steve Block44f0eee2011-05-26 01:26:41 +0100147 Handle<String> NewExternalStringFromAscii(
Steve Blocka7e24c12009-10-30 11:49:00 +0000148 ExternalAsciiString::Resource* resource);
Steve Block44f0eee2011-05-26 01:26:41 +0100149 Handle<String> NewExternalStringFromTwoByte(
Steve Blocka7e24c12009-10-30 11:49:00 +0000150 ExternalTwoByteString::Resource* resource);
151
152 // Create a global (but otherwise uninitialized) context.
Steve Block44f0eee2011-05-26 01:26:41 +0100153 Handle<Context> NewGlobalContext();
Steve Blocka7e24c12009-10-30 11:49:00 +0000154
155 // Create a function context.
Steve Block44f0eee2011-05-26 01:26:41 +0100156 Handle<Context> NewFunctionContext(int length,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000157 Handle<JSFunction> function);
158
159 // Create a catch context.
160 Handle<Context> NewCatchContext(Handle<JSFunction> function,
161 Handle<Context> previous,
162 Handle<String> name,
163 Handle<Object> thrown_object);
Steve Blocka7e24c12009-10-30 11:49:00 +0000164
165 // Create a 'with' context.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000166 Handle<Context> NewWithContext(Handle<JSFunction> function,
167 Handle<Context> previous,
168 Handle<JSObject> extension);
Steve Blocka7e24c12009-10-30 11:49:00 +0000169
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000170 // Create a 'block' context.
171 Handle<Context> NewBlockContext(Handle<JSFunction> function,
172 Handle<Context> previous,
173 Handle<SerializedScopeInfo> scope_info);
174
Steve Blocka7e24c12009-10-30 11:49:00 +0000175 // Return the Symbol matching the passed in string.
Steve Block44f0eee2011-05-26 01:26:41 +0100176 Handle<String> SymbolFromString(Handle<String> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000177
178 // Allocate a new struct. The struct is pretenured (allocated directly in
179 // the old generation).
Steve Block44f0eee2011-05-26 01:26:41 +0100180 Handle<Struct> NewStruct(InstanceType type);
Steve Blocka7e24c12009-10-30 11:49:00 +0000181
Steve Block44f0eee2011-05-26 01:26:41 +0100182 Handle<AccessorInfo> NewAccessorInfo();
Steve Blocka7e24c12009-10-30 11:49:00 +0000183
Steve Block44f0eee2011-05-26 01:26:41 +0100184 Handle<Script> NewScript(Handle<String> source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000185
Ben Murdoch257744e2011-11-30 15:57:28 +0000186 // Foreign objects are pretenured when allocated by the bootstrapper.
187 Handle<Foreign> NewForeign(Address addr,
188 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000189
Ben Murdoch257744e2011-11-30 15:57:28 +0000190 // Allocate a new foreign object. The foreign is pretenured (allocated
191 // directly in the old generation).
192 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
Steve Blocka7e24c12009-10-30 11:49:00 +0000193
Steve Block44f0eee2011-05-26 01:26:41 +0100194 Handle<ByteArray> NewByteArray(int length,
195 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000196
Steve Block44f0eee2011-05-26 01:26:41 +0100197 Handle<ExternalArray> NewExternalArray(
Steve Block3ce2e202009-11-05 08:53:23 +0000198 int length,
199 ExternalArrayType array_type,
200 void* external_pointer,
201 PretenureFlag pretenure = NOT_TENURED);
202
Steve Block44f0eee2011-05-26 01:26:41 +0100203 Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
Ben Murdochb0fe1622011-05-05 13:52:32 +0100204 Handle<Object> value);
205
Steve Block44f0eee2011-05-26 01:26:41 +0100206 Handle<Map> NewMap(InstanceType type, int instance_size);
Steve Blocka7e24c12009-10-30 11:49:00 +0000207
Steve Block44f0eee2011-05-26 01:26:41 +0100208 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000209
Steve Block44f0eee2011-05-26 01:26:41 +0100210 Handle<Map> CopyMapDropDescriptors(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000211
212 // Copy the map adding more inobject properties if possible without
213 // overflowing the instance size.
Steve Block44f0eee2011-05-26 01:26:41 +0100214 Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
Steve Blocka7e24c12009-10-30 11:49:00 +0000215
Steve Block44f0eee2011-05-26 01:26:41 +0100216 Handle<Map> CopyMapDropTransitions(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000217
Steve Block44f0eee2011-05-26 01:26:41 +0100218 Handle<Map> GetFastElementsMap(Handle<Map> map);
Steve Block8defd9f2010-07-08 12:39:36 +0100219
Steve Block44f0eee2011-05-26 01:26:41 +0100220 Handle<Map> GetSlowElementsMap(Handle<Map> map);
Steve Block8defd9f2010-07-08 12:39:36 +0100221
Steve Block44f0eee2011-05-26 01:26:41 +0100222 Handle<Map> GetExternalArrayElementsMap(Handle<Map> map,
223 ExternalArrayType array_type,
224 bool safe_to_add_transition);
Steve Block1e0659c2011-05-24 12:43:12 +0100225
Steve Block44f0eee2011-05-26 01:26:41 +0100226 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
Steve Blocka7e24c12009-10-30 11:49:00 +0000227
228 // Numbers (eg, literals) are pretenured by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100229 Handle<Object> NewNumber(double value,
230 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000231
Steve Block44f0eee2011-05-26 01:26:41 +0100232 Handle<Object> NewNumberFromInt(int value);
233 Handle<Object> NewNumberFromUint(uint32_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000234
235 // These objects are used by the api to create env-independent data
236 // structures in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100237 Handle<JSObject> NewNeanderObject();
Steve Blocka7e24c12009-10-30 11:49:00 +0000238
Steve Block44f0eee2011-05-26 01:26:41 +0100239 Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000240
241 // JS objects are pretenured when allocated by the bootstrapper and
242 // runtime.
Steve Block44f0eee2011-05-26 01:26:41 +0100243 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
244 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000245
246 // Global objects are pretenured.
Steve Block44f0eee2011-05-26 01:26:41 +0100247 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
Steve Blocka7e24c12009-10-30 11:49:00 +0000248
249 // JS objects are pretenured when allocated by the bootstrapper and
250 // runtime.
Steve Block44f0eee2011-05-26 01:26:41 +0100251 Handle<JSObject> NewJSObjectFromMap(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000252
253 // JS arrays are pretenured when allocated by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100254 Handle<JSArray> NewJSArray(int capacity,
255 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000256
Steve Block44f0eee2011-05-26 01:26:41 +0100257 Handle<JSArray> NewJSArrayWithElements(
Steve Blocka7e24c12009-10-30 11:49:00 +0000258 Handle<FixedArray> elements,
259 PretenureFlag pretenure = NOT_TENURED);
260
Ben Murdoch257744e2011-11-30 15:57:28 +0000261 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
262
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000263 // Change the type of the argument into a regular JS object and reinitialize.
264 void BecomeJSObject(Handle<JSProxy> object);
265
Steve Block44f0eee2011-05-26 01:26:41 +0100266 Handle<JSFunction> NewFunction(Handle<String> name,
267 Handle<Object> prototype);
Steve Blocka7e24c12009-10-30 11:49:00 +0000268
Steve Block44f0eee2011-05-26 01:26:41 +0100269 Handle<JSFunction> NewFunctionWithoutPrototype(
270 Handle<String> name,
271 StrictModeFlag strict_mode);
Steve Block6ded16b2010-05-10 14:33:55 +0100272
Steve Block44f0eee2011-05-26 01:26:41 +0100273 Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
Steve Blocka7e24c12009-10-30 11:49:00 +0000274
Steve Block44f0eee2011-05-26 01:26:41 +0100275 Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100276 Handle<SharedFunctionInfo> function_info,
277 Handle<Map> function_map,
278 PretenureFlag pretenure);
279
Steve Block44f0eee2011-05-26 01:26:41 +0100280 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100281 Handle<SharedFunctionInfo> function_info,
Leon Clarkee46be812010-01-19 14:06:41 +0000282 Handle<Context> context,
283 PretenureFlag pretenure = TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000284
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000285 Handle<SerializedScopeInfo> NewSerializedScopeInfo(int length);
286
Steve Block44f0eee2011-05-26 01:26:41 +0100287 Handle<Code> NewCode(const CodeDesc& desc,
288 Code::Flags flags,
289 Handle<Object> self_reference,
290 bool immovable = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000291
Steve Block44f0eee2011-05-26 01:26:41 +0100292 Handle<Code> CopyCode(Handle<Code> code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000293
Steve Block44f0eee2011-05-26 01:26:41 +0100294 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
Steve Block6ded16b2010-05-10 14:33:55 +0100295
Steve Block44f0eee2011-05-26 01:26:41 +0100296 Handle<Object> ToObject(Handle<Object> object);
297 Handle<Object> ToObject(Handle<Object> object,
298 Handle<Context> global_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000299
300 // Interface for creating error objects.
301
Steve Block44f0eee2011-05-26 01:26:41 +0100302 Handle<Object> NewError(const char* maker, const char* type,
303 Handle<JSArray> args);
304 Handle<Object> NewError(const char* maker, const char* type,
305 Vector< Handle<Object> > args);
306 Handle<Object> NewError(const char* type,
307 Vector< Handle<Object> > args);
308 Handle<Object> NewError(Handle<String> message);
309 Handle<Object> NewError(const char* constructor,
310 Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000311
Steve Block44f0eee2011-05-26 01:26:41 +0100312 Handle<Object> NewTypeError(const char* type,
313 Vector< Handle<Object> > args);
314 Handle<Object> NewTypeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000315
Steve Block44f0eee2011-05-26 01:26:41 +0100316 Handle<Object> NewRangeError(const char* type,
317 Vector< Handle<Object> > args);
318 Handle<Object> NewRangeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000319
Steve Block44f0eee2011-05-26 01:26:41 +0100320 Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
321 Handle<Object> NewSyntaxError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000322
Steve Block44f0eee2011-05-26 01:26:41 +0100323 Handle<Object> NewReferenceError(const char* type,
324 Vector< Handle<Object> > args);
325 Handle<Object> NewReferenceError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000326
Steve Block44f0eee2011-05-26 01:26:41 +0100327 Handle<Object> NewEvalError(const char* type,
328 Vector< Handle<Object> > args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000329
330
Steve Block44f0eee2011-05-26 01:26:41 +0100331 Handle<JSFunction> NewFunction(Handle<String> name,
332 InstanceType type,
333 int instance_size,
334 Handle<Code> code,
335 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000336
Steve Block44f0eee2011-05-26 01:26:41 +0100337 Handle<JSFunction> NewFunction(Handle<Map> function_map,
Steve Blocka7e24c12009-10-30 11:49:00 +0000338 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
339
340
Steve Block44f0eee2011-05-26 01:26:41 +0100341 Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
342 InstanceType type,
343 int instance_size,
344 Handle<JSObject> prototype,
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> NewFunctionWithoutPrototype(Handle<String> name,
349 Handle<Code> code);
Steve Block6ded16b2010-05-10 14:33:55 +0100350
Ben Murdoch257744e2011-11-30 15:57:28 +0000351 Handle<DescriptorArray> CopyAppendForeignDescriptor(
Steve Blocka7e24c12009-10-30 11:49:00 +0000352 Handle<DescriptorArray> array,
353 Handle<String> key,
354 Handle<Object> value,
355 PropertyAttributes attributes);
356
Steve Block44f0eee2011-05-26 01:26:41 +0100357 Handle<String> NumberToString(Handle<Object> number);
Steve Blocka7e24c12009-10-30 11:49:00 +0000358
359 enum ApiInstanceType {
360 JavaScriptObject,
361 InnerGlobalObject,
362 OuterGlobalObject
363 };
364
Steve Block44f0eee2011-05-26 01:26:41 +0100365 Handle<JSFunction> CreateApiFunction(
Steve Blocka7e24c12009-10-30 11:49:00 +0000366 Handle<FunctionTemplateInfo> data,
367 ApiInstanceType type = JavaScriptObject);
368
Steve Block44f0eee2011-05-26 01:26:41 +0100369 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000370
371 // Installs interceptors on the instance. 'desc' is a function template,
372 // and instance is an object instance created by the function of this
373 // function template.
Steve Block44f0eee2011-05-26 01:26:41 +0100374 void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
375 Handle<JSObject> instance,
376 bool* pending_exception);
Steve Blocka7e24c12009-10-30 11:49:00 +0000377
378#define ROOT_ACCESSOR(type, name, camel_name) \
Steve Block44f0eee2011-05-26 01:26:41 +0100379 inline Handle<type> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100380 return Handle<type>(BitCast<type**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100381 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000382 }
383 ROOT_LIST(ROOT_ACCESSOR)
384#undef ROOT_ACCESSOR_ACCESSOR
385
Steve Block44f0eee2011-05-26 01:26:41 +0100386#define SYMBOL_ACCESSOR(name, str) \
387 inline Handle<String> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100388 return Handle<String>(BitCast<String**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100389 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000390 }
391 SYMBOL_LIST(SYMBOL_ACCESSOR)
392#undef SYMBOL_ACCESSOR
393
Steve Block44f0eee2011-05-26 01:26:41 +0100394 Handle<String> hidden_symbol() {
395 return Handle<String>(&isolate()->heap()->hidden_symbol_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000396 }
397
Steve Block44f0eee2011-05-26 01:26:41 +0100398 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100399 Handle<String> name,
400 int number_of_literals,
401 Handle<Code> code,
402 Handle<SerializedScopeInfo> scope_info);
Steve Block44f0eee2011-05-26 01:26:41 +0100403 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000404
Steve Block44f0eee2011-05-26 01:26:41 +0100405 Handle<JSMessageObject> NewJSMessageObject(
Steve Block1e0659c2011-05-24 12:43:12 +0100406 Handle<String> type,
407 Handle<JSArray> arguments,
408 int start_position,
409 int end_position,
410 Handle<Object> script,
411 Handle<Object> stack_trace,
412 Handle<Object> stack_frames);
413
Steve Block44f0eee2011-05-26 01:26:41 +0100414 Handle<NumberDictionary> DictionaryAtNumberPut(
Steve Blocka7e24c12009-10-30 11:49:00 +0000415 Handle<NumberDictionary>,
416 uint32_t key,
417 Handle<Object> value);
418
419#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100420 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000421#endif
422
423 // Return a map using the map cache in the global context.
424 // The key the an ordered set of property names.
Steve Block44f0eee2011-05-26 01:26:41 +0100425 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
426 Handle<FixedArray> keys);
Steve Blocka7e24c12009-10-30 11:49:00 +0000427
428 // Creates a new FixedArray that holds the data associated with the
429 // atom regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100430 void SetRegExpAtomData(Handle<JSRegExp> regexp,
431 JSRegExp::Type type,
432 Handle<String> source,
433 JSRegExp::Flags flags,
434 Handle<Object> match_pattern);
Steve Blocka7e24c12009-10-30 11:49:00 +0000435
436 // Creates a new FixedArray that holds the data associated with the
437 // irregexp regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100438 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
439 JSRegExp::Type type,
440 Handle<String> source,
441 JSRegExp::Flags flags,
442 int capture_count);
Steve Blocka7e24c12009-10-30 11:49:00 +0000443
444 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100445 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000446
Steve Block44f0eee2011-05-26 01:26:41 +0100447 Handle<JSFunction> NewFunctionHelper(Handle<String> name,
448 Handle<Object> prototype);
Steve Block6ded16b2010-05-10 14:33:55 +0100449
Steve Block44f0eee2011-05-26 01:26:41 +0100450 Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
451 Handle<String> name,
452 StrictModeFlag strict_mode);
453
454 Handle<DescriptorArray> CopyAppendCallbackDescriptors(
Steve Blocka7e24c12009-10-30 11:49:00 +0000455 Handle<DescriptorArray> array,
456 Handle<Object> descriptors);
457
Steve Blocka7e24c12009-10-30 11:49:00 +0000458 // Create a new map cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100459 Handle<MapCache> NewMapCache(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +0000460
461 // Update the map cache in the global context with (keys, map)
Steve Block44f0eee2011-05-26 01:26:41 +0100462 Handle<MapCache> AddToMapCache(Handle<Context> context,
463 Handle<FixedArray> keys,
464 Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000465};
466
467
468} } // namespace v8::internal
469
470#endif // V8_FACTORY_H_