blob: 786d4a983a4d6bba856337956474aac509e812e1 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 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 Murdoch3ef787d2012-04-12 10:51:47 +010053 Handle<FixedDoubleArray> 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 Murdoch3ef787d2012-04-12 10:51:47 +010065 Handle<ObjectHashSet> NewObjectHashSet(int at_least_space_for);
66
Ben Murdoch69a99ed2011-11-30 16:03:39 +000067 Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for);
68
Steve Block44f0eee2011-05-26 01:26:41 +010069 Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors);
70 Handle<DeoptimizationInputData> NewDeoptimizationInputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010071 int deopt_entry_count,
72 PretenureFlag pretenure);
Steve Block44f0eee2011-05-26 01:26:41 +010073 Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
Ben Murdochb0fe1622011-05-05 13:52:32 +010074 int deopt_entry_count,
75 PretenureFlag pretenure);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010076 // Allocates a pre-tenured empty AccessorPair.
77 Handle<AccessorPair> NewAccessorPair();
78
79 Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +010080
Steve Block44f0eee2011-05-26 01:26:41 +010081 Handle<String> LookupSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000082 Handle<String> LookupSymbol(Handle<String> str);
Steve Block44f0eee2011-05-26 01:26:41 +010083 Handle<String> LookupAsciiSymbol(Vector<const char> str);
Ben Murdoch257744e2011-11-30 15:57:28 +000084 Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>,
85 int from,
86 int length);
Steve Block44f0eee2011-05-26 01:26:41 +010087 Handle<String> LookupTwoByteSymbol(Vector<const uc16> str);
88 Handle<String> LookupAsciiSymbol(const char* str) {
Steve Blocka7e24c12009-10-30 11:49:00 +000089 return LookupSymbol(CStrVector(str));
90 }
91
92
93 // String creation functions. Most of the string creation functions take
94 // a Heap::PretenureFlag argument to optionally request that they be
95 // allocated in the old generation. The pretenure flag defaults to
96 // DONT_TENURE.
97 //
98 // Creates a new String object. There are two String encodings: ASCII and
99 // two byte. One should choose between the three string factory functions
100 // based on the encoding of the string buffer that the string is
101 // initialized from.
102 // - ...FromAscii initializes the string from a buffer that is ASCII
103 // encoded (it does not check that the buffer is ASCII encoded) and
104 // the result will be ASCII encoded.
105 // - ...FromUtf8 initializes the string from a buffer that is UTF-8
106 // encoded. If the characters are all single-byte characters, the
107 // result will be ASCII encoded, otherwise it will converted to two
108 // byte.
109 // - ...FromTwoByte initializes the string from a buffer that is two
110 // byte encoded. If the characters are all single-byte characters,
111 // the result will be converted to ASCII, otherwise it will be left as
112 // two byte.
113 //
114 // ASCII strings are pretenured when used as keys in the SourceCodeCache.
Steve Block44f0eee2011-05-26 01:26:41 +0100115 Handle<String> NewStringFromAscii(
Steve Blocka7e24c12009-10-30 11:49:00 +0000116 Vector<const char> str,
117 PretenureFlag pretenure = NOT_TENURED);
118
119 // UTF8 strings are pretenured when used for regexp literal patterns and
120 // flags in the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100121 Handle<String> NewStringFromUtf8(
Steve Blocka7e24c12009-10-30 11:49:00 +0000122 Vector<const char> str,
123 PretenureFlag pretenure = NOT_TENURED);
124
Steve Block44f0eee2011-05-26 01:26:41 +0100125 Handle<String> NewStringFromTwoByte(
Leon Clarkeac952652010-07-15 11:15:24 +0100126 Vector<const uc16> str,
Steve Blocka7e24c12009-10-30 11:49:00 +0000127 PretenureFlag pretenure = NOT_TENURED);
128
Leon Clarkeac952652010-07-15 11:15:24 +0100129 // Allocates and partially initializes an ASCII or TwoByte String. The
130 // characters of the string are uninitialized. Currently used in regexp code
131 // only, where they are pretenured.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000132 Handle<SeqAsciiString> NewRawAsciiString(
Leon Clarkeac952652010-07-15 11:15:24 +0100133 int length,
134 PretenureFlag pretenure = NOT_TENURED);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000135 Handle<SeqTwoByteString> NewRawTwoByteString(
Steve Blocka7e24c12009-10-30 11:49:00 +0000136 int length,
137 PretenureFlag pretenure = NOT_TENURED);
138
139 // Create a new cons string object which consists of a pair of strings.
Steve Block44f0eee2011-05-26 01:26:41 +0100140 Handle<String> NewConsString(Handle<String> first,
141 Handle<String> second);
Steve Blocka7e24c12009-10-30 11:49:00 +0000142
Steve Blockd0582a62009-12-15 09:54:21 +0000143 // Create a new string object which holds a substring of a string.
Steve Block44f0eee2011-05-26 01:26:41 +0100144 Handle<String> NewSubString(Handle<String> str,
145 int begin,
146 int end);
Steve Blocka7e24c12009-10-30 11:49:00 +0000147
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000148 // Create a new string object which holds a proper substring of a string.
149 Handle<String> NewProperSubString(Handle<String> str,
150 int begin,
151 int end);
152
Steve Blocka7e24c12009-10-30 11:49:00 +0000153 // Creates a new external String object. There are two String encodings
154 // in the system: ASCII and two byte. Unlike other String types, it does
155 // not make sense to have a UTF-8 factory function for external strings,
156 // because we cannot change the underlying buffer.
Steve Block44f0eee2011-05-26 01:26:41 +0100157 Handle<String> NewExternalStringFromAscii(
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100158 const ExternalAsciiString::Resource* resource);
Steve Block44f0eee2011-05-26 01:26:41 +0100159 Handle<String> NewExternalStringFromTwoByte(
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100160 const ExternalTwoByteString::Resource* resource);
Steve Blocka7e24c12009-10-30 11:49:00 +0000161
162 // Create a global (but otherwise uninitialized) context.
Steve Block44f0eee2011-05-26 01:26:41 +0100163 Handle<Context> NewGlobalContext();
Steve Blocka7e24c12009-10-30 11:49:00 +0000164
165 // Create a function context.
Steve Block44f0eee2011-05-26 01:26:41 +0100166 Handle<Context> NewFunctionContext(int length,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000167 Handle<JSFunction> function);
168
169 // Create a catch context.
170 Handle<Context> NewCatchContext(Handle<JSFunction> function,
171 Handle<Context> previous,
172 Handle<String> name,
173 Handle<Object> thrown_object);
Steve Blocka7e24c12009-10-30 11:49:00 +0000174
175 // Create a 'with' context.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000176 Handle<Context> NewWithContext(Handle<JSFunction> function,
177 Handle<Context> previous,
178 Handle<JSObject> extension);
Steve Blocka7e24c12009-10-30 11:49:00 +0000179
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000180 // Create a 'block' context.
181 Handle<Context> NewBlockContext(Handle<JSFunction> function,
182 Handle<Context> previous,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100183 Handle<ScopeInfo> scope_info);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000184
Steve Blocka7e24c12009-10-30 11:49:00 +0000185 // Return the Symbol matching the passed in string.
Steve Block44f0eee2011-05-26 01:26:41 +0100186 Handle<String> SymbolFromString(Handle<String> value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000187
188 // Allocate a new struct. The struct is pretenured (allocated directly in
189 // the old generation).
Steve Block44f0eee2011-05-26 01:26:41 +0100190 Handle<Struct> NewStruct(InstanceType type);
Steve Blocka7e24c12009-10-30 11:49:00 +0000191
Steve Block44f0eee2011-05-26 01:26:41 +0100192 Handle<AccessorInfo> NewAccessorInfo();
Steve Blocka7e24c12009-10-30 11:49:00 +0000193
Steve Block44f0eee2011-05-26 01:26:41 +0100194 Handle<Script> NewScript(Handle<String> source);
Steve Blocka7e24c12009-10-30 11:49:00 +0000195
Ben Murdoch257744e2011-11-30 15:57:28 +0000196 // Foreign objects are pretenured when allocated by the bootstrapper.
197 Handle<Foreign> NewForeign(Address addr,
198 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000199
Ben Murdoch257744e2011-11-30 15:57:28 +0000200 // Allocate a new foreign object. The foreign is pretenured (allocated
201 // directly in the old generation).
202 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
Steve Blocka7e24c12009-10-30 11:49:00 +0000203
Steve Block44f0eee2011-05-26 01:26:41 +0100204 Handle<ByteArray> NewByteArray(int length,
205 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000206
Steve Block44f0eee2011-05-26 01:26:41 +0100207 Handle<ExternalArray> NewExternalArray(
Steve Block3ce2e202009-11-05 08:53:23 +0000208 int length,
209 ExternalArrayType array_type,
210 void* external_pointer,
211 PretenureFlag pretenure = NOT_TENURED);
212
Steve Block44f0eee2011-05-26 01:26:41 +0100213 Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
Ben Murdochb0fe1622011-05-05 13:52:32 +0100214 Handle<Object> value);
215
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100216 Handle<Map> NewMap(InstanceType type,
217 int instance_size,
218 ElementsKind elements_kind = FAST_ELEMENTS);
Steve Blocka7e24c12009-10-30 11:49:00 +0000219
Steve Block44f0eee2011-05-26 01:26:41 +0100220 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000221
Steve Block44f0eee2011-05-26 01:26:41 +0100222 Handle<Map> CopyMapDropDescriptors(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000223
224 // Copy the map adding more inobject properties if possible without
225 // overflowing the instance size.
Steve Block44f0eee2011-05-26 01:26:41 +0100226 Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
Steve Blocka7e24c12009-10-30 11:49:00 +0000227
Steve Block44f0eee2011-05-26 01:26:41 +0100228 Handle<Map> CopyMapDropTransitions(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000229
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100230 Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
231 ElementsKind elements_kind);
Steve Block1e0659c2011-05-24 12:43:12 +0100232
Steve Block44f0eee2011-05-26 01:26:41 +0100233 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
Steve Blocka7e24c12009-10-30 11:49:00 +0000234
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100235 Handle<FixedDoubleArray> CopyFixedDoubleArray(
236 Handle<FixedDoubleArray> array);
237
238 // Numbers (e.g. literals) are pretenured by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100239 Handle<Object> NewNumber(double value,
240 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000241
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100242 Handle<Object> NewNumberFromInt(int32_t value,
243 PretenureFlag pretenure = NOT_TENURED);
244 Handle<Object> NewNumberFromUint(uint32_t value,
245 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000246
247 // These objects are used by the api to create env-independent data
248 // structures in the heap.
Steve Block44f0eee2011-05-26 01:26:41 +0100249 Handle<JSObject> NewNeanderObject();
Steve Blocka7e24c12009-10-30 11:49:00 +0000250
Steve Block44f0eee2011-05-26 01:26:41 +0100251 Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
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> NewJSObject(Handle<JSFunction> constructor,
256 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000257
258 // Global objects are pretenured.
Steve Block44f0eee2011-05-26 01:26:41 +0100259 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
Steve Blocka7e24c12009-10-30 11:49:00 +0000260
261 // JS objects are pretenured when allocated by the bootstrapper and
262 // runtime.
Steve Block44f0eee2011-05-26 01:26:41 +0100263 Handle<JSObject> NewJSObjectFromMap(Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000264
265 // JS arrays are pretenured when allocated by the parser.
Steve Block44f0eee2011-05-26 01:26:41 +0100266 Handle<JSArray> NewJSArray(int capacity,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100267 ElementsKind elements_kind = FAST_ELEMENTS,
Steve Block44f0eee2011-05-26 01:26:41 +0100268 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000269
Steve Block44f0eee2011-05-26 01:26:41 +0100270 Handle<JSArray> NewJSArrayWithElements(
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100271 Handle<FixedArrayBase> elements,
272 ElementsKind elements_kind = FAST_ELEMENTS,
Steve Blocka7e24c12009-10-30 11:49:00 +0000273 PretenureFlag pretenure = NOT_TENURED);
274
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100275 void SetElementsCapacityAndLength(Handle<JSArray> array,
276 int capacity,
277 int length);
278
279 void SetContent(Handle<JSArray> array, Handle<FixedArrayBase> elements);
280
281 void EnsureCanContainHeapObjectElements(Handle<JSArray> array);
282 void EnsureCanContainElements(Handle<JSArray> array,
283 Handle<FixedArrayBase> elements,
284 EnsureElementsMode mode);
285
Ben Murdoch257744e2011-11-30 15:57:28 +0000286 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
287
Ben Murdoch589d6972011-11-30 16:04:58 +0000288 // Change the type of the argument into a JS object/function and reinitialize.
289 void BecomeJSObject(Handle<JSReceiver> object);
290 void BecomeJSFunction(Handle<JSReceiver> object);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000291
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100292 void SetIdentityHash(Handle<JSObject> object, Object* hash);
293
Steve Block44f0eee2011-05-26 01:26:41 +0100294 Handle<JSFunction> NewFunction(Handle<String> name,
295 Handle<Object> prototype);
Steve Blocka7e24c12009-10-30 11:49:00 +0000296
Steve Block44f0eee2011-05-26 01:26:41 +0100297 Handle<JSFunction> NewFunctionWithoutPrototype(
298 Handle<String> name,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100299 LanguageMode language_mode);
Steve Block6ded16b2010-05-10 14:33:55 +0100300
Steve Block44f0eee2011-05-26 01:26:41 +0100301 Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
Steve Blocka7e24c12009-10-30 11:49:00 +0000302
Steve Block44f0eee2011-05-26 01:26:41 +0100303 Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100304 Handle<SharedFunctionInfo> function_info,
305 Handle<Map> function_map,
306 PretenureFlag pretenure);
307
Steve Block44f0eee2011-05-26 01:26:41 +0100308 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
Steve Block6ded16b2010-05-10 14:33:55 +0100309 Handle<SharedFunctionInfo> function_info,
Leon Clarkee46be812010-01-19 14:06:41 +0000310 Handle<Context> context,
311 PretenureFlag pretenure = TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +0000312
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100313 Handle<ScopeInfo> NewScopeInfo(int length);
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000314
Steve Block44f0eee2011-05-26 01:26:41 +0100315 Handle<Code> NewCode(const CodeDesc& desc,
316 Code::Flags flags,
317 Handle<Object> self_reference,
318 bool immovable = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000319
Steve Block44f0eee2011-05-26 01:26:41 +0100320 Handle<Code> CopyCode(Handle<Code> code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000321
Steve Block44f0eee2011-05-26 01:26:41 +0100322 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
Steve Block6ded16b2010-05-10 14:33:55 +0100323
Steve Block44f0eee2011-05-26 01:26:41 +0100324 Handle<Object> ToObject(Handle<Object> object);
325 Handle<Object> ToObject(Handle<Object> object,
326 Handle<Context> global_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000327
328 // Interface for creating error objects.
329
Steve Block44f0eee2011-05-26 01:26:41 +0100330 Handle<Object> NewError(const char* maker, const char* type,
331 Handle<JSArray> args);
332 Handle<Object> NewError(const char* maker, const char* type,
333 Vector< Handle<Object> > args);
334 Handle<Object> NewError(const char* type,
335 Vector< Handle<Object> > args);
336 Handle<Object> NewError(Handle<String> message);
337 Handle<Object> NewError(const char* constructor,
338 Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000339
Steve Block44f0eee2011-05-26 01:26:41 +0100340 Handle<Object> NewTypeError(const char* type,
341 Vector< Handle<Object> > args);
342 Handle<Object> NewTypeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000343
Steve Block44f0eee2011-05-26 01:26:41 +0100344 Handle<Object> NewRangeError(const char* type,
345 Vector< Handle<Object> > args);
346 Handle<Object> NewRangeError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000347
Steve Block44f0eee2011-05-26 01:26:41 +0100348 Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
349 Handle<Object> NewSyntaxError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000350
Steve Block44f0eee2011-05-26 01:26:41 +0100351 Handle<Object> NewReferenceError(const char* type,
352 Vector< Handle<Object> > args);
353 Handle<Object> NewReferenceError(Handle<String> message);
Steve Blocka7e24c12009-10-30 11:49:00 +0000354
Steve Block44f0eee2011-05-26 01:26:41 +0100355 Handle<Object> NewEvalError(const char* type,
356 Vector< Handle<Object> > args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000357
358
Steve Block44f0eee2011-05-26 01:26:41 +0100359 Handle<JSFunction> NewFunction(Handle<String> name,
360 InstanceType type,
361 int instance_size,
362 Handle<Code> code,
363 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000364
Steve Block44f0eee2011-05-26 01:26:41 +0100365 Handle<JSFunction> NewFunction(Handle<Map> function_map,
Steve Blocka7e24c12009-10-30 11:49:00 +0000366 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
367
368
Steve Block44f0eee2011-05-26 01:26:41 +0100369 Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
370 InstanceType type,
371 int instance_size,
372 Handle<JSObject> prototype,
373 Handle<Code> code,
374 bool force_initial_map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000375
Steve Block44f0eee2011-05-26 01:26:41 +0100376 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
377 Handle<Code> code);
Steve Block6ded16b2010-05-10 14:33:55 +0100378
Ben Murdoch257744e2011-11-30 15:57:28 +0000379 Handle<DescriptorArray> CopyAppendForeignDescriptor(
Steve Blocka7e24c12009-10-30 11:49:00 +0000380 Handle<DescriptorArray> array,
381 Handle<String> key,
382 Handle<Object> value,
383 PropertyAttributes attributes);
384
Steve Block44f0eee2011-05-26 01:26:41 +0100385 Handle<String> NumberToString(Handle<Object> number);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100386 Handle<String> Uint32ToString(uint32_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000387
388 enum ApiInstanceType {
389 JavaScriptObject,
390 InnerGlobalObject,
391 OuterGlobalObject
392 };
393
Steve Block44f0eee2011-05-26 01:26:41 +0100394 Handle<JSFunction> CreateApiFunction(
Steve Blocka7e24c12009-10-30 11:49:00 +0000395 Handle<FunctionTemplateInfo> data,
396 ApiInstanceType type = JavaScriptObject);
397
Steve Block44f0eee2011-05-26 01:26:41 +0100398 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +0000399
400 // Installs interceptors on the instance. 'desc' is a function template,
401 // and instance is an object instance created by the function of this
402 // function template.
Steve Block44f0eee2011-05-26 01:26:41 +0100403 void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
404 Handle<JSObject> instance,
405 bool* pending_exception);
Steve Blocka7e24c12009-10-30 11:49:00 +0000406
407#define ROOT_ACCESSOR(type, name, camel_name) \
Steve Block44f0eee2011-05-26 01:26:41 +0100408 inline Handle<type> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100409 return Handle<type>(BitCast<type**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100410 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000411 }
412 ROOT_LIST(ROOT_ACCESSOR)
413#undef ROOT_ACCESSOR_ACCESSOR
414
Steve Block44f0eee2011-05-26 01:26:41 +0100415#define SYMBOL_ACCESSOR(name, str) \
416 inline Handle<String> name() { \
Iain Merrick75681382010-08-19 15:07:18 +0100417 return Handle<String>(BitCast<String**>( \
Steve Block44f0eee2011-05-26 01:26:41 +0100418 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000419 }
420 SYMBOL_LIST(SYMBOL_ACCESSOR)
421#undef SYMBOL_ACCESSOR
422
Steve Block44f0eee2011-05-26 01:26:41 +0100423 Handle<String> hidden_symbol() {
424 return Handle<String>(&isolate()->heap()->hidden_symbol_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000425 }
426
Steve Block44f0eee2011-05-26 01:26:41 +0100427 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100428 Handle<String> name,
429 int number_of_literals,
430 Handle<Code> code,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100431 Handle<ScopeInfo> scope_info);
Steve Block44f0eee2011-05-26 01:26:41 +0100432 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
Steve Blocka7e24c12009-10-30 11:49:00 +0000433
Steve Block44f0eee2011-05-26 01:26:41 +0100434 Handle<JSMessageObject> NewJSMessageObject(
Steve Block1e0659c2011-05-24 12:43:12 +0100435 Handle<String> type,
436 Handle<JSArray> arguments,
437 int start_position,
438 int end_position,
439 Handle<Object> script,
440 Handle<Object> stack_trace,
441 Handle<Object> stack_frames);
442
Ben Murdochc7cc0282012-03-05 14:35:55 +0000443 Handle<SeededNumberDictionary> DictionaryAtNumberPut(
444 Handle<SeededNumberDictionary>,
445 uint32_t key,
446 Handle<Object> value);
447
448 Handle<UnseededNumberDictionary> DictionaryAtNumberPut(
449 Handle<UnseededNumberDictionary>,
Steve Blocka7e24c12009-10-30 11:49:00 +0000450 uint32_t key,
451 Handle<Object> value);
452
453#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100454 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
Steve Blocka7e24c12009-10-30 11:49:00 +0000455#endif
456
457 // Return a map using the map cache in the global context.
458 // The key the an ordered set of property names.
Steve Block44f0eee2011-05-26 01:26:41 +0100459 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
460 Handle<FixedArray> keys);
Steve Blocka7e24c12009-10-30 11:49:00 +0000461
462 // Creates a new FixedArray that holds the data associated with the
463 // atom regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100464 void SetRegExpAtomData(Handle<JSRegExp> regexp,
465 JSRegExp::Type type,
466 Handle<String> source,
467 JSRegExp::Flags flags,
468 Handle<Object> match_pattern);
Steve Blocka7e24c12009-10-30 11:49:00 +0000469
470 // Creates a new FixedArray that holds the data associated with the
471 // irregexp regexp and stores it in the regexp.
Steve Block44f0eee2011-05-26 01:26:41 +0100472 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
473 JSRegExp::Type type,
474 Handle<String> source,
475 JSRegExp::Flags flags,
476 int capture_count);
Steve Blocka7e24c12009-10-30 11:49:00 +0000477
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100478 // Returns the value for a known global constant (a property of the global
479 // object which is neither configurable nor writable) like 'undefined'.
480 // Returns a null handle when the given name is unknown.
481 Handle<Object> GlobalConstantFor(Handle<String> name);
482
483 // Converts the given boolean condition to JavaScript boolean value.
484 Handle<Object> ToBoolean(bool value);
485
Steve Blocka7e24c12009-10-30 11:49:00 +0000486 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100487 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000488
Steve Block44f0eee2011-05-26 01:26:41 +0100489 Handle<JSFunction> NewFunctionHelper(Handle<String> name,
490 Handle<Object> prototype);
Steve Block6ded16b2010-05-10 14:33:55 +0100491
Steve Block44f0eee2011-05-26 01:26:41 +0100492 Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
493 Handle<String> name,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100494 LanguageMode language_mode);
Steve Block44f0eee2011-05-26 01:26:41 +0100495
496 Handle<DescriptorArray> CopyAppendCallbackDescriptors(
Steve Blocka7e24c12009-10-30 11:49:00 +0000497 Handle<DescriptorArray> array,
498 Handle<Object> descriptors);
499
Steve Blocka7e24c12009-10-30 11:49:00 +0000500 // Create a new map cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100501 Handle<MapCache> NewMapCache(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +0000502
503 // Update the map cache in the global context with (keys, map)
Steve Block44f0eee2011-05-26 01:26:41 +0100504 Handle<MapCache> AddToMapCache(Handle<Context> context,
505 Handle<FixedArray> keys,
506 Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +0000507};
508
509
510} } // namespace v8::internal
511
512#endif // V8_FACTORY_H_