blob: 5e8970835b3d7dfc425496df4bc69bddaf42d804 [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
ulan@chromium.org750145a2013-03-07 15:14:13 +000063 Handle<NameDictionary> NewNameDictionary(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
verwaest@chromium.org33e09c82012-10-10 17:07:22 +000069 Handle<DescriptorArray> NewDescriptorArray(int number_of_descriptors,
70 int slack = 0);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000071 Handle<DeoptimizationInputData> NewDeoptimizationInputData(
kasperl@chromium.orga5551262010-12-07 12:49:48 +000072 int deopt_entry_count,
73 PretenureFlag pretenure);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000074 Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
kasperl@chromium.orga5551262010-12-07 12:49:48 +000075 int deopt_entry_count,
76 PretenureFlag pretenure);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +000077 // Allocates a pre-tenured empty AccessorPair.
78 Handle<AccessorPair> NewAccessorPair();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000079
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +000080 Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
81
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +000082 Handle<String> InternalizeUtf8String(Vector<const char> str);
83 Handle<String> InternalizeUtf8String(const char* str) {
84 return InternalizeUtf8String(CStrVector(str));
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +000085 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +000086 Handle<String> InternalizeString(Handle<String> str);
87 Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
88 Handle<String> InternalizeOneByteString(Handle<SeqOneByteString>,
danno@chromium.org40cb8782011-05-25 07:58:50 +000089 int from,
90 int length);
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +000091 Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000092
93
94 // String creation functions. Most of the string creation functions take
95 // a Heap::PretenureFlag argument to optionally request that they be
96 // allocated in the old generation. The pretenure flag defaults to
97 // DONT_TENURE.
98 //
99 // Creates a new String object. There are two String encodings: ASCII and
100 // two byte. One should choose between the three string factory functions
101 // based on the encoding of the string buffer that the string is
102 // initialized from.
103 // - ...FromAscii initializes the string from a buffer that is ASCII
104 // encoded (it does not check that the buffer is ASCII encoded) and
105 // the result will be ASCII encoded.
106 // - ...FromUtf8 initializes the string from a buffer that is UTF-8
107 // encoded. If the characters are all single-byte characters, the
108 // result will be ASCII encoded, otherwise it will converted to two
109 // byte.
110 // - ...FromTwoByte initializes the string from a buffer that is two
111 // byte encoded. If the characters are all single-byte characters,
112 // the result will be converted to ASCII, otherwise it will be left as
113 // two byte.
114 //
115 // ASCII strings are pretenured when used as keys in the SourceCodeCache.
jkummerow@chromium.org59297c72013-01-09 16:32:23 +0000116 Handle<String> NewStringFromOneByte(
117 Vector<const uint8_t> str,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000118 PretenureFlag pretenure = NOT_TENURED);
jkummerow@chromium.org59297c72013-01-09 16:32:23 +0000119 // TODO(dcarney): remove this function.
120 inline Handle<String> NewStringFromAscii(
121 Vector<const char> str,
122 PretenureFlag pretenure = NOT_TENURED) {
123 return NewStringFromOneByte(Vector<const uint8_t>::cast(str), pretenure);
124 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000125
126 // UTF8 strings are pretenured when used for regexp literal patterns and
127 // flags in the parser.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000128 Handle<String> NewStringFromUtf8(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000129 Vector<const char> str,
130 PretenureFlag pretenure = NOT_TENURED);
131
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000132 Handle<String> NewStringFromTwoByte(
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000133 Vector<const uc16> str,
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000134 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000135
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000136 // Allocates and partially initializes an ASCII or TwoByte String. The
137 // characters of the string are uninitialized. Currently used in regexp code
138 // only, where they are pretenured.
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000139 Handle<SeqOneByteString> NewRawOneByteString(
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000140 int length,
141 PretenureFlag pretenure = NOT_TENURED);
ager@chromium.org04921a82011-06-27 13:21:41 +0000142 Handle<SeqTwoByteString> NewRawTwoByteString(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000143 int length,
144 PretenureFlag pretenure = NOT_TENURED);
145
146 // Create a new cons string object which consists of a pair of strings.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000147 Handle<String> NewConsString(Handle<String> first,
148 Handle<String> second);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000149
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000150 // Create a new string object which holds a substring of a string.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000151 Handle<String> NewSubString(Handle<String> str,
152 int begin,
153 int end);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000154
ager@chromium.org04921a82011-06-27 13:21:41 +0000155 // Create a new string object which holds a proper substring of a string.
156 Handle<String> NewProperSubString(Handle<String> str,
157 int begin,
158 int end);
159
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000160 // Creates a new external String object. There are two String encodings
161 // in the system: ASCII and two byte. Unlike other String types, it does
162 // not make sense to have a UTF-8 factory function for external strings,
163 // because we cannot change the underlying buffer.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000164 Handle<String> NewExternalStringFromAscii(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000165 const ExternalAsciiString::Resource* resource);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000166 Handle<String> NewExternalStringFromTwoByte(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000167 const ExternalTwoByteString::Resource* resource);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000168
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000169 // Create a symbol.
170 Handle<Symbol> NewSymbol();
171
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000172 // Create a global (but otherwise uninitialized) context.
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000173 Handle<Context> NewNativeContext();
174
175 // Create a global context.
176 Handle<Context> NewGlobalContext(Handle<JSFunction> function,
177 Handle<ScopeInfo> scope_info);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000178
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000179 // Create a module context.
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000180 Handle<Context> NewModuleContext(Handle<ScopeInfo> scope_info);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000181
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000182 // Create a function context.
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000183 Handle<Context> NewFunctionContext(int length, Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000184
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000185 // Create a catch context.
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000186 Handle<Context> NewCatchContext(Handle<JSFunction> function,
187 Handle<Context> previous,
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000188 Handle<String> name,
189 Handle<Object> thrown_object);
190
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000191 // Create a 'with' context.
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000192 Handle<Context> NewWithContext(Handle<JSFunction> function,
193 Handle<Context> previous,
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000194 Handle<JSObject> extension);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000195
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000196 // Create a block context.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000197 Handle<Context> NewBlockContext(Handle<JSFunction> function,
198 Handle<Context> previous,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000199 Handle<ScopeInfo> scope_info);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000200
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000201 // Return the internalized version of the passed in string.
202 Handle<String> InternalizedStringFromString(Handle<String> value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000203
204 // Allocate a new struct. The struct is pretenured (allocated directly in
205 // the old generation).
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000206 Handle<Struct> NewStruct(InstanceType type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000207
ulan@chromium.org750145a2013-03-07 15:14:13 +0000208 Handle<DeclaredAccessorDescriptor> NewDeclaredAccessorDescriptor();
209
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +0000210 Handle<DeclaredAccessorInfo> NewDeclaredAccessorInfo();
211
212 Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000213
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000214 Handle<Script> NewScript(Handle<String> source);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000215
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000216 // Foreign objects are pretenured when allocated by the bootstrapper.
217 Handle<Foreign> NewForeign(Address addr,
218 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000219
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000220 // Allocate a new foreign object. The foreign is pretenured (allocated
221 // directly in the old generation).
222 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000223
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000224 Handle<ByteArray> NewByteArray(int length,
225 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000226
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000227 Handle<ExternalArray> NewExternalArray(
ager@chromium.org3811b432009-10-28 14:53:37 +0000228 int length,
229 ExternalArrayType array_type,
230 void* external_pointer,
231 PretenureFlag pretenure = NOT_TENURED);
232
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000233 Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000234 Handle<Object> value);
235
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000236 Handle<Map> NewMap(
237 InstanceType type,
238 int instance_size,
239 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000240
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000241 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000242
rossberg@chromium.org657d53b2012-07-12 11:06:03 +0000243 Handle<Map> CopyWithPreallocatedFieldDescriptors(Handle<Map> map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000244
ager@chromium.org32912102009-01-16 10:38:43 +0000245 // Copy the map adding more inobject properties if possible without
246 // overflowing the instance size.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000247 Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
verwaest@chromium.org753aee42012-07-17 16:15:42 +0000248 Handle<Map> CopyMap(Handle<Map> map);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000249
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000250 Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
251 ElementsKind elements_kind);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +0000252
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000253 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000254
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +0000255 Handle<FixedArray> CopySizeFixedArray(Handle<FixedArray> array,
256 int new_length);
257
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000258 Handle<FixedDoubleArray> CopyFixedDoubleArray(
259 Handle<FixedDoubleArray> array);
260
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000261 // Numbers (e.g. literals) are pretenured by the parser.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000262 Handle<Object> NewNumber(double value,
263 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000264
erikcorry0ad885c2011-11-21 13:51:57 +0000265 Handle<Object> NewNumberFromInt(int32_t value,
266 PretenureFlag pretenure = NOT_TENURED);
267 Handle<Object> NewNumberFromUint(uint32_t value,
268 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000269
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000270 Handle<HeapNumber> NewHeapNumber(double value,
271 PretenureFlag pretenure = NOT_TENURED);
272
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000273 // These objects are used by the api to create env-independent data
274 // structures in the heap.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000275 Handle<JSObject> NewNeanderObject();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000276
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000277 Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000278
279 // JS objects are pretenured when allocated by the bootstrapper and
280 // runtime.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000281 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
282 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000283
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000284 // Global objects are pretenured.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000285 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000286
ager@chromium.org236ad962008-09-25 09:45:57 +0000287 // JS objects are pretenured when allocated by the bootstrapper and
288 // runtime.
mstarzinger@chromium.org71fc3462013-02-27 09:34:27 +0000289 Handle<JSObject> NewJSObjectFromMap(Handle<Map> map,
290 PretenureFlag pretenure = NOT_TENURED);
ager@chromium.org236ad962008-09-25 09:45:57 +0000291
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000292 // JS modules are pretenured.
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000293 Handle<JSModule> NewJSModule(Handle<Context> context,
294 Handle<ScopeInfo> scope_info);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000295
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000296 // JS arrays are pretenured when allocated by the parser.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000297 Handle<JSArray> NewJSArray(
298 int capacity,
299 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
300 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000301
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000302 Handle<JSArray> NewJSArrayWithElements(
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000303 Handle<FixedArrayBase> elements,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000304 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000305 PretenureFlag pretenure = NOT_TENURED);
306
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000307 void SetElementsCapacityAndLength(Handle<JSArray> array,
308 int capacity,
309 int length);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000310
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000311 void SetContent(Handle<JSArray> array, Handle<FixedArrayBase> elements);
312
313 void EnsureCanContainHeapObjectElements(Handle<JSArray> array);
314 void EnsureCanContainElements(Handle<JSArray> array,
315 Handle<FixedArrayBase> elements,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000316 uint32_t length,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000317 EnsureElementsMode mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000318
danno@chromium.orgca29dd82013-04-26 11:59:48 +0000319 Handle<JSArrayBuffer> NewJSArrayBuffer();
320
danno@chromium.orgf005df62013-04-30 16:36:45 +0000321 Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
322
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000323 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
324
lrn@chromium.org34e60782011-09-15 07:25:40 +0000325 // Change the type of the argument into a JS object/function and reinitialize.
326 void BecomeJSObject(Handle<JSReceiver> object);
327 void BecomeJSFunction(Handle<JSReceiver> object);
rossberg@chromium.org717967f2011-07-20 13:44:42 +0000328
jkummerow@chromium.org000f7fb2012-08-01 11:14:42 +0000329 void SetIdentityHash(Handle<JSObject> object, Smi* hash);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000330
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000331 Handle<JSFunction> NewFunction(Handle<String> name,
332 Handle<Object> prototype);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000333
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000334 Handle<JSFunction> NewFunctionWithoutPrototype(
335 Handle<String> name,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000336 LanguageMode language_mode);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000337
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000338 Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000339
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000340 Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000341 Handle<SharedFunctionInfo> function_info,
342 Handle<Map> function_map,
343 PretenureFlag pretenure);
344
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000345 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000346 Handle<SharedFunctionInfo> function_info,
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000347 Handle<Context> context,
348 PretenureFlag pretenure = TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000349
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000350 Handle<ScopeInfo> NewScopeInfo(int length);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000351
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +0000352 Handle<JSObject> NewExternal(void* value);
353
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000354 Handle<Code> NewCode(const CodeDesc& desc,
355 Code::Flags flags,
356 Handle<Object> self_reference,
mstarzinger@chromium.orgb228be02013-04-18 14:56:59 +0000357 bool immovable = false,
358 bool crankshafted = false);
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000359
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000360 Handle<Code> CopyCode(Handle<Code> code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000361
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000362 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000363
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000364 Handle<Object> ToObject(Handle<Object> object);
365 Handle<Object> ToObject(Handle<Object> object,
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000366 Handle<Context> native_context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000367
368 // Interface for creating error objects.
369
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000370 Handle<Object> NewError(const char* maker, const char* type,
371 Handle<JSArray> args);
verwaest@chromium.org37141392012-05-31 13:27:02 +0000372 Handle<String> EmergencyNewError(const char* type, Handle<JSArray> args);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000373 Handle<Object> NewError(const char* maker, const char* type,
374 Vector< Handle<Object> > args);
375 Handle<Object> NewError(const char* type,
376 Vector< Handle<Object> > args);
377 Handle<Object> NewError(Handle<String> message);
378 Handle<Object> NewError(const char* constructor,
379 Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000380
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000381 Handle<Object> NewTypeError(const char* type,
382 Vector< Handle<Object> > args);
383 Handle<Object> NewTypeError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000384
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000385 Handle<Object> NewRangeError(const char* type,
386 Vector< Handle<Object> > args);
387 Handle<Object> NewRangeError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000388
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000389 Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
390 Handle<Object> NewSyntaxError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000391
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000392 Handle<Object> NewReferenceError(const char* type,
393 Vector< Handle<Object> > args);
394 Handle<Object> NewReferenceError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000395
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000396 Handle<Object> NewEvalError(const char* type,
397 Vector< Handle<Object> > args);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000398
399
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000400 Handle<JSFunction> NewFunction(Handle<String> name,
401 InstanceType type,
402 int instance_size,
403 Handle<Code> code,
404 bool force_initial_map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000405
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000406 Handle<JSFunction> NewFunction(Handle<Map> function_map,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000407 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
408
409
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000410 Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
411 InstanceType type,
412 int instance_size,
413 Handle<JSObject> prototype,
414 Handle<Code> code,
415 bool force_initial_map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000416
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000417 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
418 Handle<Code> code);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000419
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000420 Handle<String> NumberToString(Handle<Object> number);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000421 Handle<String> Uint32ToString(uint32_t value);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000422
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000423 enum ApiInstanceType {
424 JavaScriptObject,
425 InnerGlobalObject,
426 OuterGlobalObject
427 };
428
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000429 Handle<JSFunction> CreateApiFunction(
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000430 Handle<FunctionTemplateInfo> data,
431 ApiInstanceType type = JavaScriptObject);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000432
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000433 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000434
435 // Installs interceptors on the instance. 'desc' is a function template,
436 // and instance is an object instance created by the function of this
ager@chromium.org32912102009-01-16 10:38:43 +0000437 // function template.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000438 void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
439 Handle<JSObject> instance,
440 bool* pending_exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000441
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000442#define ROOT_ACCESSOR(type, name, camel_name) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000443 inline Handle<type> name() { \
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000444 return Handle<type>(BitCast<type**>( \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000445 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000446 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000447 ROOT_LIST(ROOT_ACCESSOR)
448#undef ROOT_ACCESSOR_ACCESSOR
449
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000450#define STRING_ACCESSOR(name, str) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000451 inline Handle<String> name() { \
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000452 return Handle<String>(BitCast<String**>( \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000453 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000454 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000455 INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
456#undef STRING_ACCESSOR
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000457
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000458 Handle<String> hidden_string() {
459 return Handle<String>(&isolate()->heap()->hidden_string_);
ager@chromium.org3b45ab52009-03-19 22:21:34 +0000460 }
461
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000462 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000463 Handle<String> name,
464 int number_of_literals,
mstarzinger@chromium.orgb228be02013-04-18 14:56:59 +0000465 bool is_generator,
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000466 Handle<Code> code,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000467 Handle<ScopeInfo> scope_info);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000468 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000469
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000470 Handle<JSMessageObject> NewJSMessageObject(
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000471 Handle<String> type,
472 Handle<JSArray> arguments,
473 int start_position,
474 int end_position,
475 Handle<Object> script,
476 Handle<Object> stack_trace,
477 Handle<Object> stack_frames);
478
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000479 Handle<SeededNumberDictionary> DictionaryAtNumberPut(
480 Handle<SeededNumberDictionary>,
481 uint32_t key,
482 Handle<Object> value);
483
484 Handle<UnseededNumberDictionary> DictionaryAtNumberPut(
485 Handle<UnseededNumberDictionary>,
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000486 uint32_t key,
487 Handle<Object> value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000488
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000489#ifdef ENABLE_DEBUGGER_SUPPORT
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000490 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000491#endif
ager@chromium.org236ad962008-09-25 09:45:57 +0000492
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000493 // Return a map using the map cache in the native context.
ager@chromium.org236ad962008-09-25 09:45:57 +0000494 // The key the an ordered set of property names.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000495 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
496 Handle<FixedArray> keys);
ager@chromium.org236ad962008-09-25 09:45:57 +0000497
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000498 // Creates a new FixedArray that holds the data associated with the
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000499 // atom regexp and stores it in the regexp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000500 void SetRegExpAtomData(Handle<JSRegExp> regexp,
501 JSRegExp::Type type,
502 Handle<String> source,
503 JSRegExp::Flags flags,
504 Handle<Object> match_pattern);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000505
506 // Creates a new FixedArray that holds the data associated with the
507 // irregexp regexp and stores it in the regexp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000508 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
509 JSRegExp::Type type,
510 Handle<String> source,
511 JSRegExp::Flags flags,
512 int capture_count);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000513
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000514 // Returns the value for a known global constant (a property of the global
515 // object which is neither configurable nor writable) like 'undefined'.
516 // Returns a null handle when the given name is unknown.
517 Handle<Object> GlobalConstantFor(Handle<String> name);
518
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000519 // Converts the given boolean condition to JavaScript boolean value.
520 Handle<Object> ToBoolean(bool value);
521
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000522 private:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000523 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000524
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000525 Handle<JSFunction> NewFunctionHelper(Handle<String> name,
526 Handle<Object> prototype);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000527
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000528 Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
529 Handle<String> name,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000530 LanguageMode language_mode);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000531
ager@chromium.org236ad962008-09-25 09:45:57 +0000532 // Create a new map cache.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000533 Handle<MapCache> NewMapCache(int at_least_space_for);
ager@chromium.org236ad962008-09-25 09:45:57 +0000534
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000535 // Update the map cache in the native context with (keys, map)
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000536 Handle<MapCache> AddToMapCache(Handle<Context> context,
537 Handle<FixedArray> keys,
538 Handle<Map> map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000539};
540
541
542} } // namespace v8::internal
543
544#endif // V8_FACTORY_H_