blob: 55d1e9a174550ced4914035086a9eeec33540feb [file] [log] [blame]
Ben Murdochb0fe1622011-05-05 13:52:32 +01001// Copyright 2010 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:
42 // Allocate a new fixed array with undefined entries.
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
Steve Block44f0eee2011-05-26 01:26:41 +010052 Handle<NumberDictionary> NewNumberDictionary(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +000053
Steve Block44f0eee2011-05-26 01:26:41 +010054 Handle<StringDictionary> NewStringDictionary(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +000055
Steve Block44f0eee2011-05-26 01:26:41 +010056 Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors);
57 Handle<DeoptimizationInputData> NewDeoptimizationInputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010058 int deopt_entry_count,
59 PretenureFlag pretenure);
Steve Block44f0eee2011-05-26 01:26:41 +010060 Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010061 int deopt_entry_count,
62 PretenureFlag pretenure);
Steve Blocka7e24c12009-10-30 11:49:00 +000063
Steve Block44f0eee2011-05-26 01:26:41 +010064 Handle<String> LookupSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000065 Handle<String> LookupSymbol(Handle<String> str);
Steve Block44f0eee2011-05-26 01:26:41 +010066 Handle<String> LookupAsciiSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000067 Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>,
68 int from,
69 int length);
Steve Block44f0eee2011-05-26 01:26:41 +010070 Handle<String> LookupTwoByteSymbol(Vector<const uc16> str);
71 Handle<String> LookupAsciiSymbol(const char* str) {
Steve Blocka7e24c12009-10-30 11:49:00 +000072 return LookupSymbol(CStrVector(str));
73 }
74
75
76 // String creation functions. Most of the string creation functions take
77 // a Heap::PretenureFlag argument to optionally request that they be
78 // allocated in the old generation. The pretenure flag defaults to
79 // DONT_TENURE.
80 //
81 // Creates a new String object. There are two String encodings: ASCII and
82 // two byte. One should choose between the three string factory functions
83 // based on the encoding of the string buffer that the string is
84 // initialized from.
85 // - ...FromAscii initializes the string from a buffer that is ASCII
86 // encoded (it does not check that the buffer is ASCII encoded) and
87 // the result will be ASCII encoded.
88 // - ...FromUtf8 initializes the string from a buffer that is UTF-8
89 // encoded. If the characters are all single-byte characters, the
90 // result will be ASCII encoded, otherwise it will converted to two
91 // byte.
92 // - ...FromTwoByte initializes the string from a buffer that is two
93 // byte encoded. If the characters are all single-byte characters,
94 // the result will be converted to ASCII, otherwise it will be left as
95 // two byte.
96 //
97 // ASCII strings are pretenured when used as keys in the SourceCodeCache.
Steve Block44f0eee2011-05-26 01:26:41 +010098 Handle<String> NewStringFromAscii(
Steve Blocka7e24c12009-10-30 11:49:00 +000099 Vector<const char> str,
100 PretenureFlag pretenure = NOT_TENURED);
101
102 // UTF8 strings are pretenured when used for regexp literal patterns and
103 // flags in the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100104 Handle<String> NewStringFromUtf8(
Steve Blocka7e24c12009-10-30 11:49:00 +0000105 Vector<const char> str,
106 PretenureFlag pretenure = NOT_TENURED);
107
Steve Block44f0eee2011-05-26 01:26:41 +0100108 Handle<String> NewStringFromTwoByte(
Leon Clarkeac952652010-07-15 11:15:24 +0100109 Vector<const uc16> str,
Steve Blocka7e24c12009-10-30 11:49:00 +0000110 PretenureFlag pretenure = NOT_TENURED);
111
Leon Clarkeac952652010-07-15 11:15:24 +0100112 // Allocates and partially initializes an ASCII or TwoByte String. The
113 // characters of the string are uninitialized. Currently used in regexp code
114 // only, where they are pretenured.
Steve Block44f0eee2011-05-26 01:26:41 +0100115 Handle<String> NewRawAsciiString(
Leon Clarkeac952652010-07-15 11:15:24 +0100116 int length,
117 PretenureFlag pretenure = NOT_TENURED);
Steve Block44f0eee2011-05-26 01:26:41 +0100118 Handle<String> NewRawTwoByteString(
Steve Blocka7e24c12009-10-30 11:49:00 +0000119 int length,
120 PretenureFlag pretenure = NOT_TENURED);
121
122 // Create a new cons string object which consists of a pair of strings.
Steve Block44f0eee2011-05-26 01:26:41 +0100123 Handle<String> NewConsString(Handle<String> first,
124 Handle<String> second);
Steve Blocka7e24c12009-10-30 11:49:00 +0000125
Steve Blockd0582a62009-12-15 09:54:21 +0000126 // Create a new string object which holds a substring of a string.
Steve Block44f0eee2011-05-26 01:26:41 +0100127 Handle<String> NewSubString(Handle<String> str,
128 int begin,
129 int end);
Steve Blocka7e24c12009-10-30 11:49:00 +0000130
131 // Creates a new external String object. There are two String encodings
132 // in the system: ASCII and two byte. Unlike other String types, it does
133 // not make sense to have a UTF-8 factory function for external strings,
134 // because we cannot change the underlying buffer.
Steve Block44f0eee2011-05-26 01:26:41 +0100135 Handle<String> NewExternalStringFromAscii(
Steve Blocka7e24c12009-10-30 11:49:00 +0000136 ExternalAsciiString::Resource* resource);
Steve Block44f0eee2011-05-26 01:26:41 +0100137 Handle<String> NewExternalStringFromTwoByte(
Steve Blocka7e24c12009-10-30 11:49:00 +0000138 ExternalTwoByteString::Resource* resource);
139
140 // Create a global (but otherwise uninitialized) context.
Steve Block44f0eee2011-05-26 01:26:41 +0100141 Handle<Context> NewGlobalContext();
Steve Blocka7e24c12009-10-30 11:49:00 +0000142
143 // Create a function context.
Steve Block44f0eee2011-05-26 01:26:41 +0100144 Handle<Context> NewFunctionContext(int length,
145 Handle<JSFunction> closure);
Steve Blocka7e24c12009-10-30 11:49:00 +0000146
147 // Create a 'with' context.
Steve Block44f0eee2011-05-26 01:26:41 +0100148 Handle<Context> NewWithContext(Handle<Context> previous,
149 Handle<JSObject> extension,
150 bool is_catch_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000151
152 // Return the Symbol matching the passed in string.
Steve Block44f0eee2011-05-26 01:26:41 +0100153 Handle<String> SymbolFromString(Handle<String> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000154
155 // Allocate a new struct. The struct is pretenured (allocated directly in
156 // the old generation).
Steve Block44f0eee2011-05-26 01:26:41 +0100157 Handle<Struct> NewStruct(InstanceType type);
Steve Blocka7e24c12009-10-30 11:49:00 +0000158
Steve Block44f0eee2011-05-26 01:26:41 +0100159 Handle<AccessorInfo> NewAccessorInfo();
Steve Blocka7e24c12009-10-30 11:49:00 +0000160
Steve Block44f0eee2011-05-26 01:26:41 +0100161 Handle<Script> NewScript(Handle<String> source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000162
Ben Murdoch257744e2011-11-30 15:57:28 +0000163 // Foreign objects are pretenured when allocated by the bootstrapper.
164 Handle<Foreign> NewForeign(Address addr,
165 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000166
Ben Murdoch257744e2011-11-30 15:57:28 +0000167 // Allocate a new foreign object. The foreign is pretenured (allocated
168 // directly in the old generation).
169 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
Steve Blocka7e24c12009-10-30 11:49:00 +0000170
Steve Block44f0eee2011-05-26 01:26:41 +0100171 Handle<ByteArray> NewByteArray(int length,
172 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000173
Steve Block44f0eee2011-05-26 01:26:41 +0100174 Handle<ExternalArray> NewExternalArray(
Steve Block3ce2e202009-11-05 08:53:23 +0000175 int length,
176 ExternalArrayType array_type,
177 void* external_pointer,
178 PretenureFlag pretenure = NOT_TENURED);
179
Steve Block44f0eee2011-05-26 01:26:41 +0100180 Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
Ben Murdochb0fe1622011-05-05 13:52:32 +0100181 Handle<Object> value);
182
Steve Block44f0eee2011-05-26 01:26:41 +0100183 Handle<Map> NewMap(InstanceType type, int instance_size);
Steve Blocka7e24c12009-10-30 11:49:00 +0000184
Steve Block44f0eee2011-05-26 01:26:41 +0100185 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000186
Steve Block44f0eee2011-05-26 01:26:41 +0100187 Handle<Map> CopyMapDropDescriptors(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000188
189 // Copy the map adding more inobject properties if possible without
190 // overflowing the instance size.
Steve Block44f0eee2011-05-26 01:26:41 +0100191 Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
Steve Blocka7e24c12009-10-30 11:49:00 +0000192
Steve Block44f0eee2011-05-26 01:26:41 +0100193 Handle<Map> CopyMapDropTransitions(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000194
Steve Block44f0eee2011-05-26 01:26:41 +0100195 Handle<Map> GetFastElementsMap(Handle<Map> map);
Steve Block8defd9f2010-07-08 12:39:36 +0100196
Steve Block44f0eee2011-05-26 01:26:41 +0100197 Handle<Map> GetSlowElementsMap(Handle<Map> map);
Steve Block8defd9f2010-07-08 12:39:36 +0100198
Steve Block44f0eee2011-05-26 01:26:41 +0100199 Handle<Map> GetExternalArrayElementsMap(Handle<Map> map,
200 ExternalArrayType array_type,
201 bool safe_to_add_transition);
Steve Block1e0659c2011-05-24 12:43:12 +0100202
Steve Block44f0eee2011-05-26 01:26:41 +0100203 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
Steve Blocka7e24c12009-10-30 11:49:00 +0000204
205 // Numbers (eg, literals) are pretenured by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100206 Handle<Object> NewNumber(double value,
207 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000208
Steve Block44f0eee2011-05-26 01:26:41 +0100209 Handle<Object> NewNumberFromInt(int value);
210 Handle<Object> NewNumberFromUint(uint32_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000211
212 // These objects are used by the api to create env-independent data
213 // structures in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100214 Handle<JSObject> NewNeanderObject();
Steve Blocka7e24c12009-10-30 11:49:00 +0000215
Steve Block44f0eee2011-05-26 01:26:41 +0100216 Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
Steve Blocka7e24c12009-10-30 11:49:00 +0000217
218 // JS objects are pretenured when allocated by the bootstrapper and
219 // runtime.
Steve Block44f0eee2011-05-26 01:26:41 +0100220 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
221 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000222
223 // Global objects are pretenured.
Steve Block44f0eee2011-05-26 01:26:41 +0100224 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
Steve Blocka7e24c12009-10-30 11:49:00 +0000225
226 // JS objects are pretenured when allocated by the bootstrapper and
227 // runtime.
Steve Block44f0eee2011-05-26 01:26:41 +0100228 Handle<JSObject> NewJSObjectFromMap(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000229
230 // JS arrays are pretenured when allocated by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100231 Handle<JSArray> NewJSArray(int capacity,
232 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000233
Steve Block44f0eee2011-05-26 01:26:41 +0100234 Handle<JSArray> NewJSArrayWithElements(
Steve Blocka7e24c12009-10-30 11:49:00 +0000235 Handle<FixedArray> elements,
236 PretenureFlag pretenure = NOT_TENURED);
237
Ben Murdoch257744e2011-11-30 15:57:28 +0000238 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
239
Steve Block44f0eee2011-05-26 01:26:41 +0100240 Handle<JSFunction> NewFunction(Handle<String> name,
241 Handle<Object> prototype);
Steve Blocka7e24c12009-10-30 11:49:00 +0000242
Steve Block44f0eee2011-05-26 01:26:41 +0100243 Handle<JSFunction> NewFunctionWithoutPrototype(
244 Handle<String> name,
245 StrictModeFlag strict_mode);
Steve Block6ded16b2010-05-10 14:33:55 +0100246
Steve Block44f0eee2011-05-26 01:26:41 +0100247 Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
Steve Blocka7e24c12009-10-30 11:49:00 +0000248
Steve Block44f0eee2011-05-26 01:26:41 +0100249 Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100250 Handle<SharedFunctionInfo> function_info,
251 Handle<Map> function_map,
252 PretenureFlag pretenure);
253
Steve Block44f0eee2011-05-26 01:26:41 +0100254 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100255 Handle<SharedFunctionInfo> function_info,
Leon Clarkee46be812010-01-19 14:06:41 +0000256 Handle<Context> context,
257 PretenureFlag pretenure = TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000258
Steve Block44f0eee2011-05-26 01:26:41 +0100259 Handle<Code> NewCode(const CodeDesc& desc,
260 Code::Flags flags,
261 Handle<Object> self_reference,
262 bool immovable = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000263
Steve Block44f0eee2011-05-26 01:26:41 +0100264 Handle<Code> CopyCode(Handle<Code> code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000265
Steve Block44f0eee2011-05-26 01:26:41 +0100266 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
Steve Block6ded16b2010-05-10 14:33:55 +0100267
Steve Block44f0eee2011-05-26 01:26:41 +0100268 Handle<Object> ToObject(Handle<Object> object);
269 Handle<Object> ToObject(Handle<Object> object,
270 Handle<Context> global_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000271
272 // Interface for creating error objects.
273
Steve Block44f0eee2011-05-26 01:26:41 +0100274 Handle<Object> NewError(const char* maker, const char* type,
275 Handle<JSArray> args);
276 Handle<Object> NewError(const char* maker, const char* type,
277 Vector< Handle<Object> > args);
278 Handle<Object> NewError(const char* type,
279 Vector< Handle<Object> > args);
280 Handle<Object> NewError(Handle<String> message);
281 Handle<Object> NewError(const char* constructor,
282 Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000283
Steve Block44f0eee2011-05-26 01:26:41 +0100284 Handle<Object> NewTypeError(const char* type,
285 Vector< Handle<Object> > args);
286 Handle<Object> NewTypeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000287
Steve Block44f0eee2011-05-26 01:26:41 +0100288 Handle<Object> NewRangeError(const char* type,
289 Vector< Handle<Object> > args);
290 Handle<Object> NewRangeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000291
Steve Block44f0eee2011-05-26 01:26:41 +0100292 Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
293 Handle<Object> NewSyntaxError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000294
Steve Block44f0eee2011-05-26 01:26:41 +0100295 Handle<Object> NewReferenceError(const char* type,
296 Vector< Handle<Object> > args);
297 Handle<Object> NewReferenceError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000298
Steve Block44f0eee2011-05-26 01:26:41 +0100299 Handle<Object> NewEvalError(const char* type,
300 Vector< Handle<Object> > args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000301
302
Steve Block44f0eee2011-05-26 01:26:41 +0100303 Handle<JSFunction> NewFunction(Handle<String> name,
304 InstanceType type,
305 int instance_size,
306 Handle<Code> code,
307 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000308
Steve Block44f0eee2011-05-26 01:26:41 +0100309 Handle<JSFunction> NewFunction(Handle<Map> function_map,
Steve Blocka7e24c12009-10-30 11:49:00 +0000310 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
311
312
Steve Block44f0eee2011-05-26 01:26:41 +0100313 Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
314 InstanceType type,
315 int instance_size,
316 Handle<JSObject> prototype,
317 Handle<Code> code,
318 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000319
Steve Block44f0eee2011-05-26 01:26:41 +0100320 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
321 Handle<Code> code);
Steve Block6ded16b2010-05-10 14:33:55 +0100322
Ben Murdoch257744e2011-11-30 15:57:28 +0000323 Handle<DescriptorArray> CopyAppendForeignDescriptor(
Steve Blocka7e24c12009-10-30 11:49:00 +0000324 Handle<DescriptorArray> array,
325 Handle<String> key,
326 Handle<Object> value,
327 PropertyAttributes attributes);
328
Steve Block44f0eee2011-05-26 01:26:41 +0100329 Handle<String> NumberToString(Handle<Object> number);
Steve Blocka7e24c12009-10-30 11:49:00 +0000330
331 enum ApiInstanceType {
332 JavaScriptObject,
333 InnerGlobalObject,
334 OuterGlobalObject
335 };
336
Steve Block44f0eee2011-05-26 01:26:41 +0100337 Handle<JSFunction> CreateApiFunction(
Steve Blocka7e24c12009-10-30 11:49:00 +0000338 Handle<FunctionTemplateInfo> data,
339 ApiInstanceType type = JavaScriptObject);
340
Steve Block44f0eee2011-05-26 01:26:41 +0100341 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000342
343 // Installs interceptors on the instance. 'desc' is a function template,
344 // and instance is an object instance created by the function of this
345 // function template.
Steve Block44f0eee2011-05-26 01:26:41 +0100346 void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
347 Handle<JSObject> instance,
348 bool* pending_exception);
Steve Blocka7e24c12009-10-30 11:49:00 +0000349
350#define ROOT_ACCESSOR(type, name, camel_name) \
Steve Block44f0eee2011-05-26 01:26:41 +0100351 inline Handle<type> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100352 return Handle<type>(BitCast<type**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100353 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000354 }
355 ROOT_LIST(ROOT_ACCESSOR)
356#undef ROOT_ACCESSOR_ACCESSOR
357
Steve Block44f0eee2011-05-26 01:26:41 +0100358#define SYMBOL_ACCESSOR(name, str) \
359 inline Handle<String> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100360 return Handle<String>(BitCast<String**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100361 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000362 }
363 SYMBOL_LIST(SYMBOL_ACCESSOR)
364#undef SYMBOL_ACCESSOR
365
Steve Block44f0eee2011-05-26 01:26:41 +0100366 Handle<String> hidden_symbol() {
367 return Handle<String>(&isolate()->heap()->hidden_symbol_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000368 }
369
Steve Block44f0eee2011-05-26 01:26:41 +0100370 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100371 Handle<String> name,
372 int number_of_literals,
373 Handle<Code> code,
374 Handle<SerializedScopeInfo> scope_info);
Steve Block44f0eee2011-05-26 01:26:41 +0100375 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000376
Steve Block44f0eee2011-05-26 01:26:41 +0100377 Handle<JSMessageObject> NewJSMessageObject(
Steve Block1e0659c2011-05-24 12:43:12 +0100378 Handle<String> type,
379 Handle<JSArray> arguments,
380 int start_position,
381 int end_position,
382 Handle<Object> script,
383 Handle<Object> stack_trace,
384 Handle<Object> stack_frames);
385
Steve Block44f0eee2011-05-26 01:26:41 +0100386 Handle<NumberDictionary> DictionaryAtNumberPut(
Steve Blocka7e24c12009-10-30 11:49:00 +0000387 Handle<NumberDictionary>,
388 uint32_t key,
389 Handle<Object> value);
390
391#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100392 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000393#endif
394
395 // Return a map using the map cache in the global context.
396 // The key the an ordered set of property names.
Steve Block44f0eee2011-05-26 01:26:41 +0100397 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
398 Handle<FixedArray> keys);
Steve Blocka7e24c12009-10-30 11:49:00 +0000399
400 // Creates a new FixedArray that holds the data associated with the
401 // atom regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100402 void SetRegExpAtomData(Handle<JSRegExp> regexp,
403 JSRegExp::Type type,
404 Handle<String> source,
405 JSRegExp::Flags flags,
406 Handle<Object> match_pattern);
Steve Blocka7e24c12009-10-30 11:49:00 +0000407
408 // Creates a new FixedArray that holds the data associated with the
409 // irregexp regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100410 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
411 JSRegExp::Type type,
412 Handle<String> source,
413 JSRegExp::Flags flags,
414 int capture_count);
Steve Blocka7e24c12009-10-30 11:49:00 +0000415
416 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100417 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000418
Steve Block44f0eee2011-05-26 01:26:41 +0100419 Handle<JSFunction> NewFunctionHelper(Handle<String> name,
420 Handle<Object> prototype);
Steve Block6ded16b2010-05-10 14:33:55 +0100421
Steve Block44f0eee2011-05-26 01:26:41 +0100422 Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
423 Handle<String> name,
424 StrictModeFlag strict_mode);
425
426 Handle<DescriptorArray> CopyAppendCallbackDescriptors(
Steve Blocka7e24c12009-10-30 11:49:00 +0000427 Handle<DescriptorArray> array,
428 Handle<Object> descriptors);
429
Steve Blocka7e24c12009-10-30 11:49:00 +0000430 // Create a new map cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100431 Handle<MapCache> NewMapCache(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +0000432
433 // Update the map cache in the global context with (keys, map)
Steve Block44f0eee2011-05-26 01:26:41 +0100434 Handle<MapCache> AddToMapCache(Handle<Context> context,
435 Handle<FixedArray> keys,
436 Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000437};
438
439
440} } // namespace v8::internal
441
442#endif // V8_FACTORY_H_