blob: 143b342083f7489c18bcabd100739cfaacd911a4 [file] [log] [blame]
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001// Copyright 2011 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#include "v8.h"
29
30#include "api.h"
v8.team.kasperl727e9952008-09-02 14:56:44 +000031#include "debug.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000032#include "execution.h"
33#include "factory.h"
34#include "macro-assembler.h"
kasperl@chromium.orga5551262010-12-07 12:49:48 +000035#include "objects.h"
ager@chromium.orgea4f62e2010-08-16 16:28:43 +000036#include "objects-visiting.h"
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +000037#include "scopeinfo.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000038
kasperl@chromium.org71affb52009-05-26 05:44:31 +000039namespace v8 {
40namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000041
42
43Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) {
44 ASSERT(0 <= size);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000045 CALL_HEAP_FUNCTION(
46 isolate(),
47 isolate()->heap()->AllocateFixedArray(size, pretenure),
48 FixedArray);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000049}
50
51
ricow@chromium.orgc9c80822010-04-21 08:22:37 +000052Handle<FixedArray> Factory::NewFixedArrayWithHoles(int size,
53 PretenureFlag pretenure) {
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000054 ASSERT(0 <= size);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000055 CALL_HEAP_FUNCTION(
56 isolate(),
57 isolate()->heap()->AllocateFixedArrayWithHoles(size, pretenure),
58 FixedArray);
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000059}
60
61
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +000062Handle<FixedArray> Factory::NewFixedDoubleArray(int size,
63 PretenureFlag pretenure) {
64 ASSERT(0 <= size);
65 CALL_HEAP_FUNCTION(
66 isolate(),
67 isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure),
68 FixedArray);
69}
70
71
kasperl@chromium.org86f77b72009-07-06 08:21:57 +000072Handle<StringDictionary> Factory::NewStringDictionary(int at_least_space_for) {
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000073 ASSERT(0 <= at_least_space_for);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000074 CALL_HEAP_FUNCTION(isolate(),
75 StringDictionary::Allocate(at_least_space_for),
kasperl@chromium.org86f77b72009-07-06 08:21:57 +000076 StringDictionary);
77}
78
79
80Handle<NumberDictionary> Factory::NewNumberDictionary(int at_least_space_for) {
81 ASSERT(0 <= at_least_space_for);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000082 CALL_HEAP_FUNCTION(isolate(),
83 NumberDictionary::Allocate(at_least_space_for),
kasperl@chromium.org86f77b72009-07-06 08:21:57 +000084 NumberDictionary);
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000085}
86
87
vegorov@chromium.org7943d462011-08-01 11:41:52 +000088Handle<ObjectHashTable> Factory::NewObjectHashTable(int at_least_space_for) {
89 ASSERT(0 <= at_least_space_for);
90 CALL_HEAP_FUNCTION(isolate(),
91 ObjectHashTable::Allocate(at_least_space_for),
92 ObjectHashTable);
93}
94
95
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000096Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors) {
97 ASSERT(0 <= number_of_descriptors);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000098 CALL_HEAP_FUNCTION(isolate(),
99 DescriptorArray::Allocate(number_of_descriptors),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000100 DescriptorArray);
101}
102
103
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000104Handle<DeoptimizationInputData> Factory::NewDeoptimizationInputData(
105 int deopt_entry_count,
106 PretenureFlag pretenure) {
107 ASSERT(deopt_entry_count > 0);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000108 CALL_HEAP_FUNCTION(isolate(),
109 DeoptimizationInputData::Allocate(deopt_entry_count,
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000110 pretenure),
111 DeoptimizationInputData);
112}
113
114
115Handle<DeoptimizationOutputData> Factory::NewDeoptimizationOutputData(
116 int deopt_entry_count,
117 PretenureFlag pretenure) {
118 ASSERT(deopt_entry_count > 0);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000119 CALL_HEAP_FUNCTION(isolate(),
120 DeoptimizationOutputData::Allocate(deopt_entry_count,
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000121 pretenure),
122 DeoptimizationOutputData);
123}
124
125
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000126// Symbols are created in the old generation (data space).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000127Handle<String> Factory::LookupSymbol(Vector<const char> string) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000128 CALL_HEAP_FUNCTION(isolate(),
129 isolate()->heap()->LookupSymbol(string),
130 String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000131}
132
danno@chromium.org40cb8782011-05-25 07:58:50 +0000133// Symbols are created in the old generation (data space).
134Handle<String> Factory::LookupSymbol(Handle<String> string) {
135 CALL_HEAP_FUNCTION(isolate(),
136 isolate()->heap()->LookupSymbol(*string),
137 String);
138}
139
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +0000140Handle<String> Factory::LookupAsciiSymbol(Vector<const char> string) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000141 CALL_HEAP_FUNCTION(isolate(),
142 isolate()->heap()->LookupAsciiSymbol(string),
143 String);
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +0000144}
145
danno@chromium.org40cb8782011-05-25 07:58:50 +0000146
147Handle<String> Factory::LookupAsciiSymbol(Handle<SeqAsciiString> string,
148 int from,
149 int length) {
150 CALL_HEAP_FUNCTION(isolate(),
151 isolate()->heap()->LookupAsciiSymbol(string,
152 from,
153 length),
154 String);
155}
156
157
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +0000158Handle<String> Factory::LookupTwoByteSymbol(Vector<const uc16> string) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000159 CALL_HEAP_FUNCTION(isolate(),
160 isolate()->heap()->LookupTwoByteSymbol(string),
161 String);
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +0000162}
163
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000164
165Handle<String> Factory::NewStringFromAscii(Vector<const char> string,
166 PretenureFlag pretenure) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000167 CALL_HEAP_FUNCTION(
168 isolate(),
169 isolate()->heap()->AllocateStringFromAscii(string, pretenure),
170 String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000171}
172
173Handle<String> Factory::NewStringFromUtf8(Vector<const char> string,
174 PretenureFlag pretenure) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000175 CALL_HEAP_FUNCTION(
176 isolate(),
177 isolate()->heap()->AllocateStringFromUtf8(string, pretenure),
178 String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000179}
180
181
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000182Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
183 PretenureFlag pretenure) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000184 CALL_HEAP_FUNCTION(
185 isolate(),
186 isolate()->heap()->AllocateStringFromTwoByte(string, pretenure),
187 String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000188}
189
190
ager@chromium.org04921a82011-06-27 13:21:41 +0000191Handle<SeqAsciiString> Factory::NewRawAsciiString(int length,
192 PretenureFlag pretenure) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000193 CALL_HEAP_FUNCTION(
194 isolate(),
195 isolate()->heap()->AllocateRawAsciiString(length, pretenure),
ager@chromium.org04921a82011-06-27 13:21:41 +0000196 SeqAsciiString);
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000197}
198
199
ager@chromium.org04921a82011-06-27 13:21:41 +0000200Handle<SeqTwoByteString> Factory::NewRawTwoByteString(int length,
201 PretenureFlag pretenure) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000202 CALL_HEAP_FUNCTION(
203 isolate(),
204 isolate()->heap()->AllocateRawTwoByteString(length, pretenure),
ager@chromium.org04921a82011-06-27 13:21:41 +0000205 SeqTwoByteString);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000206}
207
208
209Handle<String> Factory::NewConsString(Handle<String> first,
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000210 Handle<String> second) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000211 CALL_HEAP_FUNCTION(isolate(),
212 isolate()->heap()->AllocateConsString(*first, *second),
213 String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000214}
215
216
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000217Handle<String> Factory::NewSubString(Handle<String> str,
218 int begin,
219 int end) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000220 CALL_HEAP_FUNCTION(isolate(),
221 str->SubString(begin, end),
222 String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000223}
224
225
ager@chromium.org04921a82011-06-27 13:21:41 +0000226Handle<String> Factory::NewProperSubString(Handle<String> str,
227 int begin,
228 int end) {
229 ASSERT(begin > 0 || end < str->length());
230 CALL_HEAP_FUNCTION(isolate(),
231 isolate()->heap()->AllocateSubString(*str, begin, end),
232 String);
233}
234
235
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000236Handle<String> Factory::NewExternalStringFromAscii(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000237 const ExternalAsciiString::Resource* resource) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000238 CALL_HEAP_FUNCTION(
239 isolate(),
240 isolate()->heap()->AllocateExternalStringFromAscii(resource),
241 String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000242}
243
244
245Handle<String> Factory::NewExternalStringFromTwoByte(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000246 const ExternalTwoByteString::Resource* resource) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000247 CALL_HEAP_FUNCTION(
248 isolate(),
249 isolate()->heap()->AllocateExternalStringFromTwoByte(resource),
250 String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000251}
252
253
254Handle<Context> Factory::NewGlobalContext() {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000255 CALL_HEAP_FUNCTION(
256 isolate(),
257 isolate()->heap()->AllocateGlobalContext(),
258 Context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000259}
260
261
262Handle<Context> Factory::NewFunctionContext(int length,
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000263 Handle<JSFunction> function) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000264 CALL_HEAP_FUNCTION(
265 isolate(),
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000266 isolate()->heap()->AllocateFunctionContext(length, *function),
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000267 Context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000268}
269
270
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000271Handle<Context> Factory::NewCatchContext(Handle<JSFunction> function,
272 Handle<Context> previous,
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000273 Handle<String> name,
274 Handle<Object> thrown_object) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000275 CALL_HEAP_FUNCTION(
276 isolate(),
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000277 isolate()->heap()->AllocateCatchContext(*function,
278 *previous,
279 *name,
280 *thrown_object),
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000281 Context);
282}
283
284
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000285Handle<Context> Factory::NewWithContext(Handle<JSFunction> function,
286 Handle<Context> previous,
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000287 Handle<JSObject> extension) {
288 CALL_HEAP_FUNCTION(
289 isolate(),
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000290 isolate()->heap()->AllocateWithContext(*function, *previous, *extension),
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000291 Context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000292}
293
294
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000295Handle<Context> Factory::NewBlockContext(
296 Handle<JSFunction> function,
297 Handle<Context> previous,
298 Handle<SerializedScopeInfo> scope_info) {
299 CALL_HEAP_FUNCTION(
300 isolate(),
301 isolate()->heap()->AllocateBlockContext(*function,
302 *previous,
303 *scope_info),
304 Context);
305}
306
307
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000308Handle<Struct> Factory::NewStruct(InstanceType type) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000309 CALL_HEAP_FUNCTION(
310 isolate(),
311 isolate()->heap()->AllocateStruct(type),
312 Struct);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000313}
314
315
316Handle<AccessorInfo> Factory::NewAccessorInfo() {
317 Handle<AccessorInfo> info =
318 Handle<AccessorInfo>::cast(NewStruct(ACCESSOR_INFO_TYPE));
319 info->set_flag(0); // Must clear the flag, it was initialized as undefined.
320 return info;
321}
322
323
324Handle<Script> Factory::NewScript(Handle<String> source) {
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000325 // Generate id for this script.
326 int id;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000327 Heap* heap = isolate()->heap();
328 if (heap->last_script_id()->IsUndefined()) {
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000329 // Script ids start from one.
330 id = 1;
331 } else {
332 // Increment id, wrap when positive smi is exhausted.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000333 id = Smi::cast(heap->last_script_id())->value();
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000334 id++;
335 if (!Smi::IsValid(id)) {
336 id = 0;
337 }
338 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000339 heap->SetLastScriptId(Smi::FromInt(id));
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000340
341 // Create and initialize script object.
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000342 Handle<Foreign> wrapper = NewForeign(0, TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000343 Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE));
344 script->set_source(*source);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000345 script->set_name(heap->undefined_value());
346 script->set_id(heap->last_script_id());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000347 script->set_line_offset(Smi::FromInt(0));
348 script->set_column_offset(Smi::FromInt(0));
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000349 script->set_data(heap->undefined_value());
350 script->set_context_data(heap->undefined_value());
ager@chromium.orge2902be2009-06-08 12:21:35 +0000351 script->set_type(Smi::FromInt(Script::TYPE_NORMAL));
352 script->set_compilation_type(Smi::FromInt(Script::COMPILATION_TYPE_HOST));
ager@chromium.org9085a012009-05-11 19:22:57 +0000353 script->set_wrapper(*wrapper);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000354 script->set_line_ends(heap->undefined_value());
355 script->set_eval_from_shared(heap->undefined_value());
ager@chromium.orge2902be2009-06-08 12:21:35 +0000356 script->set_eval_from_instructions_offset(Smi::FromInt(0));
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000357
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000358 return script;
359}
360
361
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000362Handle<Foreign> Factory::NewForeign(Address addr, PretenureFlag pretenure) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000363 CALL_HEAP_FUNCTION(isolate(),
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000364 isolate()->heap()->AllocateForeign(addr, pretenure),
365 Foreign);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000366}
367
368
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000369Handle<Foreign> Factory::NewForeign(const AccessorDescriptor* desc) {
370 return NewForeign((Address) desc, TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000371}
372
373
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000374Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000375 ASSERT(0 <= length);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000376 CALL_HEAP_FUNCTION(
377 isolate(),
378 isolate()->heap()->AllocateByteArray(length, pretenure),
379 ByteArray);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000380}
381
382
ager@chromium.org3811b432009-10-28 14:53:37 +0000383Handle<ExternalArray> Factory::NewExternalArray(int length,
384 ExternalArrayType array_type,
385 void* external_pointer,
386 PretenureFlag pretenure) {
387 ASSERT(0 <= length);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000388 CALL_HEAP_FUNCTION(
389 isolate(),
390 isolate()->heap()->AllocateExternalArray(length,
391 array_type,
392 external_pointer,
393 pretenure),
394 ExternalArray);
ager@chromium.org3811b432009-10-28 14:53:37 +0000395}
396
397
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000398Handle<JSGlobalPropertyCell> Factory::NewJSGlobalPropertyCell(
399 Handle<Object> value) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000400 CALL_HEAP_FUNCTION(
401 isolate(),
402 isolate()->heap()->AllocateJSGlobalPropertyCell(*value),
403 JSGlobalPropertyCell);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000404}
405
406
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000407Handle<Map> Factory::NewMap(InstanceType type,
408 int instance_size,
409 ElementsKind elements_kind) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000410 CALL_HEAP_FUNCTION(
411 isolate(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000412 isolate()->heap()->AllocateMap(type, instance_size, elements_kind),
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000413 Map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000414}
415
416
417Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000418 CALL_HEAP_FUNCTION(
419 isolate(),
420 isolate()->heap()->AllocateFunctionPrototype(*function),
421 JSObject);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000422}
423
424
ager@chromium.org3a37e9b2009-04-27 09:26:21 +0000425Handle<Map> Factory::CopyMapDropDescriptors(Handle<Map> src) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000426 CALL_HEAP_FUNCTION(isolate(), src->CopyDropDescriptors(), Map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000427}
428
429
ager@chromium.org32912102009-01-16 10:38:43 +0000430Handle<Map> Factory::CopyMap(Handle<Map> src,
431 int extra_inobject_properties) {
ager@chromium.org3a37e9b2009-04-27 09:26:21 +0000432 Handle<Map> copy = CopyMapDropDescriptors(src);
ager@chromium.org32912102009-01-16 10:38:43 +0000433 // Check that we do not overflow the instance size when adding the
434 // extra inobject properties.
435 int instance_size_delta = extra_inobject_properties * kPointerSize;
436 int max_instance_size_delta =
437 JSObject::kMaxInstanceSize - copy->instance_size();
438 if (instance_size_delta > max_instance_size_delta) {
439 // If the instance size overflows, we allocate as many properties
440 // as we can as inobject properties.
441 instance_size_delta = max_instance_size_delta;
442 extra_inobject_properties = max_instance_size_delta >> kPointerSizeLog2;
443 }
444 // Adjust the map with the extra inobject properties.
445 int inobject_properties =
446 copy->inobject_properties() + extra_inobject_properties;
447 copy->set_inobject_properties(inobject_properties);
448 copy->set_unused_property_fields(inobject_properties);
449 copy->set_instance_size(copy->instance_size() + instance_size_delta);
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000450 copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy));
ager@chromium.org32912102009-01-16 10:38:43 +0000451 return copy;
452}
453
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000454
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000455Handle<Map> Factory::CopyMapDropTransitions(Handle<Map> src) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000456 CALL_HEAP_FUNCTION(isolate(), src->CopyDropTransitions(), Map);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000457}
458
459
kmillikin@chromium.org83e16822011-09-13 08:21:47 +0000460Handle<Map> Factory::GetElementsTransitionMap(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000461 Handle<JSObject> src,
462 ElementsKind elements_kind) {
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000463 CALL_HEAP_FUNCTION(isolate(),
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000464 src->GetElementsTransitionMap(elements_kind),
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +0000465 Map);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +0000466}
467
468
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000469Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000470 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000471}
472
473
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000474Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo(
475 Handle<SharedFunctionInfo> function_info,
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000476 Handle<Map> function_map,
477 PretenureFlag pretenure) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000478 CALL_HEAP_FUNCTION(
479 isolate(),
480 isolate()->heap()->AllocateFunction(*function_map,
481 *function_info,
482 isolate()->heap()->the_hole_value(),
483 pretenure),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000484 JSFunction);
485}
486
487
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000488Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
489 Handle<SharedFunctionInfo> function_info,
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000490 Handle<Context> context,
491 PretenureFlag pretenure) {
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000492 Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo(
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000493 function_info,
494 function_info->strict_mode()
495 ? isolate()->strict_mode_function_map()
496 : isolate()->function_map(),
497 pretenure);
498
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000499 result->set_context(*context);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000500 int number_of_literals = function_info->num_literals();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000501 Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000502 if (number_of_literals > 0) {
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000503 // Store the object, regexp and array functions in the literals
504 // array prefix. These functions will be used when creating
505 // object, regexp and array literals in this function.
ager@chromium.org236ad962008-09-25 09:45:57 +0000506 literals->set(JSFunction::kLiteralGlobalContextIndex,
507 context->global_context());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000508 }
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000509 result->set_literals(*literals);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000510 result->set_next_function_link(isolate()->heap()->undefined_value());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000511
512 if (V8::UseCrankshaft() &&
513 FLAG_always_opt &&
514 result->is_compiled() &&
515 !function_info->is_toplevel() &&
516 function_info->allows_lazy_compilation()) {
517 result->MarkForLazyRecompilation();
518 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000519 return result;
520}
521
522
523Handle<Object> Factory::NewNumber(double value,
524 PretenureFlag pretenure) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000525 CALL_HEAP_FUNCTION(
526 isolate(),
527 isolate()->heap()->NumberFromDouble(value, pretenure), Object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000528}
529
530
531Handle<Object> Factory::NewNumberFromInt(int value) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000532 CALL_HEAP_FUNCTION(
533 isolate(),
534 isolate()->heap()->NumberFromInt32(value), Object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000535}
536
537
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000538Handle<Object> Factory::NewNumberFromUint(uint32_t value) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000539 CALL_HEAP_FUNCTION(
540 isolate(),
541 isolate()->heap()->NumberFromUint32(value), Object);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000542}
543
544
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000545Handle<JSObject> Factory::NewNeanderObject() {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000546 CALL_HEAP_FUNCTION(
547 isolate(),
548 isolate()->heap()->AllocateJSObjectFromMap(
549 isolate()->heap()->neander_map()),
550 JSObject);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000551}
552
553
554Handle<Object> Factory::NewTypeError(const char* type,
555 Vector< Handle<Object> > args) {
556 return NewError("MakeTypeError", type, args);
557}
558
559
560Handle<Object> Factory::NewTypeError(Handle<String> message) {
561 return NewError("$TypeError", message);
562}
563
564
565Handle<Object> Factory::NewRangeError(const char* type,
566 Vector< Handle<Object> > args) {
567 return NewError("MakeRangeError", type, args);
568}
569
570
571Handle<Object> Factory::NewRangeError(Handle<String> message) {
572 return NewError("$RangeError", message);
573}
574
575
576Handle<Object> Factory::NewSyntaxError(const char* type, Handle<JSArray> args) {
577 return NewError("MakeSyntaxError", type, args);
578}
579
580
581Handle<Object> Factory::NewSyntaxError(Handle<String> message) {
582 return NewError("$SyntaxError", message);
583}
584
585
586Handle<Object> Factory::NewReferenceError(const char* type,
587 Vector< Handle<Object> > args) {
588 return NewError("MakeReferenceError", type, args);
589}
590
591
592Handle<Object> Factory::NewReferenceError(Handle<String> message) {
593 return NewError("$ReferenceError", message);
594}
595
596
597Handle<Object> Factory::NewError(const char* maker, const char* type,
598 Vector< Handle<Object> > args) {
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000599 v8::HandleScope scope; // Instantiate a closeable HandleScope for EscapeFrom.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000600 Handle<FixedArray> array = NewFixedArray(args.length());
ager@chromium.org7c537e22008-10-16 08:43:32 +0000601 for (int i = 0; i < args.length(); i++) {
602 array->set(i, *args[i]);
603 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000604 Handle<JSArray> object = NewJSArrayWithElements(array);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000605 Handle<Object> result = NewError(maker, type, object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000606 return result.EscapeFrom(&scope);
607}
608
609
610Handle<Object> Factory::NewEvalError(const char* type,
611 Vector< Handle<Object> > args) {
612 return NewError("MakeEvalError", type, args);
613}
614
615
616Handle<Object> Factory::NewError(const char* type,
617 Vector< Handle<Object> > args) {
618 return NewError("MakeError", type, args);
619}
620
621
622Handle<Object> Factory::NewError(const char* maker,
623 const char* type,
624 Handle<JSArray> args) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000625 Handle<String> make_str = LookupAsciiSymbol(maker);
626 Handle<Object> fun_obj(
627 isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str));
ager@chromium.org4af710e2009-09-15 12:20:11 +0000628 // If the builtins haven't been properly configured yet this error
629 // constructor may not have been defined. Bail out.
630 if (!fun_obj->IsJSFunction())
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000631 return undefined_value();
ager@chromium.org4af710e2009-09-15 12:20:11 +0000632 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000633 Handle<Object> type_obj = LookupAsciiSymbol(type);
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000634 Handle<Object> argv[] = { type_obj, args };
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000635
636 // Invoke the JavaScript factory method. If an exception is thrown while
637 // running the factory method, use the exception as the result.
638 bool caught_exception;
639 Handle<Object> result = Execution::TryCall(fun,
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000640 isolate()->js_builtins_object(),
641 ARRAY_SIZE(argv),
642 argv,
643 &caught_exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000644 return result;
645}
646
647
648Handle<Object> Factory::NewError(Handle<String> message) {
649 return NewError("$Error", message);
650}
651
652
653Handle<Object> Factory::NewError(const char* constructor,
654 Handle<String> message) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000655 Handle<String> constr = LookupAsciiSymbol(constructor);
656 Handle<JSFunction> fun = Handle<JSFunction>(
657 JSFunction::cast(isolate()->js_builtins_object()->
658 GetPropertyNoExceptionThrown(*constr)));
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000659 Handle<Object> argv[] = { message };
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000660
661 // Invoke the JavaScript factory method. If an exception is thrown while
662 // running the factory method, use the exception as the result.
663 bool caught_exception;
664 Handle<Object> result = Execution::TryCall(fun,
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000665 isolate()->js_builtins_object(),
666 ARRAY_SIZE(argv),
667 argv,
668 &caught_exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000669 return result;
670}
671
672
673Handle<JSFunction> Factory::NewFunction(Handle<String> name,
674 InstanceType type,
675 int instance_size,
676 Handle<Code> code,
677 bool force_initial_map) {
678 // Allocate the function
679 Handle<JSFunction> function = NewFunction(name, the_hole_value());
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000680
681 // Setup the code pointer in both the shared function info and in
682 // the function itself.
683 function->shared()->set_code(*code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000684 function->set_code(*code);
685
686 if (force_initial_map ||
687 type != JS_OBJECT_TYPE ||
688 instance_size != JSObject::kHeaderSize) {
689 Handle<Map> initial_map = NewMap(type, instance_size);
690 Handle<JSObject> prototype = NewFunctionPrototype(function);
691 initial_map->set_prototype(*prototype);
692 function->set_initial_map(*initial_map);
693 initial_map->set_constructor(*function);
694 } else {
695 ASSERT(!function->has_initial_map());
696 ASSERT(!function->has_prototype());
697 }
698
699 return function;
700}
701
702
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000703Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name,
704 InstanceType type,
705 int instance_size,
706 Handle<JSObject> prototype,
707 Handle<Code> code,
708 bool force_initial_map) {
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000709 // Allocate the function.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000710 Handle<JSFunction> function = NewFunction(name, prototype);
711
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000712 // Setup the code pointer in both the shared function info and in
713 // the function itself.
714 function->shared()->set_code(*code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000715 function->set_code(*code);
716
717 if (force_initial_map ||
718 type != JS_OBJECT_TYPE ||
719 instance_size != JSObject::kHeaderSize) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000720 ElementsKind default_elements_kind = FLAG_smi_only_arrays
721 ? FAST_SMI_ONLY_ELEMENTS
722 : FAST_ELEMENTS;
723 Handle<Map> initial_map = NewMap(type,
724 instance_size,
725 default_elements_kind);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000726 function->set_initial_map(*initial_map);
727 initial_map->set_constructor(*function);
728 }
729
730 // Set function.prototype and give the prototype a constructor
731 // property that refers to the function.
732 SetPrototypeProperty(function, prototype);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +0000733 // Currently safe because it is only invoked from Genesis.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000734 SetLocalPropertyNoThrow(prototype, constructor_symbol(), function, DONT_ENUM);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000735 return function;
736}
737
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000738
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000739Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
740 Handle<Code> code) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000741 Handle<JSFunction> function = NewFunctionWithoutPrototype(name,
742 kNonStrictMode);
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000743 function->shared()->set_code(*code);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000744 function->set_code(*code);
745 ASSERT(!function->has_initial_map());
746 ASSERT(!function->has_prototype());
747 return function;
748}
749
750
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000751Handle<SerializedScopeInfo> Factory::NewSerializedScopeInfo(int length) {
752 CALL_HEAP_FUNCTION(
753 isolate(),
754 isolate()->heap()->AllocateSerializedScopeInfo(length),
755 SerializedScopeInfo);
756}
757
758
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000759Handle<Code> Factory::NewCode(const CodeDesc& desc,
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000760 Code::Flags flags,
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000761 Handle<Object> self_ref,
762 bool immovable) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000763 CALL_HEAP_FUNCTION(isolate(),
764 isolate()->heap()->CreateCode(
765 desc, flags, self_ref, immovable),
766 Code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000767}
768
769
770Handle<Code> Factory::CopyCode(Handle<Code> code) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000771 CALL_HEAP_FUNCTION(isolate(),
772 isolate()->heap()->CopyCode(*code),
773 Code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000774}
775
776
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000777Handle<Code> Factory::CopyCode(Handle<Code> code, Vector<byte> reloc_info) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000778 CALL_HEAP_FUNCTION(isolate(),
779 isolate()->heap()->CopyCode(*code, reloc_info),
780 Code);
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000781}
782
783
lrn@chromium.org303ada72010-10-27 09:33:13 +0000784MUST_USE_RESULT static inline MaybeObject* DoCopyInsert(
785 DescriptorArray* array,
786 String* key,
787 Object* value,
788 PropertyAttributes attributes) {
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000789 CallbacksDescriptor desc(key, value, attributes);
lrn@chromium.org303ada72010-10-27 09:33:13 +0000790 MaybeObject* obj = array->CopyInsert(&desc, REMOVE_TRANSITIONS);
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000791 return obj;
792}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000793
794
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000795// Allocate the new array.
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000796Handle<DescriptorArray> Factory::CopyAppendForeignDescriptor(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000797 Handle<DescriptorArray> array,
798 Handle<String> key,
799 Handle<Object> value,
800 PropertyAttributes attributes) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000801 CALL_HEAP_FUNCTION(isolate(),
802 DoCopyInsert(*array, *key, *value, attributes),
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000803 DescriptorArray);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000804}
805
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000806
807Handle<String> Factory::SymbolFromString(Handle<String> value) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000808 CALL_HEAP_FUNCTION(isolate(),
809 isolate()->heap()->LookupSymbol(*value), String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000810}
811
812
813Handle<DescriptorArray> Factory::CopyAppendCallbackDescriptors(
814 Handle<DescriptorArray> array,
815 Handle<Object> descriptors) {
816 v8::NeanderArray callbacks(descriptors);
817 int nof_callbacks = callbacks.length();
818 Handle<DescriptorArray> result =
819 NewDescriptorArray(array->number_of_descriptors() + nof_callbacks);
820
821 // Number of descriptors added to the result so far.
822 int descriptor_count = 0;
823
824 // Copy the descriptors from the array.
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000825 for (int i = 0; i < array->number_of_descriptors(); i++) {
826 if (array->GetType(i) != NULL_DESCRIPTOR) {
827 result->CopyFrom(descriptor_count++, *array, i);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000828 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000829 }
830
831 // Number of duplicates detected.
832 int duplicates = 0;
833
834 // Fill in new callback descriptors. Process the callbacks from
835 // back to front so that the last callback with a given name takes
836 // precedence over previously added callbacks with that name.
837 for (int i = nof_callbacks - 1; i >= 0; i--) {
838 Handle<AccessorInfo> entry =
839 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i)));
840 // Ensure the key is a symbol before writing into the instance descriptor.
841 Handle<String> key =
842 SymbolFromString(Handle<String>(String::cast(entry->name())));
843 // Check if a descriptor with this name already exists before writing.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000844 if (result->LinearSearch(*key, descriptor_count) ==
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000845 DescriptorArray::kNotFound) {
846 CallbacksDescriptor desc(*key, *entry, entry->property_attributes());
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000847 result->Set(descriptor_count, &desc);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000848 descriptor_count++;
849 } else {
850 duplicates++;
851 }
852 }
853
854 // If duplicates were detected, allocate a result of the right size
855 // and transfer the elements.
856 if (duplicates > 0) {
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000857 int number_of_descriptors = result->number_of_descriptors() - duplicates;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000858 Handle<DescriptorArray> new_result =
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000859 NewDescriptorArray(number_of_descriptors);
860 for (int i = 0; i < number_of_descriptors; i++) {
861 new_result->CopyFrom(i, *result, i);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000862 }
863 result = new_result;
864 }
865
866 // Sort the result before returning.
867 result->Sort();
868 return result;
869}
870
871
872Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
873 PretenureFlag pretenure) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000874 CALL_HEAP_FUNCTION(
875 isolate(),
876 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000877}
878
879
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000880Handle<GlobalObject> Factory::NewGlobalObject(
881 Handle<JSFunction> constructor) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000882 CALL_HEAP_FUNCTION(isolate(),
883 isolate()->heap()->AllocateGlobalObject(*constructor),
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000884 GlobalObject);
885}
886
887
888
ager@chromium.org236ad962008-09-25 09:45:57 +0000889Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000890 CALL_HEAP_FUNCTION(
891 isolate(),
892 isolate()->heap()->AllocateJSObjectFromMap(*map, NOT_TENURED),
893 JSObject);
ager@chromium.org236ad962008-09-25 09:45:57 +0000894}
895
896
ricow@chromium.orgbadaffc2011-03-17 12:15:27 +0000897Handle<JSArray> Factory::NewJSArray(int capacity,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000898 PretenureFlag pretenure) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000899 Handle<JSObject> obj = NewJSObject(isolate()->array_function(), pretenure);
900 CALL_HEAP_FUNCTION(isolate(),
901 Handle<JSArray>::cast(obj)->Initialize(capacity),
902 JSArray);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000903}
904
905
906Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArray> elements,
907 PretenureFlag pretenure) {
908 Handle<JSArray> result =
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000909 Handle<JSArray>::cast(NewJSObject(isolate()->array_function(),
910 pretenure));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000911 SetContent(result, elements);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000912 return result;
913}
914
915
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000916void Factory::SetContent(Handle<JSArray> array,
917 Handle<FixedArray> elements) {
918 CALL_HEAP_FUNCTION_VOID(
919 isolate(),
920 array->SetContent(*elements));
921}
922
923
924void Factory::EnsureCanContainNonSmiElements(Handle<JSArray> array) {
925 CALL_HEAP_FUNCTION_VOID(
926 isolate(),
927 array->EnsureCanContainNonSmiElements());
928}
929
930
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000931Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
932 Handle<Object> prototype) {
933 CALL_HEAP_FUNCTION(
934 isolate(),
935 isolate()->heap()->AllocateJSProxy(*handler, *prototype),
936 JSProxy);
937}
938
939
lrn@chromium.org34e60782011-09-15 07:25:40 +0000940void Factory::BecomeJSObject(Handle<JSReceiver> object) {
rossberg@chromium.org717967f2011-07-20 13:44:42 +0000941 CALL_HEAP_FUNCTION_VOID(
942 isolate(),
lrn@chromium.org34e60782011-09-15 07:25:40 +0000943 isolate()->heap()->ReinitializeJSReceiver(
944 *object, JS_OBJECT_TYPE, JSObject::kHeaderSize));
945}
946
947
948void Factory::BecomeJSFunction(Handle<JSReceiver> object) {
949 CALL_HEAP_FUNCTION_VOID(
950 isolate(),
951 isolate()->heap()->ReinitializeJSReceiver(
952 *object, JS_FUNCTION_TYPE, JSFunction::kSize));
rossberg@chromium.org717967f2011-07-20 13:44:42 +0000953}
954
955
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000956void Factory::SetIdentityHash(Handle<JSObject> object, Object* hash) {
957 CALL_HEAP_FUNCTION_VOID(
958 isolate(),
959 object->SetIdentityHash(hash, ALLOW_CREATION));
960}
961
962
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000963Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000964 Handle<String> name,
965 int number_of_literals,
966 Handle<Code> code,
ager@chromium.orgb5737492010-07-15 09:29:43 +0000967 Handle<SerializedScopeInfo> scope_info) {
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000968 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name);
969 shared->set_code(*code);
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000970 shared->set_scope_info(*scope_info);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000971 int literals_array_size = number_of_literals;
972 // If the function contains object, regexp or array literals,
973 // allocate extra space for a literals array prefix containing the
974 // context.
975 if (number_of_literals > 0) {
976 literals_array_size += JSFunction::kLiteralsPrefixSize;
977 }
978 shared->set_num_literals(literals_array_size);
979 return shared;
980}
981
982
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000983Handle<JSMessageObject> Factory::NewJSMessageObject(
984 Handle<String> type,
985 Handle<JSArray> arguments,
986 int start_position,
987 int end_position,
988 Handle<Object> script,
989 Handle<Object> stack_trace,
990 Handle<Object> stack_frames) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000991 CALL_HEAP_FUNCTION(isolate(),
992 isolate()->heap()->AllocateJSMessageObject(*type,
993 *arguments,
994 start_position,
995 end_position,
996 *script,
997 *stack_trace,
998 *stack_frames),
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000999 JSMessageObject);
1000}
1001
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001002Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(Handle<String> name) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001003 CALL_HEAP_FUNCTION(isolate(),
1004 isolate()->heap()->AllocateSharedFunctionInfo(*name),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001005 SharedFunctionInfo);
1006}
1007
1008
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001009Handle<String> Factory::NumberToString(Handle<Object> number) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001010 CALL_HEAP_FUNCTION(isolate(),
1011 isolate()->heap()->NumberToString(*number), String);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00001012}
1013
1014
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001015Handle<String> Factory::Uint32ToString(uint32_t value) {
1016 CALL_HEAP_FUNCTION(isolate(),
1017 isolate()->heap()->Uint32ToString(value), String);
1018}
1019
1020
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001021Handle<NumberDictionary> Factory::DictionaryAtNumberPut(
1022 Handle<NumberDictionary> dictionary,
1023 uint32_t key,
1024 Handle<Object> value) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001025 CALL_HEAP_FUNCTION(isolate(),
1026 dictionary->AtNumberPut(key, *value),
1027 NumberDictionary);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001028}
1029
1030
1031Handle<JSFunction> Factory::NewFunctionHelper(Handle<String> name,
1032 Handle<Object> prototype) {
1033 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001034 CALL_HEAP_FUNCTION(
1035 isolate(),
1036 isolate()->heap()->AllocateFunction(*isolate()->function_map(),
1037 *function_share,
1038 *prototype),
1039 JSFunction);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001040}
1041
1042
1043Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1044 Handle<Object> prototype) {
1045 Handle<JSFunction> fun = NewFunctionHelper(name, prototype);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001046 fun->set_context(isolate()->context()->global_context());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001047 return fun;
1048}
1049
1050
kmillikin@chromium.org4111b802010-05-03 10:34:42 +00001051Handle<JSFunction> Factory::NewFunctionWithoutPrototypeHelper(
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001052 Handle<String> name,
1053 StrictModeFlag strict_mode) {
kmillikin@chromium.org4111b802010-05-03 10:34:42 +00001054 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001055 Handle<Map> map = strict_mode == kStrictMode
1056 ? isolate()->strict_mode_function_without_prototype_map()
1057 : isolate()->function_without_prototype_map();
1058 CALL_HEAP_FUNCTION(isolate(),
1059 isolate()->heap()->AllocateFunction(
1060 *map,
kmillikin@chromium.org4111b802010-05-03 10:34:42 +00001061 *function_share,
1062 *the_hole_value()),
1063 JSFunction);
1064}
1065
1066
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001067Handle<JSFunction> Factory::NewFunctionWithoutPrototype(
1068 Handle<String> name,
1069 StrictModeFlag strict_mode) {
1070 Handle<JSFunction> fun = NewFunctionWithoutPrototypeHelper(name, strict_mode);
1071 fun->set_context(isolate()->context()->global_context());
kmillikin@chromium.org4111b802010-05-03 10:34:42 +00001072 return fun;
1073}
1074
1075
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001076Handle<Object> Factory::ToObject(Handle<Object> object) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001077 CALL_HEAP_FUNCTION(isolate(), object->ToObject(), Object);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001078}
1079
1080
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001081Handle<Object> Factory::ToObject(Handle<Object> object,
1082 Handle<Context> global_context) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001083 CALL_HEAP_FUNCTION(isolate(), object->ToObject(*global_context), Object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001084}
1085
1086
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001087#ifdef ENABLE_DEBUGGER_SUPPORT
v8.team.kasperl727e9952008-09-02 14:56:44 +00001088Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
1089 // Get the original code of the function.
1090 Handle<Code> code(shared->code());
1091
1092 // Create a copy of the code before allocating the debug info object to avoid
1093 // allocation while setting up the debug info object.
1094 Handle<Code> original_code(*Factory::CopyCode(code));
1095
1096 // Allocate initial fixed array for active break points before allocating the
1097 // debug info object to avoid allocation while setting up the debug info
1098 // object.
1099 Handle<FixedArray> break_points(
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001100 NewFixedArray(Debug::kEstimatedNofBreakPointsInFunction));
v8.team.kasperl727e9952008-09-02 14:56:44 +00001101
1102 // Create and set up the debug info object. Debug info contains function, a
1103 // copy of the original code, the executing code and initial fixed array for
1104 // active break points.
1105 Handle<DebugInfo> debug_info =
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001106 Handle<DebugInfo>::cast(NewStruct(DEBUG_INFO_TYPE));
v8.team.kasperl727e9952008-09-02 14:56:44 +00001107 debug_info->set_shared(*shared);
1108 debug_info->set_original_code(*original_code);
1109 debug_info->set_code(*code);
1110 debug_info->set_break_points(*break_points);
1111
1112 // Link debug info to function.
1113 shared->set_debug_info(*debug_info);
1114
1115 return debug_info;
1116}
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001117#endif
v8.team.kasperl727e9952008-09-02 14:56:44 +00001118
1119
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001120Handle<JSObject> Factory::NewArgumentsObject(Handle<Object> callee,
1121 int length) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001122 CALL_HEAP_FUNCTION(
1123 isolate(),
1124 isolate()->heap()->AllocateArgumentsObject(*callee, length), JSObject);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001125}
1126
1127
1128Handle<JSFunction> Factory::CreateApiFunction(
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001129 Handle<FunctionTemplateInfo> obj, ApiInstanceType instance_type) {
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001130 Handle<Code> code = isolate()->builtins()->HandleApiCall();
1131 Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001132
kasper.lund212ac232008-07-16 07:07:30 +00001133 int internal_field_count = 0;
1134 if (!obj->instance_template()->IsUndefined()) {
1135 Handle<ObjectTemplateInfo> instance_template =
1136 Handle<ObjectTemplateInfo>(
1137 ObjectTemplateInfo::cast(obj->instance_template()));
1138 internal_field_count =
1139 Smi::cast(instance_template->internal_field_count())->value();
1140 }
1141
1142 int instance_size = kPointerSize * internal_field_count;
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00001143 InstanceType type = INVALID_TYPE;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001144 switch (instance_type) {
1145 case JavaScriptObject:
1146 type = JS_OBJECT_TYPE;
1147 instance_size += JSObject::kHeaderSize;
1148 break;
1149 case InnerGlobalObject:
1150 type = JS_GLOBAL_OBJECT_TYPE;
1151 instance_size += JSGlobalObject::kSize;
1152 break;
1153 case OuterGlobalObject:
1154 type = JS_GLOBAL_PROXY_TYPE;
1155 instance_size += JSGlobalProxy::kSize;
1156 break;
1157 default:
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001158 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001159 }
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00001160 ASSERT(type != INVALID_TYPE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001161
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001162 Handle<JSFunction> result =
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001163 NewFunction(Factory::empty_symbol(),
1164 type,
1165 instance_size,
1166 code,
1167 true);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001168 // Set class name.
1169 Handle<Object> class_name = Handle<Object>(obj->class_name());
1170 if (class_name->IsString()) {
1171 result->shared()->set_instance_class_name(*class_name);
1172 result->shared()->set_name(*class_name);
1173 }
1174
1175 Handle<Map> map = Handle<Map>(result->initial_map());
1176
1177 // Mark as undetectable if needed.
1178 if (obj->undetectable()) {
1179 map->set_is_undetectable();
1180 }
1181
1182 // Mark as hidden for the __proto__ accessor if needed.
1183 if (obj->hidden_prototype()) {
1184 map->set_is_hidden_prototype();
1185 }
1186
1187 // Mark as needs_access_check if needed.
1188 if (obj->needs_access_check()) {
ager@chromium.org870a0b62008-11-04 11:43:05 +00001189 map->set_is_access_check_needed(true);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001190 }
1191
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001192 // Set interceptor information in the map.
1193 if (!obj->named_property_handler()->IsUndefined()) {
1194 map->set_has_named_interceptor();
1195 }
1196 if (!obj->indexed_property_handler()->IsUndefined()) {
1197 map->set_has_indexed_interceptor();
1198 }
1199
1200 // Set instance call-as-function information in the map.
1201 if (!obj->instance_call_handler()->IsUndefined()) {
1202 map->set_has_instance_call_handler();
1203 }
1204
1205 result->shared()->set_function_data(*obj);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001206 result->shared()->set_construct_stub(*construct_stub);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00001207 result->shared()->DontAdaptArguments();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001208
1209 // Recursively copy parent templates' accessors, 'data' may be modified.
1210 Handle<DescriptorArray> array =
1211 Handle<DescriptorArray>(map->instance_descriptors());
1212 while (true) {
1213 Handle<Object> props = Handle<Object>(obj->property_accessors());
1214 if (!props->IsUndefined()) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001215 array = CopyAppendCallbackDescriptors(array, props);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001216 }
1217 Handle<Object> parent = Handle<Object>(obj->parent_template());
1218 if (parent->IsUndefined()) break;
1219 obj = Handle<FunctionTemplateInfo>::cast(parent);
1220 }
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001221 if (!array->IsEmpty()) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001222 map->set_instance_descriptors(*array);
1223 }
1224
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001225 ASSERT(result->shared()->IsApiFunction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001226 return result;
1227}
1228
1229
ager@chromium.org236ad962008-09-25 09:45:57 +00001230Handle<MapCache> Factory::NewMapCache(int at_least_space_for) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001231 CALL_HEAP_FUNCTION(isolate(),
1232 MapCache::Allocate(at_least_space_for), MapCache);
ager@chromium.org236ad962008-09-25 09:45:57 +00001233}
1234
1235
lrn@chromium.org303ada72010-10-27 09:33:13 +00001236MUST_USE_RESULT static MaybeObject* UpdateMapCacheWith(Context* context,
1237 FixedArray* keys,
1238 Map* map) {
1239 Object* result;
1240 { MaybeObject* maybe_result =
1241 MapCache::cast(context->map_cache())->Put(keys, map);
1242 if (!maybe_result->ToObject(&result)) return maybe_result;
1243 }
1244 context->set_map_cache(MapCache::cast(result));
ager@chromium.org236ad962008-09-25 09:45:57 +00001245 return result;
1246}
1247
1248
1249Handle<MapCache> Factory::AddToMapCache(Handle<Context> context,
1250 Handle<FixedArray> keys,
1251 Handle<Map> map) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001252 CALL_HEAP_FUNCTION(isolate(),
1253 UpdateMapCacheWith(*context, *keys, *map), MapCache);
ager@chromium.org236ad962008-09-25 09:45:57 +00001254}
1255
1256
1257Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
1258 Handle<FixedArray> keys) {
1259 if (context->map_cache()->IsUndefined()) {
1260 // Allocate the new map cache for the global context.
1261 Handle<MapCache> new_cache = NewMapCache(24);
1262 context->set_map_cache(*new_cache);
1263 }
ager@chromium.org32912102009-01-16 10:38:43 +00001264 // Check to see whether there is a matching element in the cache.
ager@chromium.org236ad962008-09-25 09:45:57 +00001265 Handle<MapCache> cache =
1266 Handle<MapCache>(MapCache::cast(context->map_cache()));
1267 Handle<Object> result = Handle<Object>(cache->Lookup(*keys));
1268 if (result->IsMap()) return Handle<Map>::cast(result);
1269 // Create a new map and add it to the cache.
1270 Handle<Map> map =
ager@chromium.org32912102009-01-16 10:38:43 +00001271 CopyMap(Handle<Map>(context->object_function()->initial_map()),
1272 keys->length());
ager@chromium.org236ad962008-09-25 09:45:57 +00001273 AddToMapCache(context, keys, map);
1274 return Handle<Map>(map);
1275}
1276
1277
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001278void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp,
1279 JSRegExp::Type type,
1280 Handle<String> source,
1281 JSRegExp::Flags flags,
1282 Handle<Object> data) {
1283 Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize);
1284
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00001285 store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
1286 store->set(JSRegExp::kSourceIndex, *source);
1287 store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
1288 store->set(JSRegExp::kAtomPatternIndex, *data);
1289 regexp->set_data(*store);
1290}
1291
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001292void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp,
1293 JSRegExp::Type type,
1294 Handle<String> source,
1295 JSRegExp::Flags flags,
1296 int capture_count) {
1297 Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize);
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00001298 Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001299 store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
1300 store->set(JSRegExp::kSourceIndex, *source);
1301 store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00001302 store->set(JSRegExp::kIrregexpASCIICodeIndex, uninitialized);
1303 store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized);
1304 store->set(JSRegExp::kIrregexpASCIICodeSavedIndex, uninitialized);
1305 store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001306 store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0));
1307 store->set(JSRegExp::kIrregexpCaptureCountIndex,
1308 Smi::FromInt(capture_count));
1309 regexp->set_data(*store);
1310}
1311
1312
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00001313
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001314void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc,
1315 Handle<JSObject> instance,
1316 bool* pending_exception) {
1317 // Configure the instance by adding the properties specified by the
1318 // instance template.
1319 Handle<Object> instance_template = Handle<Object>(desc->instance_template());
1320 if (!instance_template->IsUndefined()) {
1321 Execution::ConfigureInstance(instance,
1322 instance_template,
1323 pending_exception);
1324 } else {
1325 *pending_exception = false;
1326 }
1327}
1328
1329
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001330Handle<Object> Factory::GlobalConstantFor(Handle<String> name) {
1331 Heap* h = isolate()->heap();
1332 if (name->Equals(h->undefined_symbol())) return undefined_value();
1333 if (name->Equals(h->nan_symbol())) return nan_value();
1334 if (name->Equals(h->infinity_symbol())) return infinity_value();
1335 return Handle<Object>::null();
1336}
1337
1338
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +00001339Handle<Object> Factory::ToBoolean(bool value) {
1340 return Handle<Object>(value
1341 ? isolate()->heap()->true_value()
1342 : isolate()->heap()->false_value());
1343}
1344
1345
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001346} } // namespace v8::internal