blob: 19f3827931fc6fe7be5ada6167bbf01618dc5f37 [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
Steve Block44f0eee2011-05-26 01:26:41 +010061 Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors);
62 Handle<DeoptimizationInputData> NewDeoptimizationInputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010063 int deopt_entry_count,
64 PretenureFlag pretenure);
Steve Block44f0eee2011-05-26 01:26:41 +010065 Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010066 int deopt_entry_count,
67 PretenureFlag pretenure);
Steve Blocka7e24c12009-10-30 11:49:00 +000068
Steve Block44f0eee2011-05-26 01:26:41 +010069 Handle<String> LookupSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000070 Handle<String> LookupSymbol(Handle<String> str);
Steve Block44f0eee2011-05-26 01:26:41 +010071 Handle<String> LookupAsciiSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000072 Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>,
73 int from,
74 int length);
Steve Block44f0eee2011-05-26 01:26:41 +010075 Handle<String> LookupTwoByteSymbol(Vector<const uc16> str);
76 Handle<String> LookupAsciiSymbol(const char* str) {
Steve Blocka7e24c12009-10-30 11:49:00 +000077 return LookupSymbol(CStrVector(str));
78 }
79
80
81 // String creation functions. Most of the string creation functions take
82 // a Heap::PretenureFlag argument to optionally request that they be
83 // allocated in the old generation. The pretenure flag defaults to
84 // DONT_TENURE.
85 //
86 // Creates a new String object. There are two String encodings: ASCII and
87 // two byte. One should choose between the three string factory functions
88 // based on the encoding of the string buffer that the string is
89 // initialized from.
90 // - ...FromAscii initializes the string from a buffer that is ASCII
91 // encoded (it does not check that the buffer is ASCII encoded) and
92 // the result will be ASCII encoded.
93 // - ...FromUtf8 initializes the string from a buffer that is UTF-8
94 // encoded. If the characters are all single-byte characters, the
95 // result will be ASCII encoded, otherwise it will converted to two
96 // byte.
97 // - ...FromTwoByte initializes the string from a buffer that is two
98 // byte encoded. If the characters are all single-byte characters,
99 // the result will be converted to ASCII, otherwise it will be left as
100 // two byte.
101 //
102 // ASCII strings are pretenured when used as keys in the SourceCodeCache.
Steve Block44f0eee2011-05-26 01:26:41 +0100103 Handle<String> NewStringFromAscii(
Steve Blocka7e24c12009-10-30 11:49:00 +0000104 Vector<const char> str,
105 PretenureFlag pretenure = NOT_TENURED);
106
107 // UTF8 strings are pretenured when used for regexp literal patterns and
108 // flags in the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100109 Handle<String> NewStringFromUtf8(
Steve Blocka7e24c12009-10-30 11:49:00 +0000110 Vector<const char> str,
111 PretenureFlag pretenure = NOT_TENURED);
112
Steve Block44f0eee2011-05-26 01:26:41 +0100113 Handle<String> NewStringFromTwoByte(
Leon Clarkeac952652010-07-15 11:15:24 +0100114 Vector<const uc16> str,
Steve Blocka7e24c12009-10-30 11:49:00 +0000115 PretenureFlag pretenure = NOT_TENURED);
116
Leon Clarkeac952652010-07-15 11:15:24 +0100117 // Allocates and partially initializes an ASCII or TwoByte String. The
118 // characters of the string are uninitialized. Currently used in regexp code
119 // only, where they are pretenured.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000120 Handle<SeqAsciiString> NewRawAsciiString(
Leon Clarkeac952652010-07-15 11:15:24 +0100121 int length,
122 PretenureFlag pretenure = NOT_TENURED);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000123 Handle<SeqTwoByteString> NewRawTwoByteString(
Steve Blocka7e24c12009-10-30 11:49:00 +0000124 int length,
125 PretenureFlag pretenure = NOT_TENURED);
126
127 // Create a new cons string object which consists of a pair of strings.
Steve Block44f0eee2011-05-26 01:26:41 +0100128 Handle<String> NewConsString(Handle<String> first,
129 Handle<String> second);
Steve Blocka7e24c12009-10-30 11:49:00 +0000130
Steve Blockd0582a62009-12-15 09:54:21 +0000131 // Create a new string object which holds a substring of a string.
Steve Block44f0eee2011-05-26 01:26:41 +0100132 Handle<String> NewSubString(Handle<String> str,
133 int begin,
134 int end);
Steve Blocka7e24c12009-10-30 11:49:00 +0000135
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000136 // Create a new string object which holds a proper substring of a string.
137 Handle<String> NewProperSubString(Handle<String> str,
138 int begin,
139 int end);
140
Steve Blocka7e24c12009-10-30 11:49:00 +0000141 // Creates a new external String object. There are two String encodings
142 // in the system: ASCII and two byte. Unlike other String types, it does
143 // not make sense to have a UTF-8 factory function for external strings,
144 // because we cannot change the underlying buffer.
Steve Block44f0eee2011-05-26 01:26:41 +0100145 Handle<String> NewExternalStringFromAscii(
Steve Blocka7e24c12009-10-30 11:49:00 +0000146 ExternalAsciiString::Resource* resource);
Steve Block44f0eee2011-05-26 01:26:41 +0100147 Handle<String> NewExternalStringFromTwoByte(
Steve Blocka7e24c12009-10-30 11:49:00 +0000148 ExternalTwoByteString::Resource* resource);
149
150 // Create a global (but otherwise uninitialized) context.
Steve Block44f0eee2011-05-26 01:26:41 +0100151 Handle<Context> NewGlobalContext();
Steve Blocka7e24c12009-10-30 11:49:00 +0000152
153 // Create a function context.
Steve Block44f0eee2011-05-26 01:26:41 +0100154 Handle<Context> NewFunctionContext(int length,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000155 Handle<JSFunction> function);
156
157 // Create a catch context.
158 Handle<Context> NewCatchContext(Handle<JSFunction> function,
159 Handle<Context> previous,
160 Handle<String> name,
161 Handle<Object> thrown_object);
Steve Blocka7e24c12009-10-30 11:49:00 +0000162
163 // Create a 'with' context.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000164 Handle<Context> NewWithContext(Handle<JSFunction> function,
165 Handle<Context> previous,
166 Handle<JSObject> extension);
Steve Blocka7e24c12009-10-30 11:49:00 +0000167
168 // Return the Symbol matching the passed in string.
Steve Block44f0eee2011-05-26 01:26:41 +0100169 Handle<String> SymbolFromString(Handle<String> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000170
171 // Allocate a new struct. The struct is pretenured (allocated directly in
172 // the old generation).
Steve Block44f0eee2011-05-26 01:26:41 +0100173 Handle<Struct> NewStruct(InstanceType type);
Steve Blocka7e24c12009-10-30 11:49:00 +0000174
Steve Block44f0eee2011-05-26 01:26:41 +0100175 Handle<AccessorInfo> NewAccessorInfo();
Steve Blocka7e24c12009-10-30 11:49:00 +0000176
Steve Block44f0eee2011-05-26 01:26:41 +0100177 Handle<Script> NewScript(Handle<String> source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000178
Ben Murdoch257744e2011-11-30 15:57:28 +0000179 // Foreign objects are pretenured when allocated by the bootstrapper.
180 Handle<Foreign> NewForeign(Address addr,
181 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000182
Ben Murdoch257744e2011-11-30 15:57:28 +0000183 // Allocate a new foreign object. The foreign is pretenured (allocated
184 // directly in the old generation).
185 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
Steve Blocka7e24c12009-10-30 11:49:00 +0000186
Steve Block44f0eee2011-05-26 01:26:41 +0100187 Handle<ByteArray> NewByteArray(int length,
188 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000189
Steve Block44f0eee2011-05-26 01:26:41 +0100190 Handle<ExternalArray> NewExternalArray(
Steve Block3ce2e202009-11-05 08:53:23 +0000191 int length,
192 ExternalArrayType array_type,
193 void* external_pointer,
194 PretenureFlag pretenure = NOT_TENURED);
195
Steve Block44f0eee2011-05-26 01:26:41 +0100196 Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
Ben Murdochb0fe1622011-05-05 13:52:32 +0100197 Handle<Object> value);
198
Steve Block44f0eee2011-05-26 01:26:41 +0100199 Handle<Map> NewMap(InstanceType type, int instance_size);
Steve Blocka7e24c12009-10-30 11:49:00 +0000200
Steve Block44f0eee2011-05-26 01:26:41 +0100201 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000202
Steve Block44f0eee2011-05-26 01:26:41 +0100203 Handle<Map> CopyMapDropDescriptors(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000204
205 // Copy the map adding more inobject properties if possible without
206 // overflowing the instance size.
Steve Block44f0eee2011-05-26 01:26:41 +0100207 Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
Steve Blocka7e24c12009-10-30 11:49:00 +0000208
Steve Block44f0eee2011-05-26 01:26:41 +0100209 Handle<Map> CopyMapDropTransitions(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000210
Steve Block44f0eee2011-05-26 01:26:41 +0100211 Handle<Map> GetFastElementsMap(Handle<Map> map);
Steve Block8defd9f2010-07-08 12:39:36 +0100212
Steve Block44f0eee2011-05-26 01:26:41 +0100213 Handle<Map> GetSlowElementsMap(Handle<Map> map);
Steve Block8defd9f2010-07-08 12:39:36 +0100214
Steve Block44f0eee2011-05-26 01:26:41 +0100215 Handle<Map> GetExternalArrayElementsMap(Handle<Map> map,
216 ExternalArrayType array_type,
217 bool safe_to_add_transition);
Steve Block1e0659c2011-05-24 12:43:12 +0100218
Steve Block44f0eee2011-05-26 01:26:41 +0100219 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
Steve Blocka7e24c12009-10-30 11:49:00 +0000220
221 // Numbers (eg, literals) are pretenured by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100222 Handle<Object> NewNumber(double value,
223 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000224
Steve Block44f0eee2011-05-26 01:26:41 +0100225 Handle<Object> NewNumberFromInt(int value);
226 Handle<Object> NewNumberFromUint(uint32_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000227
228 // These objects are used by the api to create env-independent data
229 // structures in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100230 Handle<JSObject> NewNeanderObject();
Steve Blocka7e24c12009-10-30 11:49:00 +0000231
Steve Block44f0eee2011-05-26 01:26:41 +0100232 Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000233
234 // JS objects are pretenured when allocated by the bootstrapper and
235 // runtime.
Steve Block44f0eee2011-05-26 01:26:41 +0100236 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
237 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000238
239 // Global objects are pretenured.
Steve Block44f0eee2011-05-26 01:26:41 +0100240 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
Steve Blocka7e24c12009-10-30 11:49:00 +0000241
242 // JS objects are pretenured when allocated by the bootstrapper and
243 // runtime.
Steve Block44f0eee2011-05-26 01:26:41 +0100244 Handle<JSObject> NewJSObjectFromMap(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000245
246 // JS arrays are pretenured when allocated by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100247 Handle<JSArray> NewJSArray(int capacity,
248 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000249
Steve Block44f0eee2011-05-26 01:26:41 +0100250 Handle<JSArray> NewJSArrayWithElements(
Steve Blocka7e24c12009-10-30 11:49:00 +0000251 Handle<FixedArray> elements,
252 PretenureFlag pretenure = NOT_TENURED);
253
Ben Murdoch257744e2011-11-30 15:57:28 +0000254 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
255
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000256 // Change the type of the argument into a regular JS object and reinitialize.
257 void BecomeJSObject(Handle<JSProxy> object);
258
Steve Block44f0eee2011-05-26 01:26:41 +0100259 Handle<JSFunction> NewFunction(Handle<String> name,
260 Handle<Object> prototype);
Steve Blocka7e24c12009-10-30 11:49:00 +0000261
Steve Block44f0eee2011-05-26 01:26:41 +0100262 Handle<JSFunction> NewFunctionWithoutPrototype(
263 Handle<String> name,
264 StrictModeFlag strict_mode);
Steve Block6ded16b2010-05-10 14:33:55 +0100265
Steve Block44f0eee2011-05-26 01:26:41 +0100266 Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
Steve Blocka7e24c12009-10-30 11:49:00 +0000267
Steve Block44f0eee2011-05-26 01:26:41 +0100268 Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100269 Handle<SharedFunctionInfo> function_info,
270 Handle<Map> function_map,
271 PretenureFlag pretenure);
272
Steve Block44f0eee2011-05-26 01:26:41 +0100273 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100274 Handle<SharedFunctionInfo> function_info,
Leon Clarkee46be812010-01-19 14:06:41 +0000275 Handle<Context> context,
276 PretenureFlag pretenure = TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000277
Steve Block44f0eee2011-05-26 01:26:41 +0100278 Handle<Code> NewCode(const CodeDesc& desc,
279 Code::Flags flags,
280 Handle<Object> self_reference,
281 bool immovable = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000282
Steve Block44f0eee2011-05-26 01:26:41 +0100283 Handle<Code> CopyCode(Handle<Code> code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000284
Steve Block44f0eee2011-05-26 01:26:41 +0100285 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
Steve Block6ded16b2010-05-10 14:33:55 +0100286
Steve Block44f0eee2011-05-26 01:26:41 +0100287 Handle<Object> ToObject(Handle<Object> object);
288 Handle<Object> ToObject(Handle<Object> object,
289 Handle<Context> global_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000290
291 // Interface for creating error objects.
292
Steve Block44f0eee2011-05-26 01:26:41 +0100293 Handle<Object> NewError(const char* maker, const char* type,
294 Handle<JSArray> args);
295 Handle<Object> NewError(const char* maker, const char* type,
296 Vector< Handle<Object> > args);
297 Handle<Object> NewError(const char* type,
298 Vector< Handle<Object> > args);
299 Handle<Object> NewError(Handle<String> message);
300 Handle<Object> NewError(const char* constructor,
301 Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000302
Steve Block44f0eee2011-05-26 01:26:41 +0100303 Handle<Object> NewTypeError(const char* type,
304 Vector< Handle<Object> > args);
305 Handle<Object> NewTypeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000306
Steve Block44f0eee2011-05-26 01:26:41 +0100307 Handle<Object> NewRangeError(const char* type,
308 Vector< Handle<Object> > args);
309 Handle<Object> NewRangeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000310
Steve Block44f0eee2011-05-26 01:26:41 +0100311 Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
312 Handle<Object> NewSyntaxError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000313
Steve Block44f0eee2011-05-26 01:26:41 +0100314 Handle<Object> NewReferenceError(const char* type,
315 Vector< Handle<Object> > args);
316 Handle<Object> NewReferenceError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000317
Steve Block44f0eee2011-05-26 01:26:41 +0100318 Handle<Object> NewEvalError(const char* type,
319 Vector< Handle<Object> > args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000320
321
Steve Block44f0eee2011-05-26 01:26:41 +0100322 Handle<JSFunction> NewFunction(Handle<String> name,
323 InstanceType type,
324 int instance_size,
325 Handle<Code> code,
326 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000327
Steve Block44f0eee2011-05-26 01:26:41 +0100328 Handle<JSFunction> NewFunction(Handle<Map> function_map,
Steve Blocka7e24c12009-10-30 11:49:00 +0000329 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
330
331
Steve Block44f0eee2011-05-26 01:26:41 +0100332 Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
333 InstanceType type,
334 int instance_size,
335 Handle<JSObject> prototype,
336 Handle<Code> code,
337 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000338
Steve Block44f0eee2011-05-26 01:26:41 +0100339 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
340 Handle<Code> code);
Steve Block6ded16b2010-05-10 14:33:55 +0100341
Ben Murdoch257744e2011-11-30 15:57:28 +0000342 Handle<DescriptorArray> CopyAppendForeignDescriptor(
Steve Blocka7e24c12009-10-30 11:49:00 +0000343 Handle<DescriptorArray> array,
344 Handle<String> key,
345 Handle<Object> value,
346 PropertyAttributes attributes);
347
Steve Block44f0eee2011-05-26 01:26:41 +0100348 Handle<String> NumberToString(Handle<Object> number);
Steve Blocka7e24c12009-10-30 11:49:00 +0000349
350 enum ApiInstanceType {
351 JavaScriptObject,
352 InnerGlobalObject,
353 OuterGlobalObject
354 };
355
Steve Block44f0eee2011-05-26 01:26:41 +0100356 Handle<JSFunction> CreateApiFunction(
Steve Blocka7e24c12009-10-30 11:49:00 +0000357 Handle<FunctionTemplateInfo> data,
358 ApiInstanceType type = JavaScriptObject);
359
Steve Block44f0eee2011-05-26 01:26:41 +0100360 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000361
362 // Installs interceptors on the instance. 'desc' is a function template,
363 // and instance is an object instance created by the function of this
364 // function template.
Steve Block44f0eee2011-05-26 01:26:41 +0100365 void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
366 Handle<JSObject> instance,
367 bool* pending_exception);
Steve Blocka7e24c12009-10-30 11:49:00 +0000368
369#define ROOT_ACCESSOR(type, name, camel_name) \
Steve Block44f0eee2011-05-26 01:26:41 +0100370 inline Handle<type> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100371 return Handle<type>(BitCast<type**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100372 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000373 }
374 ROOT_LIST(ROOT_ACCESSOR)
375#undef ROOT_ACCESSOR_ACCESSOR
376
Steve Block44f0eee2011-05-26 01:26:41 +0100377#define SYMBOL_ACCESSOR(name, str) \
378 inline Handle<String> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100379 return Handle<String>(BitCast<String**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100380 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000381 }
382 SYMBOL_LIST(SYMBOL_ACCESSOR)
383#undef SYMBOL_ACCESSOR
384
Steve Block44f0eee2011-05-26 01:26:41 +0100385 Handle<String> hidden_symbol() {
386 return Handle<String>(&isolate()->heap()->hidden_symbol_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000387 }
388
Steve Block44f0eee2011-05-26 01:26:41 +0100389 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100390 Handle<String> name,
391 int number_of_literals,
392 Handle<Code> code,
393 Handle<SerializedScopeInfo> scope_info);
Steve Block44f0eee2011-05-26 01:26:41 +0100394 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000395
Steve Block44f0eee2011-05-26 01:26:41 +0100396 Handle<JSMessageObject> NewJSMessageObject(
Steve Block1e0659c2011-05-24 12:43:12 +0100397 Handle<String> type,
398 Handle<JSArray> arguments,
399 int start_position,
400 int end_position,
401 Handle<Object> script,
402 Handle<Object> stack_trace,
403 Handle<Object> stack_frames);
404
Steve Block44f0eee2011-05-26 01:26:41 +0100405 Handle<NumberDictionary> DictionaryAtNumberPut(
Steve Blocka7e24c12009-10-30 11:49:00 +0000406 Handle<NumberDictionary>,
407 uint32_t key,
408 Handle<Object> value);
409
410#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100411 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000412#endif
413
414 // Return a map using the map cache in the global context.
415 // The key the an ordered set of property names.
Steve Block44f0eee2011-05-26 01:26:41 +0100416 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
417 Handle<FixedArray> keys);
Steve Blocka7e24c12009-10-30 11:49:00 +0000418
419 // Creates a new FixedArray that holds the data associated with the
420 // atom regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100421 void SetRegExpAtomData(Handle<JSRegExp> regexp,
422 JSRegExp::Type type,
423 Handle<String> source,
424 JSRegExp::Flags flags,
425 Handle<Object> match_pattern);
Steve Blocka7e24c12009-10-30 11:49:00 +0000426
427 // Creates a new FixedArray that holds the data associated with the
428 // irregexp regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100429 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
430 JSRegExp::Type type,
431 Handle<String> source,
432 JSRegExp::Flags flags,
433 int capture_count);
Steve Blocka7e24c12009-10-30 11:49:00 +0000434
435 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100436 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000437
Steve Block44f0eee2011-05-26 01:26:41 +0100438 Handle<JSFunction> NewFunctionHelper(Handle<String> name,
439 Handle<Object> prototype);
Steve Block6ded16b2010-05-10 14:33:55 +0100440
Steve Block44f0eee2011-05-26 01:26:41 +0100441 Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
442 Handle<String> name,
443 StrictModeFlag strict_mode);
444
445 Handle<DescriptorArray> CopyAppendCallbackDescriptors(
Steve Blocka7e24c12009-10-30 11:49:00 +0000446 Handle<DescriptorArray> array,
447 Handle<Object> descriptors);
448
Steve Blocka7e24c12009-10-30 11:49:00 +0000449 // Create a new map cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100450 Handle<MapCache> NewMapCache(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +0000451
452 // Update the map cache in the global context with (keys, map)
Steve Block44f0eee2011-05-26 01:26:41 +0100453 Handle<MapCache> AddToMapCache(Handle<Context> context,
454 Handle<FixedArray> keys,
455 Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000456};
457
458
459} } // namespace v8::internal
460
461#endif // V8_FACTORY_H_