blob: c9817fefecb8c5d3be0520406c57fc265cd6d84a [file] [log] [blame]
Ben Murdoch85b71792012-04-11 18:30:58 +01001// 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 Murdoch85b71792012-04-11 18:30:58 +010053 Handle<FixedArray> NewFixedDoubleArray(
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000054 int size,
55 PretenureFlag pretenure = NOT_TENURED);
56
Ben Murdochc7cc0282012-03-05 14:35:55 +000057 Handle<SeededNumberDictionary> NewSeededNumberDictionary(
58 int at_least_space_for);
59
60 Handle<UnseededNumberDictionary> NewUnseededNumberDictionary(
61 int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +000062
Steve Block44f0eee2011-05-26 01:26:41 +010063 Handle<StringDictionary> NewStringDictionary(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +000064
Ben Murdoch69a99ed2011-11-30 16:03:39 +000065 Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for);
66
Steve Block44f0eee2011-05-26 01:26:41 +010067 Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors);
68 Handle<DeoptimizationInputData> NewDeoptimizationInputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010069 int deopt_entry_count,
70 PretenureFlag pretenure);
Steve Block44f0eee2011-05-26 01:26:41 +010071 Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010072 int deopt_entry_count,
73 PretenureFlag pretenure);
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +010074
Steve Block44f0eee2011-05-26 01:26:41 +010075 Handle<String> LookupSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000076 Handle<String> LookupSymbol(Handle<String> str);
Steve Block44f0eee2011-05-26 01:26:41 +010077 Handle<String> LookupAsciiSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000078 Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>,
79 int from,
80 int length);
Steve Block44f0eee2011-05-26 01:26:41 +010081 Handle<String> LookupTwoByteSymbol(Vector<const uc16> str);
82 Handle<String> LookupAsciiSymbol(const char* str) {
Steve Blocka7e24c12009-10-30 11:49:00 +000083 return LookupSymbol(CStrVector(str));
84 }
85
86
87 // String creation functions. Most of the string creation functions take
88 // a Heap::PretenureFlag argument to optionally request that they be
89 // allocated in the old generation. The pretenure flag defaults to
90 // DONT_TENURE.
91 //
92 // Creates a new String object. There are two String encodings: ASCII and
93 // two byte. One should choose between the three string factory functions
94 // based on the encoding of the string buffer that the string is
95 // initialized from.
96 // - ...FromAscii initializes the string from a buffer that is ASCII
97 // encoded (it does not check that the buffer is ASCII encoded) and
98 // the result will be ASCII encoded.
99 // - ...FromUtf8 initializes the string from a buffer that is UTF-8
100 // encoded. If the characters are all single-byte characters, the
101 // result will be ASCII encoded, otherwise it will converted to two
102 // byte.
103 // - ...FromTwoByte initializes the string from a buffer that is two
104 // byte encoded. If the characters are all single-byte characters,
105 // the result will be converted to ASCII, otherwise it will be left as
106 // two byte.
107 //
108 // ASCII strings are pretenured when used as keys in the SourceCodeCache.
Steve Block44f0eee2011-05-26 01:26:41 +0100109 Handle<String> NewStringFromAscii(
Steve Blocka7e24c12009-10-30 11:49:00 +0000110 Vector<const char> str,
111 PretenureFlag pretenure = NOT_TENURED);
112
113 // UTF8 strings are pretenured when used for regexp literal patterns and
114 // flags in the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100115 Handle<String> NewStringFromUtf8(
Steve Blocka7e24c12009-10-30 11:49:00 +0000116 Vector<const char> str,
117 PretenureFlag pretenure = NOT_TENURED);
118
Steve Block44f0eee2011-05-26 01:26:41 +0100119 Handle<String> NewStringFromTwoByte(
Leon Clarkeac952652010-07-15 11:15:24 +0100120 Vector<const uc16> str,
Steve Blocka7e24c12009-10-30 11:49:00 +0000121 PretenureFlag pretenure = NOT_TENURED);
122
Leon Clarkeac952652010-07-15 11:15:24 +0100123 // Allocates and partially initializes an ASCII or TwoByte String. The
124 // characters of the string are uninitialized. Currently used in regexp code
125 // only, where they are pretenured.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000126 Handle<SeqAsciiString> NewRawAsciiString(
Leon Clarkeac952652010-07-15 11:15:24 +0100127 int length,
128 PretenureFlag pretenure = NOT_TENURED);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000129 Handle<SeqTwoByteString> NewRawTwoByteString(
Steve Blocka7e24c12009-10-30 11:49:00 +0000130 int length,
131 PretenureFlag pretenure = NOT_TENURED);
132
133 // Create a new cons string object which consists of a pair of strings.
Steve Block44f0eee2011-05-26 01:26:41 +0100134 Handle<String> NewConsString(Handle<String> first,
135 Handle<String> second);
Steve Blocka7e24c12009-10-30 11:49:00 +0000136
Steve Blockd0582a62009-12-15 09:54:21 +0000137 // Create a new string object which holds a substring of a string.
Steve Block44f0eee2011-05-26 01:26:41 +0100138 Handle<String> NewSubString(Handle<String> str,
139 int begin,
140 int end);
Steve Blocka7e24c12009-10-30 11:49:00 +0000141
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000142 // Create a new string object which holds a proper substring of a string.
143 Handle<String> NewProperSubString(Handle<String> str,
144 int begin,
145 int end);
146
Steve Blocka7e24c12009-10-30 11:49:00 +0000147 // Creates a new external String object. There are two String encodings
148 // in the system: ASCII and two byte. Unlike other String types, it does
149 // not make sense to have a UTF-8 factory function for external strings,
150 // because we cannot change the underlying buffer.
Steve Block44f0eee2011-05-26 01:26:41 +0100151 Handle<String> NewExternalStringFromAscii(
Ben Murdoch85b71792012-04-11 18:30:58 +0100152 ExternalAsciiString::Resource* resource);
Steve Block44f0eee2011-05-26 01:26:41 +0100153 Handle<String> NewExternalStringFromTwoByte(
Ben Murdoch85b71792012-04-11 18:30:58 +0100154 ExternalTwoByteString::Resource* resource);
Steve Blocka7e24c12009-10-30 11:49:00 +0000155
156 // Create a global (but otherwise uninitialized) context.
Steve Block44f0eee2011-05-26 01:26:41 +0100157 Handle<Context> NewGlobalContext();
Steve Blocka7e24c12009-10-30 11:49:00 +0000158
159 // Create a function context.
Steve Block44f0eee2011-05-26 01:26:41 +0100160 Handle<Context> NewFunctionContext(int length,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000161 Handle<JSFunction> function);
162
163 // Create a catch context.
164 Handle<Context> NewCatchContext(Handle<JSFunction> function,
165 Handle<Context> previous,
166 Handle<String> name,
167 Handle<Object> thrown_object);
Steve Blocka7e24c12009-10-30 11:49:00 +0000168
169 // Create a 'with' context.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000170 Handle<Context> NewWithContext(Handle<JSFunction> function,
171 Handle<Context> previous,
172 Handle<JSObject> extension);
Steve Blocka7e24c12009-10-30 11:49:00 +0000173
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000174 // Create a 'block' context.
175 Handle<Context> NewBlockContext(Handle<JSFunction> function,
176 Handle<Context> previous,
Ben Murdoch85b71792012-04-11 18:30:58 +0100177 Handle<SerializedScopeInfo> scope_info);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000178
Steve Blocka7e24c12009-10-30 11:49:00 +0000179 // Return the Symbol matching the passed in string.
Steve Block44f0eee2011-05-26 01:26:41 +0100180 Handle<String> SymbolFromString(Handle<String> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000181
182 // Allocate a new struct. The struct is pretenured (allocated directly in
183 // the old generation).
Steve Block44f0eee2011-05-26 01:26:41 +0100184 Handle<Struct> NewStruct(InstanceType type);
Steve Blocka7e24c12009-10-30 11:49:00 +0000185
Steve Block44f0eee2011-05-26 01:26:41 +0100186 Handle<AccessorInfo> NewAccessorInfo();
Steve Blocka7e24c12009-10-30 11:49:00 +0000187
Steve Block44f0eee2011-05-26 01:26:41 +0100188 Handle<Script> NewScript(Handle<String> source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000189
Ben Murdoch257744e2011-11-30 15:57:28 +0000190 // Foreign objects are pretenured when allocated by the bootstrapper.
191 Handle<Foreign> NewForeign(Address addr,
192 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000193
Ben Murdoch257744e2011-11-30 15:57:28 +0000194 // Allocate a new foreign object. The foreign is pretenured (allocated
195 // directly in the old generation).
196 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
Steve Blocka7e24c12009-10-30 11:49:00 +0000197
Steve Block44f0eee2011-05-26 01:26:41 +0100198 Handle<ByteArray> NewByteArray(int length,
199 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000200
Steve Block44f0eee2011-05-26 01:26:41 +0100201 Handle<ExternalArray> NewExternalArray(
Steve Block3ce2e202009-11-05 08:53:23 +0000202 int length,
203 ExternalArrayType array_type,
204 void* external_pointer,
205 PretenureFlag pretenure = NOT_TENURED);
206
Steve Block44f0eee2011-05-26 01:26:41 +0100207 Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
Ben Murdochb0fe1622011-05-05 13:52:32 +0100208 Handle<Object> value);
209
Ben Murdoch85b71792012-04-11 18:30:58 +0100210 Handle<Map> NewMap(InstanceType type, int instance_size);
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 Murdoch85b71792012-04-11 18:30:58 +0100222 Handle<Map> GetFastElementsMap(Handle<Map> map);
223
224 Handle<Map> GetSlowElementsMap(Handle<Map> map);
225
226 Handle<Map> GetElementsTransitionMap(Handle<Map> map,
227 ElementsKind elements_kind,
228 bool safe_to_add_transition);
Steve Block1e0659c2011-05-24 12:43:12 +0100229
Steve Block44f0eee2011-05-26 01:26:41 +0100230 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
Steve Blocka7e24c12009-10-30 11:49:00 +0000231
Ben Murdoch85b71792012-04-11 18:30:58 +0100232 // Numbers (eg, literals) are pretenured by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100233 Handle<Object> NewNumber(double value,
234 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000235
Ben Murdoch85b71792012-04-11 18:30:58 +0100236 Handle<Object> NewNumberFromInt(int value);
237 Handle<Object> NewNumberFromUint(uint32_t value);
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(
Ben Murdoch85b71792012-04-11 18:30:58 +0100262 Handle<FixedArray> elements,
Steve Blocka7e24c12009-10-30 11:49:00 +0000263 PretenureFlag pretenure = NOT_TENURED);
264
Ben Murdoch257744e2011-11-30 15:57:28 +0000265 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
266
Ben Murdoch589d6972011-11-30 16:04:58 +0000267 // Change the type of the argument into a JS object/function and reinitialize.
268 void BecomeJSObject(Handle<JSReceiver> object);
269 void BecomeJSFunction(Handle<JSReceiver> object);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000270
Steve Block44f0eee2011-05-26 01:26:41 +0100271 Handle<JSFunction> NewFunction(Handle<String> name,
272 Handle<Object> prototype);
Steve Blocka7e24c12009-10-30 11:49:00 +0000273
Steve Block44f0eee2011-05-26 01:26:41 +0100274 Handle<JSFunction> NewFunctionWithoutPrototype(
275 Handle<String> name,
Ben Murdoch85b71792012-04-11 18:30:58 +0100276 StrictModeFlag strict_mode);
Steve Block6ded16b2010-05-10 14:33:55 +0100277
Steve Block44f0eee2011-05-26 01:26:41 +0100278 Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
Steve Blocka7e24c12009-10-30 11:49:00 +0000279
Steve Block44f0eee2011-05-26 01:26:41 +0100280 Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100281 Handle<SharedFunctionInfo> function_info,
282 Handle<Map> function_map,
283 PretenureFlag pretenure);
284
Steve Block44f0eee2011-05-26 01:26:41 +0100285 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100286 Handle<SharedFunctionInfo> function_info,
Leon Clarkee46be812010-01-19 14:06:41 +0000287 Handle<Context> context,
288 PretenureFlag pretenure = TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000289
Ben Murdoch85b71792012-04-11 18:30:58 +0100290 Handle<SerializedScopeInfo> NewSerializedScopeInfo(int length);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000291
Steve Block44f0eee2011-05-26 01:26:41 +0100292 Handle<Code> NewCode(const CodeDesc& desc,
293 Code::Flags flags,
294 Handle<Object> self_reference,
295 bool immovable = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000296
Steve Block44f0eee2011-05-26 01:26:41 +0100297 Handle<Code> CopyCode(Handle<Code> code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000298
Steve Block44f0eee2011-05-26 01:26:41 +0100299 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
Steve Block6ded16b2010-05-10 14:33:55 +0100300
Steve Block44f0eee2011-05-26 01:26:41 +0100301 Handle<Object> ToObject(Handle<Object> object);
302 Handle<Object> ToObject(Handle<Object> object,
303 Handle<Context> global_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000304
305 // Interface for creating error objects.
306
Steve Block44f0eee2011-05-26 01:26:41 +0100307 Handle<Object> NewError(const char* maker, const char* type,
308 Handle<JSArray> args);
309 Handle<Object> NewError(const char* maker, const char* type,
310 Vector< Handle<Object> > args);
311 Handle<Object> NewError(const char* type,
312 Vector< Handle<Object> > args);
313 Handle<Object> NewError(Handle<String> message);
314 Handle<Object> NewError(const char* constructor,
315 Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000316
Steve Block44f0eee2011-05-26 01:26:41 +0100317 Handle<Object> NewTypeError(const char* type,
318 Vector< Handle<Object> > args);
319 Handle<Object> NewTypeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000320
Steve Block44f0eee2011-05-26 01:26:41 +0100321 Handle<Object> NewRangeError(const char* type,
322 Vector< Handle<Object> > args);
323 Handle<Object> NewRangeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000324
Steve Block44f0eee2011-05-26 01:26:41 +0100325 Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
326 Handle<Object> NewSyntaxError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000327
Steve Block44f0eee2011-05-26 01:26:41 +0100328 Handle<Object> NewReferenceError(const char* type,
329 Vector< Handle<Object> > args);
330 Handle<Object> NewReferenceError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000331
Steve Block44f0eee2011-05-26 01:26:41 +0100332 Handle<Object> NewEvalError(const char* type,
333 Vector< Handle<Object> > args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000334
335
Steve Block44f0eee2011-05-26 01:26:41 +0100336 Handle<JSFunction> NewFunction(Handle<String> name,
337 InstanceType type,
338 int instance_size,
339 Handle<Code> code,
340 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000341
Steve Block44f0eee2011-05-26 01:26:41 +0100342 Handle<JSFunction> NewFunction(Handle<Map> function_map,
Steve Blocka7e24c12009-10-30 11:49:00 +0000343 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
344
345
Steve Block44f0eee2011-05-26 01:26:41 +0100346 Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
347 InstanceType type,
348 int instance_size,
349 Handle<JSObject> prototype,
350 Handle<Code> code,
351 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000352
Steve Block44f0eee2011-05-26 01:26:41 +0100353 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
354 Handle<Code> code);
Steve Block6ded16b2010-05-10 14:33:55 +0100355
Ben Murdoch257744e2011-11-30 15:57:28 +0000356 Handle<DescriptorArray> CopyAppendForeignDescriptor(
Steve Blocka7e24c12009-10-30 11:49:00 +0000357 Handle<DescriptorArray> array,
358 Handle<String> key,
359 Handle<Object> value,
360 PropertyAttributes attributes);
361
Steve Block44f0eee2011-05-26 01:26:41 +0100362 Handle<String> NumberToString(Handle<Object> number);
Steve Blocka7e24c12009-10-30 11:49:00 +0000363
364 enum ApiInstanceType {
365 JavaScriptObject,
366 InnerGlobalObject,
367 OuterGlobalObject
368 };
369
Steve Block44f0eee2011-05-26 01:26:41 +0100370 Handle<JSFunction> CreateApiFunction(
Steve Blocka7e24c12009-10-30 11:49:00 +0000371 Handle<FunctionTemplateInfo> data,
372 ApiInstanceType type = JavaScriptObject);
373
Steve Block44f0eee2011-05-26 01:26:41 +0100374 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000375
376 // Installs interceptors on the instance. 'desc' is a function template,
377 // and instance is an object instance created by the function of this
378 // function template.
Steve Block44f0eee2011-05-26 01:26:41 +0100379 void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
380 Handle<JSObject> instance,
381 bool* pending_exception);
Steve Blocka7e24c12009-10-30 11:49:00 +0000382
383#define ROOT_ACCESSOR(type, name, camel_name) \
Steve Block44f0eee2011-05-26 01:26:41 +0100384 inline Handle<type> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100385 return Handle<type>(BitCast<type**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100386 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000387 }
388 ROOT_LIST(ROOT_ACCESSOR)
389#undef ROOT_ACCESSOR_ACCESSOR
390
Steve Block44f0eee2011-05-26 01:26:41 +0100391#define SYMBOL_ACCESSOR(name, str) \
392 inline Handle<String> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100393 return Handle<String>(BitCast<String**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100394 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000395 }
396 SYMBOL_LIST(SYMBOL_ACCESSOR)
397#undef SYMBOL_ACCESSOR
398
Steve Block44f0eee2011-05-26 01:26:41 +0100399 Handle<String> hidden_symbol() {
400 return Handle<String>(&isolate()->heap()->hidden_symbol_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000401 }
402
Steve Block44f0eee2011-05-26 01:26:41 +0100403 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100404 Handle<String> name,
405 int number_of_literals,
406 Handle<Code> code,
Ben Murdoch85b71792012-04-11 18:30:58 +0100407 Handle<SerializedScopeInfo> scope_info);
Steve Block44f0eee2011-05-26 01:26:41 +0100408 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000409
Steve Block44f0eee2011-05-26 01:26:41 +0100410 Handle<JSMessageObject> NewJSMessageObject(
Steve Block1e0659c2011-05-24 12:43:12 +0100411 Handle<String> type,
412 Handle<JSArray> arguments,
413 int start_position,
414 int end_position,
415 Handle<Object> script,
416 Handle<Object> stack_trace,
417 Handle<Object> stack_frames);
418
Ben Murdochc7cc0282012-03-05 14:35:55 +0000419 Handle<SeededNumberDictionary> DictionaryAtNumberPut(
420 Handle<SeededNumberDictionary>,
421 uint32_t key,
422 Handle<Object> value);
423
424 Handle<UnseededNumberDictionary> DictionaryAtNumberPut(
425 Handle<UnseededNumberDictionary>,
Steve Blocka7e24c12009-10-30 11:49:00 +0000426 uint32_t key,
427 Handle<Object> value);
428
429#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100430 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000431#endif
432
433 // Return a map using the map cache in the global context.
434 // The key the an ordered set of property names.
Steve Block44f0eee2011-05-26 01:26:41 +0100435 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
436 Handle<FixedArray> keys);
Steve Blocka7e24c12009-10-30 11:49:00 +0000437
438 // Creates a new FixedArray that holds the data associated with the
439 // atom regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100440 void SetRegExpAtomData(Handle<JSRegExp> regexp,
441 JSRegExp::Type type,
442 Handle<String> source,
443 JSRegExp::Flags flags,
444 Handle<Object> match_pattern);
Steve Blocka7e24c12009-10-30 11:49:00 +0000445
446 // Creates a new FixedArray that holds the data associated with the
447 // irregexp regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100448 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
449 JSRegExp::Type type,
450 Handle<String> source,
451 JSRegExp::Flags flags,
452 int capture_count);
Steve Blocka7e24c12009-10-30 11:49:00 +0000453
454 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100455 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000456
Steve Block44f0eee2011-05-26 01:26:41 +0100457 Handle<JSFunction> NewFunctionHelper(Handle<String> name,
458 Handle<Object> prototype);
Steve Block6ded16b2010-05-10 14:33:55 +0100459
Steve Block44f0eee2011-05-26 01:26:41 +0100460 Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
461 Handle<String> name,
Ben Murdoch85b71792012-04-11 18:30:58 +0100462 StrictModeFlag strict_mode);
Steve Block44f0eee2011-05-26 01:26:41 +0100463
464 Handle<DescriptorArray> CopyAppendCallbackDescriptors(
Steve Blocka7e24c12009-10-30 11:49:00 +0000465 Handle<DescriptorArray> array,
466 Handle<Object> descriptors);
467
Steve Blocka7e24c12009-10-30 11:49:00 +0000468 // Create a new map cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100469 Handle<MapCache> NewMapCache(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +0000470
471 // Update the map cache in the global context with (keys, map)
Steve Block44f0eee2011-05-26 01:26:41 +0100472 Handle<MapCache> AddToMapCache(Handle<Context> context,
473 Handle<FixedArray> keys,
474 Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000475};
476
477
478} } // namespace v8::internal
479
480#endif // V8_FACTORY_H_