blob: 3651d361fe02cb5ffaaed7743848e33fff5e47d3 [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
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
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +0000208 Handle<DeclaredAccessorInfo> NewDeclaredAccessorInfo();
209
210 Handle<ExecutableAccessorInfo> NewExecutableAccessorInfo();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000211
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000212 Handle<Script> NewScript(Handle<String> source);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000213
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000214 // Foreign objects are pretenured when allocated by the bootstrapper.
215 Handle<Foreign> NewForeign(Address addr,
216 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000217
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000218 // Allocate a new foreign object. The foreign is pretenured (allocated
219 // directly in the old generation).
220 Handle<Foreign> NewForeign(const AccessorDescriptor* foreign);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000221
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000222 Handle<ByteArray> NewByteArray(int length,
223 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000224
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000225 Handle<ExternalArray> NewExternalArray(
ager@chromium.org3811b432009-10-28 14:53:37 +0000226 int length,
227 ExternalArrayType array_type,
228 void* external_pointer,
229 PretenureFlag pretenure = NOT_TENURED);
230
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000231 Handle<JSGlobalPropertyCell> NewJSGlobalPropertyCell(
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000232 Handle<Object> value);
233
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000234 Handle<Map> NewMap(
235 InstanceType type,
236 int instance_size,
237 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000238
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000239 Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000240
rossberg@chromium.org657d53b2012-07-12 11:06:03 +0000241 Handle<Map> CopyWithPreallocatedFieldDescriptors(Handle<Map> map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000242
ager@chromium.org32912102009-01-16 10:38:43 +0000243 // Copy the map adding more inobject properties if possible without
244 // overflowing the instance size.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000245 Handle<Map> CopyMap(Handle<Map> map, int extra_inobject_props);
verwaest@chromium.org753aee42012-07-17 16:15:42 +0000246 Handle<Map> CopyMap(Handle<Map> map);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000247
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000248 Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
249 ElementsKind elements_kind);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +0000250
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000251 Handle<FixedArray> CopyFixedArray(Handle<FixedArray> array);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000252
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +0000253 Handle<FixedArray> CopySizeFixedArray(Handle<FixedArray> array,
254 int new_length);
255
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000256 Handle<FixedDoubleArray> CopyFixedDoubleArray(
257 Handle<FixedDoubleArray> array);
258
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000259 // Numbers (e.g. literals) are pretenured by the parser.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000260 Handle<Object> NewNumber(double value,
261 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000262
erikcorry0ad885c2011-11-21 13:51:57 +0000263 Handle<Object> NewNumberFromInt(int32_t value,
264 PretenureFlag pretenure = NOT_TENURED);
265 Handle<Object> NewNumberFromUint(uint32_t value,
266 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000267
268 // These objects are used by the api to create env-independent data
269 // structures in the heap.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000270 Handle<JSObject> NewNeanderObject();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000271
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000272 Handle<JSObject> NewArgumentsObject(Handle<Object> callee, int length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000273
274 // JS objects are pretenured when allocated by the bootstrapper and
275 // runtime.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000276 Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
277 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000278
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000279 // Global objects are pretenured.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000280 Handle<GlobalObject> NewGlobalObject(Handle<JSFunction> constructor);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000281
ager@chromium.org236ad962008-09-25 09:45:57 +0000282 // JS objects are pretenured when allocated by the bootstrapper and
283 // runtime.
mstarzinger@chromium.org71fc3462013-02-27 09:34:27 +0000284 Handle<JSObject> NewJSObjectFromMap(Handle<Map> map,
285 PretenureFlag pretenure = NOT_TENURED);
ager@chromium.org236ad962008-09-25 09:45:57 +0000286
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000287 // JS modules are pretenured.
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000288 Handle<JSModule> NewJSModule(Handle<Context> context,
289 Handle<ScopeInfo> scope_info);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000290
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000291 // JS arrays are pretenured when allocated by the parser.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000292 Handle<JSArray> NewJSArray(
293 int capacity,
294 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
295 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000296
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000297 Handle<JSArray> NewJSArrayWithElements(
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000298 Handle<FixedArrayBase> elements,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000299 ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000300 PretenureFlag pretenure = NOT_TENURED);
301
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000302 void SetElementsCapacityAndLength(Handle<JSArray> array,
303 int capacity,
304 int length);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000305
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000306 void SetContent(Handle<JSArray> array, Handle<FixedArrayBase> elements);
307
308 void EnsureCanContainHeapObjectElements(Handle<JSArray> array);
309 void EnsureCanContainElements(Handle<JSArray> array,
310 Handle<FixedArrayBase> elements,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000311 uint32_t length,
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000312 EnsureElementsMode mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000313
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000314 Handle<JSProxy> NewJSProxy(Handle<Object> handler, Handle<Object> prototype);
315
lrn@chromium.org34e60782011-09-15 07:25:40 +0000316 // Change the type of the argument into a JS object/function and reinitialize.
317 void BecomeJSObject(Handle<JSReceiver> object);
318 void BecomeJSFunction(Handle<JSReceiver> object);
rossberg@chromium.org717967f2011-07-20 13:44:42 +0000319
jkummerow@chromium.org000f7fb2012-08-01 11:14:42 +0000320 void SetIdentityHash(Handle<JSObject> object, Smi* hash);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000321
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000322 Handle<JSFunction> NewFunction(Handle<String> name,
323 Handle<Object> prototype);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000324
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000325 Handle<JSFunction> NewFunctionWithoutPrototype(
326 Handle<String> name,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000327 LanguageMode language_mode);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000328
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000329 Handle<JSFunction> NewFunction(Handle<Object> super, bool is_global);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000330
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000331 Handle<JSFunction> BaseNewFunctionFromSharedFunctionInfo(
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000332 Handle<SharedFunctionInfo> function_info,
333 Handle<Map> function_map,
334 PretenureFlag pretenure);
335
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000336 Handle<JSFunction> NewFunctionFromSharedFunctionInfo(
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000337 Handle<SharedFunctionInfo> function_info,
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000338 Handle<Context> context,
339 PretenureFlag pretenure = TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000340
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000341 Handle<ScopeInfo> NewScopeInfo(int length);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000342
yangguo@chromium.orgeeb44b62012-11-13 13:56:09 +0000343 Handle<JSObject> NewExternal(void* value);
344
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000345 Handle<Code> NewCode(const CodeDesc& desc,
346 Code::Flags flags,
347 Handle<Object> self_reference,
348 bool immovable = false);
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000349
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000350 Handle<Code> CopyCode(Handle<Code> code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000351
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000352 Handle<Code> CopyCode(Handle<Code> code, Vector<byte> reloc_info);
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000353
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000354 Handle<Object> ToObject(Handle<Object> object);
355 Handle<Object> ToObject(Handle<Object> object,
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000356 Handle<Context> native_context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000357
358 // Interface for creating error objects.
359
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000360 Handle<Object> NewError(const char* maker, const char* type,
361 Handle<JSArray> args);
verwaest@chromium.org37141392012-05-31 13:27:02 +0000362 Handle<String> EmergencyNewError(const char* type, Handle<JSArray> args);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000363 Handle<Object> NewError(const char* maker, const char* type,
364 Vector< Handle<Object> > args);
365 Handle<Object> NewError(const char* type,
366 Vector< Handle<Object> > args);
367 Handle<Object> NewError(Handle<String> message);
368 Handle<Object> NewError(const char* constructor,
369 Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000370
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000371 Handle<Object> NewTypeError(const char* type,
372 Vector< Handle<Object> > args);
373 Handle<Object> NewTypeError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000374
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000375 Handle<Object> NewRangeError(const char* type,
376 Vector< Handle<Object> > args);
377 Handle<Object> NewRangeError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000378
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000379 Handle<Object> NewSyntaxError(const char* type, Handle<JSArray> args);
380 Handle<Object> NewSyntaxError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000381
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000382 Handle<Object> NewReferenceError(const char* type,
383 Vector< Handle<Object> > args);
384 Handle<Object> NewReferenceError(Handle<String> message);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000385
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000386 Handle<Object> NewEvalError(const char* type,
387 Vector< Handle<Object> > args);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000388
389
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000390 Handle<JSFunction> NewFunction(Handle<String> name,
391 InstanceType type,
392 int instance_size,
393 Handle<Code> code,
394 bool force_initial_map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000395
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000396 Handle<JSFunction> NewFunction(Handle<Map> function_map,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000397 Handle<SharedFunctionInfo> shared, Handle<Object> prototype);
398
399
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000400 Handle<JSFunction> NewFunctionWithPrototype(Handle<String> name,
401 InstanceType type,
402 int instance_size,
403 Handle<JSObject> prototype,
404 Handle<Code> code,
405 bool force_initial_map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000406
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000407 Handle<JSFunction> NewFunctionWithoutPrototype(Handle<String> name,
408 Handle<Code> code);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000409
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000410 Handle<String> NumberToString(Handle<Object> number);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000411 Handle<String> Uint32ToString(uint32_t value);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000412
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000413 enum ApiInstanceType {
414 JavaScriptObject,
415 InnerGlobalObject,
416 OuterGlobalObject
417 };
418
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000419 Handle<JSFunction> CreateApiFunction(
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000420 Handle<FunctionTemplateInfo> data,
421 ApiInstanceType type = JavaScriptObject);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000422
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000423 Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000424
425 // Installs interceptors on the instance. 'desc' is a function template,
426 // and instance is an object instance created by the function of this
ager@chromium.org32912102009-01-16 10:38:43 +0000427 // function template.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000428 void ConfigureInstance(Handle<FunctionTemplateInfo> desc,
429 Handle<JSObject> instance,
430 bool* pending_exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000431
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000432#define ROOT_ACCESSOR(type, name, camel_name) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000433 inline Handle<type> name() { \
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000434 return Handle<type>(BitCast<type**>( \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000435 &isolate()->heap()->roots_[Heap::k##camel_name##RootIndex])); \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000436 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000437 ROOT_LIST(ROOT_ACCESSOR)
438#undef ROOT_ACCESSOR_ACCESSOR
439
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000440#define STRING_ACCESSOR(name, str) \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000441 inline Handle<String> name() { \
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000442 return Handle<String>(BitCast<String**>( \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000443 &isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000444 }
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000445 INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
446#undef STRING_ACCESSOR
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000447
yangguo@chromium.org4a9f6552013-03-04 14:46:33 +0000448 Handle<String> hidden_string() {
449 return Handle<String>(&isolate()->heap()->hidden_string_);
ager@chromium.org3b45ab52009-03-19 22:21:34 +0000450 }
451
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000452 Handle<SharedFunctionInfo> NewSharedFunctionInfo(
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000453 Handle<String> name,
454 int number_of_literals,
455 Handle<Code> code,
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000456 Handle<ScopeInfo> scope_info);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000457 Handle<SharedFunctionInfo> NewSharedFunctionInfo(Handle<String> name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000458
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000459 Handle<JSMessageObject> NewJSMessageObject(
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000460 Handle<String> type,
461 Handle<JSArray> arguments,
462 int start_position,
463 int end_position,
464 Handle<Object> script,
465 Handle<Object> stack_trace,
466 Handle<Object> stack_frames);
467
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000468 Handle<SeededNumberDictionary> DictionaryAtNumberPut(
469 Handle<SeededNumberDictionary>,
470 uint32_t key,
471 Handle<Object> value);
472
473 Handle<UnseededNumberDictionary> DictionaryAtNumberPut(
474 Handle<UnseededNumberDictionary>,
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000475 uint32_t key,
476 Handle<Object> value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000477
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000478#ifdef ENABLE_DEBUGGER_SUPPORT
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000479 Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared);
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000480#endif
ager@chromium.org236ad962008-09-25 09:45:57 +0000481
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000482 // Return a map using the map cache in the native context.
ager@chromium.org236ad962008-09-25 09:45:57 +0000483 // The key the an ordered set of property names.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000484 Handle<Map> ObjectLiteralMapFromCache(Handle<Context> context,
485 Handle<FixedArray> keys);
ager@chromium.org236ad962008-09-25 09:45:57 +0000486
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000487 // Creates a new FixedArray that holds the data associated with the
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000488 // atom regexp and stores it in the regexp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000489 void SetRegExpAtomData(Handle<JSRegExp> regexp,
490 JSRegExp::Type type,
491 Handle<String> source,
492 JSRegExp::Flags flags,
493 Handle<Object> match_pattern);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000494
495 // Creates a new FixedArray that holds the data associated with the
496 // irregexp regexp and stores it in the regexp.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000497 void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
498 JSRegExp::Type type,
499 Handle<String> source,
500 JSRegExp::Flags flags,
501 int capture_count);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000502
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000503 // Returns the value for a known global constant (a property of the global
504 // object which is neither configurable nor writable) like 'undefined'.
505 // Returns a null handle when the given name is unknown.
506 Handle<Object> GlobalConstantFor(Handle<String> name);
507
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000508 // Converts the given boolean condition to JavaScript boolean value.
509 Handle<Object> ToBoolean(bool value);
510
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000511 private:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000512 Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000513
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000514 Handle<JSFunction> NewFunctionHelper(Handle<String> name,
515 Handle<Object> prototype);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000516
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000517 Handle<JSFunction> NewFunctionWithoutPrototypeHelper(
518 Handle<String> name,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000519 LanguageMode language_mode);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000520
ager@chromium.org236ad962008-09-25 09:45:57 +0000521 // Create a new map cache.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000522 Handle<MapCache> NewMapCache(int at_least_space_for);
ager@chromium.org236ad962008-09-25 09:45:57 +0000523
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000524 // Update the map cache in the native context with (keys, map)
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000525 Handle<MapCache> AddToMapCache(Handle<Context> context,
526 Handle<FixedArray> keys,
527 Handle<Map> map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000528};
529
530
531} } // namespace v8::internal
532
533#endif // V8_FACTORY_H_