blob: 3b7ead534ecdbe51f9ea4630a304796bf1e573cf [file] [log] [blame]
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001// Copyright 2012 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.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +000053 Handle<FixedDoubleArray> NewFixedDoubleArray(
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +000054 int size,
55 PretenureFlag pretenure = NOT_TENURED);
56
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +000057 Handle<SeededNumberDictionary> NewSeededNumberDictionary(
58 int at_least_space_for);
59
60 Handle<UnseededNumberDictionary> NewUnseededNumberDictionary(
61 int at_least_space_for);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +000062
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000063 Handle<StringDictionary> NewStringDictionary(int at_least_space_for);
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000064
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +000065 Handle<ObjectHashSet> NewObjectHashSet(int at_least_space_for);
66
vegorov@chromium.org7943d462011-08-01 11:41:52 +000067 Handle<ObjectHashTable> NewObjectHashTable(int at_least_space_for);
68
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000069 Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors);
70 Handle<DeoptimizationInputData> NewDeoptimizationInputData(
kasperl@chromium.orga5551262010-12-07 12:49:48 +000071 int deopt_entry_count,
72 PretenureFlag pretenure);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000073 Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
kasperl@chromium.orga5551262010-12-07 12:49:48 +000074 int deopt_entry_count,
75 PretenureFlag pretenure);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +000076 // Allocates a pre-tenured empty AccessorPair.
77 Handle<AccessorPair> NewAccessorPair();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000078
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +000079 Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
80
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000081 Handle<String> LookupSymbol(Vector<const char> str);
danno@chromium.org40cb8782011-05-25 07:58:50 +000082 Handle<String> LookupSymbol(Handle<String> str);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000083 Handle<String> LookupAsciiSymbol(Vector<const char> str);
danno@chromium.org40cb8782011-05-25 07:58:50 +000084 Handle<String> LookupAsciiSymbol(Handle<SeqAsciiString>,
85 int from,
86 int length);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000087 Handle<String> LookupTwoByteSymbol(Vector<const uc16> str);
88 Handle<String> LookupAsciiSymbol(const char* str) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000115 Handle<String> NewStringFromAscii(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000121 Handle<String> NewStringFromUtf8(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000122 Vector<const char> str,
123 PretenureFlag pretenure = NOT_TENURED);
124
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000125 Handle<String> NewStringFromTwoByte(
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000126 Vector<const uc16> str,
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000127 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000128
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000129 // 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.
ager@chromium.org04921a82011-06-27 13:21:41 +0000132 Handle<SeqAsciiString> NewRawAsciiString(
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000133 int length,
134 PretenureFlag pretenure = NOT_TENURED);
ager@chromium.org04921a82011-06-27 13:21:41 +0000135 Handle<SeqTwoByteString> NewRawTwoByteString(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000136 int length,
137 PretenureFlag pretenure = NOT_TENURED);
138
139 // Create a new cons string object which consists of a pair of strings.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000140 Handle<String> NewConsString(Handle<String> first,
141 Handle<String> second);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000142
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000143 // Create a new string object which holds a substring of a string.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000144 Handle<String> NewSubString(Handle<String> str,
145 int begin,
146 int end);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000147
ager@chromium.org04921a82011-06-27 13:21:41 +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
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000157 Handle<String> NewExternalStringFromAscii(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000158 const ExternalAsciiString::Resource* resource);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000159 Handle<String> NewExternalStringFromTwoByte(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000160 const ExternalTwoByteString::Resource* resource);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000161
162 // Create a global (but otherwise uninitialized) context.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000163 Handle<Context> NewGlobalContext();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000164
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000165 // Create a module context.
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000166 Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000167
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000168 // Create a function context.
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000169 Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000170
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000171 // Create a catch context.
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000172 Handle<Context> NewCatchContext(Handle<JSFunction> function,
173 Handle<Context> previous,
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000174 Handle<String> name,
175 Handle<Object> thrown_object);
176
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000177 // Create a 'with' context.
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000178 Handle<Context> NewWithContext(Handle<JSFunction> function,
179 Handle<Context> previous,
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000180 Handle<JSObject> extension);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000181
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000182 // Create a block context.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000183 Handle<Context> NewBlockContext(Handle<JSFunction> function,
184 Handle<Context> previous,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000185 Handle<ScopeInfo> scope_info);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000186
ager@chromium.org32912102009-01-16 10:38:43 +0000187 // Return the Symbol matching the passed in string.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000188 Handle<String> SymbolFromString(Handle<String> value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000189
190 // Allocate a new struct. The struct is pretenured (allocated directly in
191 // the old generation).
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000192 Handle<Struct> NewStruct(InstanceType type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000193
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000194 Handle<AccessorInfo> NewAccessorInfo();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000195
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000196 Handle<Script> NewScript(Handle<String> source);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000197
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000198 // Foreign objects are pretenured when allocated by the bootstrapper.
199 Handle<Foreign> NewForeign(Address addr,
200 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000201
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000202 // Allocate a new foreign object. The foreign is pretenured (allocated
203 // directly in the old generation).
204 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000205
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000206 Handle<ByteArray> NewByteArray(int length,
207 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000208
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000209 Handle<ExternalArray> NewExternalArray(
ager@chromium.org3811b432009-10-28 14:53:37 +0000210 int length,
211 ExternalArrayType array_type,
212 void* external_pointer,
213 PretenureFlag pretenure = NOT_TENURED);
214
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000215 Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000216 Handle<Object> value);
217
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000218 Handle<Map> NewMap(
219 InstanceType type,
220 int instance_size,
221 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000222
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000223 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000224
rossberg@chromium.org657d53b2012-07-12 11:06:03 +0000225 Handle<Map> CopyWithPreallocatedFieldDescriptors(Handle<Map> map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000226
ager@chromium.org32912102009-01-16 10:38:43 +0000227 // Copy the map adding more inobject properties if possible without
228 // overflowing the instance size.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000229 Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
verwaest@chromium.org753aee42012-07-17 16:15:42 +0000230 Handle<Map> CopyMap(Handle<Map> map);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000231
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000232 Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
233 ElementsKind elements_kind);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +0000234
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000235 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000236
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000237 Handle<FixedDoubleArray> CopyFixedDoubleArray(
238 Handle<FixedDoubleArray> array);
239
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000240 // Numbers (e.g. literals) are pretenured by the parser.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000241 Handle<Object> NewNumber(double value,
242 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000243
erikcorry0ad885c2011-11-21 13:51:57 +0000244 Handle<Object> NewNumberFromInt(int32_t value,
245 PretenureFlag pretenure = NOT_TENURED);
246 Handle<Object> NewNumberFromUint(uint32_t value,
247 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000248
249 // These objects are used by the api to create env-independent data
250 // structures in the heap.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000251 Handle<JSObject> NewNeanderObject();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000252
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000253 Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000254
255 // JS objects are pretenured when allocated by the bootstrapper and
256 // runtime.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000257 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
258 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000259
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000260 // Global objects are pretenured.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000261 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000262
ager@chromium.org236ad962008-09-25 09:45:57 +0000263 // JS objects are pretenured when allocated by the bootstrapper and
264 // runtime.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000265 Handle<JSObject> NewJSObjectFromMap(Handle<Map> map);
ager@chromium.org236ad962008-09-25 09:45:57 +0000266
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000267 // JS modules are pretenured.
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000268 Handle<JSModule> NewJSModule(Handle<Context> context,
269 Handle<ScopeInfo> scope_info);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000270
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000271 // JS arrays are pretenured when allocated by the parser.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000272 Handle<JSArray> NewJSArray(
273 int capacity,
274 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
275 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000276
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000277 Handle<JSArray> NewJSArrayWithElements(
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000278 Handle<FixedArrayBase> elements,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000279 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000280 PretenureFlag pretenure = NOT_TENURED);
281
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000282 void SetElementsCapacityAndLength(Handle<JSArray> array,
283 int capacity,
284 int length);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000285
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000286 void SetContent(Handle<JSArray> array, Handle<FixedArrayBase> elements);
287
288 void EnsureCanContainHeapObjectElements(Handle<JSArray> array);
289 void EnsureCanContainElements(Handle<JSArray> array,
290 Handle<FixedArrayBase> elements,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000291 uint32_t length,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000292 EnsureElementsMode mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000293
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000294 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
295
lrn@chromium.org34e60782011-09-15 07:25:40 +0000296 // Change the type of the argument into a JS object/function and reinitialize.
297 void BecomeJSObject(Handle<JSReceiver> object);
298 void BecomeJSFunction(Handle<JSReceiver> object);
rossberg@chromium.org717967f2011-07-20 13:44:42 +0000299
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000300 void SetIdentityHash(Handle<JSObject> object, Object* hash);
301
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000302 Handle<JSFunction> NewFunction(Handle<String> name,
303 Handle<Object> prototype);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000304
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000305 Handle<JSFunction> NewFunctionWithoutPrototype(
306 Handle<String> name,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000307 LanguageMode language_mode);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000308
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000309 Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000310
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000311 Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000312 Handle<SharedFunctionInfo> function_info,
313 Handle<Map> function_map,
314 PretenureFlag pretenure);
315
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000316 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000317 Handle<SharedFunctionInfo> function_info,
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000318 Handle<Context> context,
319 PretenureFlag pretenure = TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000320
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000321 Handle<ScopeInfo> NewScopeInfo(int length);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000322
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000323 Handle<Code> NewCode(const CodeDesc& desc,
324 Code::Flags flags,
325 Handle<Object> self_reference,
326 bool immovable = false);
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000327
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000328 Handle<Code> CopyCode(Handle<Code> code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000329
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000330 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000331
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000332 Handle<Object> ToObject(Handle<Object> object);
333 Handle<Object> ToObject(Handle<Object> object,
334 Handle<Context> global_context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000335
336 // Interface for creating error objects.
337
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000338 Handle<Object> NewError(const char* maker, const char* type,
339 Handle<JSArray> args);
verwaest@chromium.org37141392012-05-31 13:27:02 +0000340 Handle<String> EmergencyNewError(const char* type, Handle<JSArray> args);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000341 Handle<Object> NewError(const char* maker, const char* type,
342 Vector< Handle<Object> > args);
343 Handle<Object> NewError(const char* type,
344 Vector< Handle<Object> > args);
345 Handle<Object> NewError(Handle<String> message);
346 Handle<Object> NewError(const char* constructor,
347 Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000348
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000349 Handle<Object> NewTypeError(const char* type,
350 Vector< Handle<Object> > args);
351 Handle<Object> NewTypeError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000352
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000353 Handle<Object> NewRangeError(const char* type,
354 Vector< Handle<Object> > args);
355 Handle<Object> NewRangeError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000356
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000357 Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
358 Handle<Object> NewSyntaxError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000359
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000360 Handle<Object> NewReferenceError(const char* type,
361 Vector< Handle<Object> > args);
362 Handle<Object> NewReferenceError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000363
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000364 Handle<Object> NewEvalError(const char* type,
365 Vector< Handle<Object> > args);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000366
367
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000368 Handle<JSFunction> NewFunction(Handle<String> name,
369 InstanceType type,
370 int instance_size,
371 Handle<Code> code,
372 bool force_initial_map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000373
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000374 Handle<JSFunction> NewFunction(Handle<Map> function_map,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000375 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
376
377
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000378 Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
379 InstanceType type,
380 int instance_size,
381 Handle<JSObject> prototype,
382 Handle<Code> code,
383 bool force_initial_map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000384
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000385 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
386 Handle<Code> code);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000387
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000388 Handle<DescriptorArray> CopyAppendForeignDescriptor(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000389 Handle<DescriptorArray> array,
390 Handle<String> key,
391 Handle<Object> value,
392 PropertyAttributes attributes);
393
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000394 Handle<String> NumberToString(Handle<Object> number);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000395 Handle<String> Uint32ToString(uint32_t value);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000396
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000397 enum ApiInstanceType {
398 JavaScriptObject,
399 InnerGlobalObject,
400 OuterGlobalObject
401 };
402
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000403 Handle<JSFunction> CreateApiFunction(
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000404 Handle<FunctionTemplateInfo> data,
405 ApiInstanceType type = JavaScriptObject);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000406
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000407 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000408
409 // Installs interceptors on the instance. 'desc' is a function template,
410 // and instance is an object instance created by the function of this
ager@chromium.org32912102009-01-16 10:38:43 +0000411 // function template.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000412 void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
413 Handle<JSObject> instance,
414 bool* pending_exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000415
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000416#define ROOT_ACCESSOR(type, name, camel_name) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000417 inline Handle<type> name() { \
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000418 return Handle<type>(BitCast<type**>( \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000419 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000420 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000421 ROOT_LIST(ROOT_ACCESSOR)
422#undef ROOT_ACCESSOR_ACCESSOR
423
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000424#define SYMBOL_ACCESSOR(name, str) \
425 inline Handle<String> name() { \
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000426 return Handle<String>(BitCast<String**>( \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000427 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000428 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000429 SYMBOL_LIST(SYMBOL_ACCESSOR)
430#undef SYMBOL_ACCESSOR
431
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000432 Handle<String> hidden_symbol() {
433 return Handle<String>(&isolate()->heap()->hidden_symbol_);
ager@chromium.org3b45ab52009-03-19 22:21:34 +0000434 }
435
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000436 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000437 Handle<String> name,
438 int number_of_literals,
439 Handle<Code> code,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000440 Handle<ScopeInfo> scope_info);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000441 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000442
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000443 Handle<JSMessageObject> NewJSMessageObject(
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000444 Handle<String> type,
445 Handle<JSArray> arguments,
446 int start_position,
447 int end_position,
448 Handle<Object> script,
449 Handle<Object> stack_trace,
450 Handle<Object> stack_frames);
451
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000452 Handle<SeededNumberDictionary> DictionaryAtNumberPut(
453 Handle<SeededNumberDictionary>,
454 uint32_t key,
455 Handle<Object> value);
456
457 Handle<UnseededNumberDictionary> DictionaryAtNumberPut(
458 Handle<UnseededNumberDictionary>,
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000459 uint32_t key,
460 Handle<Object> value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000461
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000462#ifdef ENABLE_DEBUGGER_SUPPORT
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000463 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000464#endif
ager@chromium.org236ad962008-09-25 09:45:57 +0000465
466 // Return a map using the map cache in the global context.
467 // The key the an ordered set of property names.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000468 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
469 Handle<FixedArray> keys);
ager@chromium.org236ad962008-09-25 09:45:57 +0000470
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000471 // Creates a new FixedArray that holds the data associated with the
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000472 // atom regexp and stores it in the regexp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000473 void SetRegExpAtomData(Handle<JSRegExp> regexp,
474 JSRegExp::Type type,
475 Handle<String> source,
476 JSRegExp::Flags flags,
477 Handle<Object> match_pattern);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000478
479 // Creates a new FixedArray that holds the data associated with the
480 // irregexp regexp and stores it in the regexp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000481 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
482 JSRegExp::Type type,
483 Handle<String> source,
484 JSRegExp::Flags flags,
485 int capture_count);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000486
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000487 // Returns the value for a known global constant (a property of the global
488 // object which is neither configurable nor writable) like 'undefined'.
489 // Returns a null handle when the given name is unknown.
490 Handle<Object> GlobalConstantFor(Handle<String> name);
491
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000492 // Converts the given boolean condition to JavaScript boolean value.
493 Handle<Object> ToBoolean(bool value);
494
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000495 private:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000496 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000497
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000498 Handle<JSFunction> NewFunctionHelper(Handle<String> name,
499 Handle<Object> prototype);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000500
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000501 Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
502 Handle<String> name,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000503 LanguageMode language_mode);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000504
505 Handle<DescriptorArray> CopyAppendCallbackDescriptors(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000506 Handle<DescriptorArray> array,
507 Handle<Object> descriptors);
508
ager@chromium.org236ad962008-09-25 09:45:57 +0000509 // Create a new map cache.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000510 Handle<MapCache> NewMapCache(int at_least_space_for);
ager@chromium.org236ad962008-09-25 09:45:57 +0000511
512 // Update the map cache in the global context with (keys, map)
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000513 Handle<MapCache> AddToMapCache(Handle<Context> context,
514 Handle<FixedArray> keys,
515 Handle<Map> map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000516};
517
518
519} } // namespace v8::internal
520
521#endif // V8_FACTORY_H_