blob: a69b05b38f00fc385b665bba6eea1ea039b3fb24 [file] [log] [blame]
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001// Copyright 2011 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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
kasperl@chromium.org68ac0092009-07-09 06:00:35 +000031#include "globals.h"
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000032#include "handles.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000033#include "heap.h"
34
kasperl@chromium.org71affb52009-05-26 05:44:31 +000035namespace v8 {
36namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000037
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000038// Interface for handle based allocation.
39
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000040class Factory {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000041 public:
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +000042 // Allocate a new uninitialized fixed array.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000043 Handle<FixedArray> NewFixedArray(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000044 int size,
45 PretenureFlag pretenure = NOT_TENURED);
46
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000047 // Allocate a new fixed array with non-existing entries (the hole).
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000048 Handle<FixedArray> NewFixedArrayWithHoles(
ricow@chromium.orgc9c80822010-04-21 08:22:37 +000049 int size,
50 PretenureFlag pretenure = NOT_TENURED);
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000051
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +000052 // Allocate a new uninitialized fixed double array.
53 Handle<FixedArray> NewFixedDoubleArray(
54 int size,
55 PretenureFlag pretenure = NOT_TENURED);
56
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000057 Handle<NumberDictionary> NewNumberDictionary(int at_least_space_for);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +000058
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000059 Handle<StringDictionary> NewStringDictionary(int at_least_space_for);
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000060
vegorov@chromium.org7943d462011-08-01 11:41:52 +000061 Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for);
62
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000063 Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors);
64 Handle<DeoptimizationInputData> NewDeoptimizationInputData(
kasperl@chromium.orga5551262010-12-07 12:49:48 +000065 int deopt_entry_count,
66 PretenureFlag pretenure);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000067 Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
kasperl@chromium.orga5551262010-12-07 12:49:48 +000068 int deopt_entry_count,
69 PretenureFlag pretenure);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000070
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000071 Handle<String> LookupSymbol(Vector<const char> str);
danno@chromium.org40cb8782011-05-25 07:58:50 +000072 Handle<String> LookupSymbol(Handle<String> str);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000073 Handle<String> LookupAsciiSymbol(Vector<const char> str);
danno@chromium.org40cb8782011-05-25 07:58:50 +000074 Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>,
75 int from,
76 int length);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000077 Handle<String> LookupTwoByteSymbol(Vector<const uc16> str);
78 Handle<String> LookupAsciiSymbol(const char* str) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000105 Handle<String> NewStringFromAscii(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000111 Handle<String> NewStringFromUtf8(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000112 Vector<const char> str,
113 PretenureFlag pretenure = NOT_TENURED);
114
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000115 Handle<String> NewStringFromTwoByte(
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000116 Vector<const uc16> str,
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000117 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000118
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000119 // 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.
ager@chromium.org04921a82011-06-27 13:21:41 +0000122 Handle<SeqAsciiString> NewRawAsciiString(
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000123 int length,
124 PretenureFlag pretenure = NOT_TENURED);
ager@chromium.org04921a82011-06-27 13:21:41 +0000125 Handle<SeqTwoByteString> NewRawTwoByteString(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000126 int length,
127 PretenureFlag pretenure = NOT_TENURED);
128
129 // Create a new cons string object which consists of a pair of strings.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000130 Handle<String> NewConsString(Handle<String> first,
131 Handle<String> second);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000132
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000133 // Create a new string object which holds a substring of a string.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000134 Handle<String> NewSubString(Handle<String> str,
135 int begin,
136 int end);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000137
ager@chromium.org04921a82011-06-27 13:21:41 +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
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000147 Handle<String> NewExternalStringFromAscii(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000148 ExternalAsciiString::Resource* resource);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000149 Handle<String> NewExternalStringFromTwoByte(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000150 ExternalTwoByteString::Resource* resource);
151
152 // Create a global (but otherwise uninitialized) context.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000153 Handle<Context> NewGlobalContext();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000154
155 // Create a function context.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000156 Handle<Context> NewFunctionContext(int length,
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000157 Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000158
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000159 // Create a catch context.
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000160 Handle<Context> NewCatchContext(Handle<JSFunction> function,
161 Handle<Context> previous,
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000162 Handle<String> name,
163 Handle<Object> thrown_object);
164
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000165 // Create a 'with' context.
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000166 Handle<Context> NewWithContext(Handle<JSFunction> function,
167 Handle<Context> previous,
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000168 Handle<JSObject> extension);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000169
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000170 // Create a 'block' context.
171 Handle<Context> NewBlockContext(Handle<JSFunction> function,
172 Handle<Context> previous,
173 Handle<SerializedScopeInfo> scope_info);
174
ager@chromium.org32912102009-01-16 10:38:43 +0000175 // Return the Symbol matching the passed in string.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000176 Handle<String> SymbolFromString(Handle<String> value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000177
178 // Allocate a new struct. The struct is pretenured (allocated directly in
179 // the old generation).
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000180 Handle<Struct> NewStruct(InstanceType type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000181
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000182 Handle<AccessorInfo> NewAccessorInfo();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000183
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000184 Handle<Script> NewScript(Handle<String> source);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000185
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000186 // Foreign objects are pretenured when allocated by the bootstrapper.
187 Handle<Foreign> NewForeign(Address addr,
188 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000189
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000190 // Allocate a new foreign object. The foreign is pretenured (allocated
191 // directly in the old generation).
192 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000193
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000194 Handle<ByteArray> NewByteArray(int length,
195 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000196
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000197 Handle<ExternalArray> NewExternalArray(
ager@chromium.org3811b432009-10-28 14:53:37 +0000198 int length,
199 ExternalArrayType array_type,
200 void* external_pointer,
201 PretenureFlag pretenure = NOT_TENURED);
202
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000203 Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000204 Handle<Object> value);
205
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000206 Handle<Map> NewMap(InstanceType type, int instance_size);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000207
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000208 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000209
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000210 Handle<Map> CopyMapDropDescriptors(Handle<Map> map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000211
ager@chromium.org32912102009-01-16 10:38:43 +0000212 // Copy the map adding more inobject properties if possible without
213 // overflowing the instance size.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000214 Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
ager@chromium.org32912102009-01-16 10:38:43 +0000215
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000216 Handle<Map> CopyMapDropTransitions(Handle<Map> map);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000217
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000218 Handle<Map> GetFastElementsMap(Handle<Map> map);
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000219
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000220 Handle<Map> GetSlowElementsMap(Handle<Map> map);
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000221
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000222 Handle<Map> GetExternalArrayElementsMap(Handle<Map> map,
223 ExternalArrayType array_type,
224 bool safe_to_add_transition);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +0000225
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000226 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000227
228 // Numbers (eg, literals) are pretenured by the parser.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000229 Handle<Object> NewNumber(double value,
230 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000231
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000232 Handle<Object> NewNumberFromInt(int value);
233 Handle<Object> NewNumberFromUint(uint32_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000234
235 // These objects are used by the api to create env-independent data
236 // structures in the heap.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000237 Handle<JSObject> NewNeanderObject();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000238
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000239 Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000240
241 // JS objects are pretenured when allocated by the bootstrapper and
242 // runtime.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000243 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
244 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000245
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000246 // Global objects are pretenured.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000247 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000248
ager@chromium.org236ad962008-09-25 09:45:57 +0000249 // JS objects are pretenured when allocated by the bootstrapper and
250 // runtime.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000251 Handle<JSObject> NewJSObjectFromMap(Handle<Map> map);
ager@chromium.org236ad962008-09-25 09:45:57 +0000252
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000253 // JS arrays are pretenured when allocated by the parser.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000254 Handle<JSArray> NewJSArray(int capacity,
255 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000256
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000257 Handle<JSArray> NewJSArrayWithElements(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000258 Handle<FixedArray> elements,
259 PretenureFlag pretenure = NOT_TENURED);
260
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000261 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
262
rossberg@chromium.org717967f2011-07-20 13:44:42 +0000263 // Change the type of the argument into a regular JS object and reinitialize.
264 void BecomeJSObject(Handle<JSProxy> object);
265
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000266 Handle<JSFunction> NewFunction(Handle<String> name,
267 Handle<Object> prototype);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000268
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000269 Handle<JSFunction> NewFunctionWithoutPrototype(
270 Handle<String> name,
271 StrictModeFlag strict_mode);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000272
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000273 Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000274
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000275 Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000276 Handle<SharedFunctionInfo> function_info,
277 Handle<Map> function_map,
278 PretenureFlag pretenure);
279
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000280 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000281 Handle<SharedFunctionInfo> function_info,
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000282 Handle<Context> context,
283 PretenureFlag pretenure = TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000284
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000285 Handle<SerializedScopeInfo> NewSerializedScopeInfo(int length);
286
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000287 Handle<Code> NewCode(const CodeDesc& desc,
288 Code::Flags flags,
289 Handle<Object> self_reference,
290 bool immovable = false);
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000291
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000292 Handle<Code> CopyCode(Handle<Code> code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000293
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000294 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000295
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000296 Handle<Object> ToObject(Handle<Object> object);
297 Handle<Object> ToObject(Handle<Object> object,
298 Handle<Context> global_context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000299
300 // Interface for creating error objects.
301
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000302 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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000311
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000312 Handle<Object> NewTypeError(const char* type,
313 Vector< Handle<Object> > args);
314 Handle<Object> NewTypeError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000315
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000316 Handle<Object> NewRangeError(const char* type,
317 Vector< Handle<Object> > args);
318 Handle<Object> NewRangeError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000319
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000320 Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
321 Handle<Object> NewSyntaxError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000322
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000323 Handle<Object> NewReferenceError(const char* type,
324 Vector< Handle<Object> > args);
325 Handle<Object> NewReferenceError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000326
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000327 Handle<Object> NewEvalError(const char* type,
328 Vector< Handle<Object> > args);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000329
330
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000331 Handle<JSFunction> NewFunction(Handle<String> name,
332 InstanceType type,
333 int instance_size,
334 Handle<Code> code,
335 bool force_initial_map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000336
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000337 Handle<JSFunction> NewFunction(Handle<Map> function_map,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000338 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
339
340
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000341 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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000347
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000348 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
349 Handle<Code> code);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000350
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000351 Handle<DescriptorArray> CopyAppendForeignDescriptor(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000352 Handle<DescriptorArray> array,
353 Handle<String> key,
354 Handle<Object> value,
355 PropertyAttributes attributes);
356
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000357 Handle<String> NumberToString(Handle<Object> number);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000358
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000359 enum ApiInstanceType {
360 JavaScriptObject,
361 InnerGlobalObject,
362 OuterGlobalObject
363 };
364
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000365 Handle<JSFunction> CreateApiFunction(
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000366 Handle<FunctionTemplateInfo> data,
367 ApiInstanceType type = JavaScriptObject);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000368
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000369 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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
ager@chromium.org32912102009-01-16 10:38:43 +0000373 // function template.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000374 void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
375 Handle<JSObject> instance,
376 bool* pending_exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000377
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000378#define ROOT_ACCESSOR(type, name, camel_name) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000379 inline Handle<type> name() { \
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000380 return Handle<type>(BitCast<type**>( \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000381 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000382 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000383 ROOT_LIST(ROOT_ACCESSOR)
384#undef ROOT_ACCESSOR_ACCESSOR
385
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000386#define SYMBOL_ACCESSOR(name, str) \
387 inline Handle<String> name() { \
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000388 return Handle<String>(BitCast<String**>( \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000389 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000390 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000391 SYMBOL_LIST(SYMBOL_ACCESSOR)
392#undef SYMBOL_ACCESSOR
393
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000394 Handle<String> hidden_symbol() {
395 return Handle<String>(&isolate()->heap()->hidden_symbol_);
ager@chromium.org3b45ab52009-03-19 22:21:34 +0000396 }
397
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000398 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000399 Handle<String> name,
400 int number_of_literals,
401 Handle<Code> code,
ager@chromium.orgb5737492010-07-15 09:29:43 +0000402 Handle<SerializedScopeInfo> scope_info);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000403 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000404
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000405 Handle<JSMessageObject> NewJSMessageObject(
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000406 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
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000414 Handle<NumberDictionary> DictionaryAtNumberPut(
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000415 Handle<NumberDictionary>,
416 uint32_t key,
417 Handle<Object> value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000418
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000419#ifdef ENABLE_DEBUGGER_SUPPORT
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000420 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000421#endif
ager@chromium.org236ad962008-09-25 09:45:57 +0000422
423 // Return a map using the map cache in the global context.
424 // The key the an ordered set of property names.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000425 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
426 Handle<FixedArray> keys);
ager@chromium.org236ad962008-09-25 09:45:57 +0000427
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000428 // Creates a new FixedArray that holds the data associated with the
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000429 // atom regexp and stores it in the regexp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000430 void SetRegExpAtomData(Handle<JSRegExp> regexp,
431 JSRegExp::Type type,
432 Handle<String> source,
433 JSRegExp::Flags flags,
434 Handle<Object> match_pattern);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000435
436 // Creates a new FixedArray that holds the data associated with the
437 // irregexp regexp and stores it in the regexp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000438 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
439 JSRegExp::Type type,
440 Handle<String> source,
441 JSRegExp::Flags flags,
442 int capture_count);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000443
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000444 private:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000445 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000446
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000447 Handle<JSFunction> NewFunctionHelper(Handle<String> name,
448 Handle<Object> prototype);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000449
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000450 Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
451 Handle<String> name,
452 StrictModeFlag strict_mode);
453
454 Handle<DescriptorArray> CopyAppendCallbackDescriptors(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000455 Handle<DescriptorArray> array,
456 Handle<Object> descriptors);
457
ager@chromium.org236ad962008-09-25 09:45:57 +0000458 // Create a new map cache.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000459 Handle<MapCache> NewMapCache(int at_least_space_for);
ager@chromium.org236ad962008-09-25 09:45:57 +0000460
461 // Update the map cache in the global context with (keys, map)
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000462 Handle<MapCache> AddToMapCache(Handle<Context> context,
463 Handle<FixedArray> keys,
464 Handle<Map> map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000465};
466
467
468} } // namespace v8::internal
469
470#endif // V8_FACTORY_H_