blob: 7c8c934044ab63d5a1da42695324be8473e2f40c [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 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"
ager@chromium.orgea4f62e2010-08-16 16:28:43 +000035#include "objects-visiting.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000036
kasperl@chromium.org71affb52009-05-26 05:44:31 +000037namespace v8 {
38namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000039
40
41Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) {
42 ASSERT(0 <= size);
43 CALL_HEAP_FUNCTION(Heap::AllocateFixedArray(size, pretenure), FixedArray);
44}
45
46
ricow@chromium.orgc9c80822010-04-21 08:22:37 +000047Handle<FixedArray> Factory::NewFixedArrayWithHoles(int size,
48 PretenureFlag pretenure) {
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000049 ASSERT(0 <= size);
ricow@chromium.orgc9c80822010-04-21 08:22:37 +000050 CALL_HEAP_FUNCTION(Heap::AllocateFixedArrayWithHoles(size, pretenure),
51 FixedArray);
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000052}
53
54
kasperl@chromium.org86f77b72009-07-06 08:21:57 +000055Handle<StringDictionary> Factory::NewStringDictionary(int at_least_space_for) {
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000056 ASSERT(0 <= at_least_space_for);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +000057 CALL_HEAP_FUNCTION(StringDictionary::Allocate(at_least_space_for),
58 StringDictionary);
59}
60
61
62Handle<NumberDictionary> Factory::NewNumberDictionary(int at_least_space_for) {
63 ASSERT(0 <= at_least_space_for);
64 CALL_HEAP_FUNCTION(NumberDictionary::Allocate(at_least_space_for),
65 NumberDictionary);
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000066}
67
68
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000069Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors) {
70 ASSERT(0 <= number_of_descriptors);
71 CALL_HEAP_FUNCTION(DescriptorArray::Allocate(number_of_descriptors),
72 DescriptorArray);
73}
74
75
ager@chromium.org9258b6b2008-09-11 09:11:10 +000076// Symbols are created in the old generation (data space).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000077Handle<String> Factory::LookupSymbol(Vector<const char> string) {
78 CALL_HEAP_FUNCTION(Heap::LookupSymbol(string), String);
79}
80
81
82Handle<String> Factory::NewStringFromAscii(Vector<const char> string,
83 PretenureFlag pretenure) {
84 CALL_HEAP_FUNCTION(Heap::AllocateStringFromAscii(string, pretenure), String);
85}
86
87Handle<String> Factory::NewStringFromUtf8(Vector<const char> string,
88 PretenureFlag pretenure) {
89 CALL_HEAP_FUNCTION(Heap::AllocateStringFromUtf8(string, pretenure), String);
90}
91
92
sgjesse@chromium.org911335c2009-08-19 12:59:44 +000093Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
94 PretenureFlag pretenure) {
95 CALL_HEAP_FUNCTION(Heap::AllocateStringFromTwoByte(string, pretenure),
96 String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000097}
98
99
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000100Handle<String> Factory::NewRawAsciiString(int length,
101 PretenureFlag pretenure) {
102 CALL_HEAP_FUNCTION(Heap::AllocateRawAsciiString(length, pretenure), String);
103}
104
105
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000106Handle<String> Factory::NewRawTwoByteString(int length,
107 PretenureFlag pretenure) {
108 CALL_HEAP_FUNCTION(Heap::AllocateRawTwoByteString(length, pretenure), String);
109}
110
111
112Handle<String> Factory::NewConsString(Handle<String> first,
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000113 Handle<String> second) {
ager@chromium.orgc3e50d82008-11-05 11:53:10 +0000114 CALL_HEAP_FUNCTION(Heap::AllocateConsString(*first, *second), String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000115}
116
117
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000118Handle<String> Factory::NewSubString(Handle<String> str,
119 int begin,
120 int end) {
121 CALL_HEAP_FUNCTION(str->SubString(begin, end), String);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000122}
123
124
125Handle<String> Factory::NewExternalStringFromAscii(
126 ExternalAsciiString::Resource* resource) {
127 CALL_HEAP_FUNCTION(Heap::AllocateExternalStringFromAscii(resource), String);
128}
129
130
131Handle<String> Factory::NewExternalStringFromTwoByte(
132 ExternalTwoByteString::Resource* resource) {
133 CALL_HEAP_FUNCTION(Heap::AllocateExternalStringFromTwoByte(resource), String);
134}
135
136
137Handle<Context> Factory::NewGlobalContext() {
138 CALL_HEAP_FUNCTION(Heap::AllocateGlobalContext(), Context);
139}
140
141
142Handle<Context> Factory::NewFunctionContext(int length,
143 Handle<JSFunction> closure) {
144 CALL_HEAP_FUNCTION(Heap::AllocateFunctionContext(length, *closure), Context);
145}
146
147
148Handle<Context> Factory::NewWithContext(Handle<Context> previous,
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000149 Handle<JSObject> extension,
150 bool is_catch_context) {
151 CALL_HEAP_FUNCTION(Heap::AllocateWithContext(*previous,
152 *extension,
153 is_catch_context),
154 Context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000155}
156
157
158Handle<Struct> Factory::NewStruct(InstanceType type) {
159 CALL_HEAP_FUNCTION(Heap::AllocateStruct(type), Struct);
160}
161
162
163Handle<AccessorInfo> Factory::NewAccessorInfo() {
164 Handle<AccessorInfo> info =
165 Handle<AccessorInfo>::cast(NewStruct(ACCESSOR_INFO_TYPE));
166 info->set_flag(0); // Must clear the flag, it was initialized as undefined.
167 return info;
168}
169
170
171Handle<Script> Factory::NewScript(Handle<String> source) {
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000172 // Generate id for this script.
173 int id;
174 if (Heap::last_script_id()->IsUndefined()) {
175 // Script ids start from one.
176 id = 1;
177 } else {
178 // Increment id, wrap when positive smi is exhausted.
179 id = Smi::cast(Heap::last_script_id())->value();
180 id++;
181 if (!Smi::IsValid(id)) {
182 id = 0;
183 }
184 }
185 Heap::SetLastScriptId(Smi::FromInt(id));
186
187 // Create and initialize script object.
ager@chromium.org9085a012009-05-11 19:22:57 +0000188 Handle<Proxy> wrapper = Factory::NewProxy(0, TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000189 Handle<Script> script = Handle<Script>::cast(NewStruct(SCRIPT_TYPE));
190 script->set_source(*source);
191 script->set_name(Heap::undefined_value());
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000192 script->set_id(Heap::last_script_id());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000193 script->set_line_offset(Smi::FromInt(0));
194 script->set_column_offset(Smi::FromInt(0));
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000195 script->set_data(Heap::undefined_value());
ager@chromium.org9085a012009-05-11 19:22:57 +0000196 script->set_context_data(Heap::undefined_value());
ager@chromium.orge2902be2009-06-08 12:21:35 +0000197 script->set_type(Smi::FromInt(Script::TYPE_NORMAL));
198 script->set_compilation_type(Smi::FromInt(Script::COMPILATION_TYPE_HOST));
ager@chromium.org9085a012009-05-11 19:22:57 +0000199 script->set_wrapper(*wrapper);
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +0000200 script->set_line_ends(Heap::undefined_value());
sgjesse@chromium.org98180592009-12-02 08:17:28 +0000201 script->set_eval_from_shared(Heap::undefined_value());
ager@chromium.orge2902be2009-06-08 12:21:35 +0000202 script->set_eval_from_instructions_offset(Smi::FromInt(0));
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000203
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000204 return script;
205}
206
207
208Handle<Proxy> Factory::NewProxy(Address addr, PretenureFlag pretenure) {
209 CALL_HEAP_FUNCTION(Heap::AllocateProxy(addr, pretenure), Proxy);
210}
211
212
213Handle<Proxy> Factory::NewProxy(const AccessorDescriptor* desc) {
214 return NewProxy((Address) desc, TENURED);
215}
216
217
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000218Handle<ByteArray> Factory::NewByteArray(int length, PretenureFlag pretenure) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000219 ASSERT(0 <= length);
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000220 CALL_HEAP_FUNCTION(Heap::AllocateByteArray(length, pretenure), ByteArray);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000221}
222
223
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000224Handle<PixelArray> Factory::NewPixelArray(int length,
225 uint8_t* external_pointer,
226 PretenureFlag pretenure) {
227 ASSERT(0 <= length);
228 CALL_HEAP_FUNCTION(Heap::AllocatePixelArray(length,
229 external_pointer,
230 pretenure), PixelArray);
231}
232
233
ager@chromium.org3811b432009-10-28 14:53:37 +0000234Handle<ExternalArray> Factory::NewExternalArray(int length,
235 ExternalArrayType array_type,
236 void* external_pointer,
237 PretenureFlag pretenure) {
238 ASSERT(0 <= length);
239 CALL_HEAP_FUNCTION(Heap::AllocateExternalArray(length,
240 array_type,
241 external_pointer,
242 pretenure), ExternalArray);
243}
244
245
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000246Handle<Map> Factory::NewMap(InstanceType type, int instance_size) {
247 CALL_HEAP_FUNCTION(Heap::AllocateMap(type, instance_size), Map);
248}
249
250
251Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
252 CALL_HEAP_FUNCTION(Heap::AllocateFunctionPrototype(*function), JSObject);
253}
254
255
ager@chromium.org3a37e9b2009-04-27 09:26:21 +0000256Handle<Map> Factory::CopyMapDropDescriptors(Handle<Map> src) {
257 CALL_HEAP_FUNCTION(src->CopyDropDescriptors(), Map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000258}
259
260
ager@chromium.org32912102009-01-16 10:38:43 +0000261Handle<Map> Factory::CopyMap(Handle<Map> src,
262 int extra_inobject_properties) {
ager@chromium.org3a37e9b2009-04-27 09:26:21 +0000263 Handle<Map> copy = CopyMapDropDescriptors(src);
ager@chromium.org32912102009-01-16 10:38:43 +0000264 // Check that we do not overflow the instance size when adding the
265 // extra inobject properties.
266 int instance_size_delta = extra_inobject_properties * kPointerSize;
267 int max_instance_size_delta =
268 JSObject::kMaxInstanceSize - copy->instance_size();
269 if (instance_size_delta > max_instance_size_delta) {
270 // If the instance size overflows, we allocate as many properties
271 // as we can as inobject properties.
272 instance_size_delta = max_instance_size_delta;
273 extra_inobject_properties = max_instance_size_delta >> kPointerSizeLog2;
274 }
275 // Adjust the map with the extra inobject properties.
276 int inobject_properties =
277 copy->inobject_properties() + extra_inobject_properties;
278 copy->set_inobject_properties(inobject_properties);
279 copy->set_unused_property_fields(inobject_properties);
280 copy->set_instance_size(copy->instance_size() + instance_size_delta);
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000281 copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy));
ager@chromium.org32912102009-01-16 10:38:43 +0000282 return copy;
283}
284
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000285
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000286Handle<Map> Factory::CopyMapDropTransitions(Handle<Map> src) {
287 CALL_HEAP_FUNCTION(src->CopyDropTransitions(), Map);
288}
289
290
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000291Handle<Map> Factory::GetFastElementsMap(Handle<Map> src) {
292 CALL_HEAP_FUNCTION(src->GetFastElementsMap(), Map);
293}
294
295
296Handle<Map> Factory::GetSlowElementsMap(Handle<Map> src) {
297 CALL_HEAP_FUNCTION(src->GetSlowElementsMap(), Map);
298}
299
300
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000301Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) {
302 CALL_HEAP_FUNCTION(array->Copy(), FixedArray);
303}
304
305
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000306Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo(
307 Handle<SharedFunctionInfo> function_info,
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000308 Handle<Map> function_map,
309 PretenureFlag pretenure) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000310 CALL_HEAP_FUNCTION(Heap::AllocateFunction(*function_map,
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000311 *function_info,
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000312 Heap::the_hole_value(),
313 pretenure),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000314 JSFunction);
315}
316
317
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000318Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
319 Handle<SharedFunctionInfo> function_info,
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000320 Handle<Context> context,
321 PretenureFlag pretenure) {
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000322 Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo(
323 function_info, Top::function_map(), pretenure);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000324 result->set_context(*context);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000325 int number_of_literals = function_info->num_literals();
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000326 Handle<FixedArray> literals =
sgjesse@chromium.org846fb742009-12-18 08:56:33 +0000327 Factory::NewFixedArray(number_of_literals, pretenure);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000328 if (number_of_literals > 0) {
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000329 // Store the object, regexp and array functions in the literals
330 // array prefix. These functions will be used when creating
331 // object, regexp and array literals in this function.
ager@chromium.org236ad962008-09-25 09:45:57 +0000332 literals->set(JSFunction::kLiteralGlobalContextIndex,
333 context->global_context());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000334 }
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000335 result->set_literals(*literals);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000336 return result;
337}
338
339
340Handle<Object> Factory::NewNumber(double value,
341 PretenureFlag pretenure) {
342 CALL_HEAP_FUNCTION(Heap::NumberFromDouble(value, pretenure), Object);
343}
344
345
346Handle<Object> Factory::NewNumberFromInt(int value) {
347 CALL_HEAP_FUNCTION(Heap::NumberFromInt32(value), Object);
348}
349
350
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000351Handle<Object> Factory::NewNumberFromUint(uint32_t value) {
352 CALL_HEAP_FUNCTION(Heap::NumberFromUint32(value), Object);
353}
354
355
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000356Handle<JSObject> Factory::NewNeanderObject() {
357 CALL_HEAP_FUNCTION(Heap::AllocateJSObjectFromMap(Heap::neander_map()),
358 JSObject);
359}
360
361
362Handle<Object> Factory::NewTypeError(const char* type,
363 Vector< Handle<Object> > args) {
364 return NewError("MakeTypeError", type, args);
365}
366
367
368Handle<Object> Factory::NewTypeError(Handle<String> message) {
369 return NewError("$TypeError", message);
370}
371
372
373Handle<Object> Factory::NewRangeError(const char* type,
374 Vector< Handle<Object> > args) {
375 return NewError("MakeRangeError", type, args);
376}
377
378
379Handle<Object> Factory::NewRangeError(Handle<String> message) {
380 return NewError("$RangeError", message);
381}
382
383
384Handle<Object> Factory::NewSyntaxError(const char* type, Handle<JSArray> args) {
385 return NewError("MakeSyntaxError", type, args);
386}
387
388
389Handle<Object> Factory::NewSyntaxError(Handle<String> message) {
390 return NewError("$SyntaxError", message);
391}
392
393
394Handle<Object> Factory::NewReferenceError(const char* type,
395 Vector< Handle<Object> > args) {
396 return NewError("MakeReferenceError", type, args);
397}
398
399
400Handle<Object> Factory::NewReferenceError(Handle<String> message) {
401 return NewError("$ReferenceError", message);
402}
403
404
405Handle<Object> Factory::NewError(const char* maker, const char* type,
406 Vector< Handle<Object> > args) {
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000407 v8::HandleScope scope; // Instantiate a closeable HandleScope for EscapeFrom.
ager@chromium.org7c537e22008-10-16 08:43:32 +0000408 Handle<FixedArray> array = Factory::NewFixedArray(args.length());
409 for (int i = 0; i < args.length(); i++) {
410 array->set(i, *args[i]);
411 }
412 Handle<JSArray> object = Factory::NewJSArrayWithElements(array);
413 Handle<Object> result = NewError(maker, type, object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000414 return result.EscapeFrom(&scope);
415}
416
417
418Handle<Object> Factory::NewEvalError(const char* type,
419 Vector< Handle<Object> > args) {
420 return NewError("MakeEvalError", type, args);
421}
422
423
424Handle<Object> Factory::NewError(const char* type,
425 Vector< Handle<Object> > args) {
426 return NewError("MakeError", type, args);
427}
428
429
430Handle<Object> Factory::NewError(const char* maker,
431 const char* type,
432 Handle<JSArray> args) {
433 Handle<String> make_str = Factory::LookupAsciiSymbol(maker);
ager@chromium.org4af710e2009-09-15 12:20:11 +0000434 Handle<Object> fun_obj(Top::builtins()->GetProperty(*make_str));
435 // If the builtins haven't been properly configured yet this error
436 // constructor may not have been defined. Bail out.
437 if (!fun_obj->IsJSFunction())
438 return Factory::undefined_value();
439 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000440 Handle<Object> type_obj = Factory::LookupAsciiSymbol(type);
441 Object** argv[2] = { type_obj.location(),
442 Handle<Object>::cast(args).location() };
443
444 // Invoke the JavaScript factory method. If an exception is thrown while
445 // running the factory method, use the exception as the result.
446 bool caught_exception;
447 Handle<Object> result = Execution::TryCall(fun,
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000448 Top::builtins(),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000449 2,
450 argv,
451 &caught_exception);
452 return result;
453}
454
455
456Handle<Object> Factory::NewError(Handle<String> message) {
457 return NewError("$Error", message);
458}
459
460
461Handle<Object> Factory::NewError(const char* constructor,
462 Handle<String> message) {
463 Handle<String> constr = Factory::LookupAsciiSymbol(constructor);
464 Handle<JSFunction> fun =
465 Handle<JSFunction>(
466 JSFunction::cast(
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000467 Top::builtins()->GetProperty(*constr)));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000468 Object** argv[1] = { Handle<Object>::cast(message).location() };
469
470 // Invoke the JavaScript factory method. If an exception is thrown while
471 // running the factory method, use the exception as the result.
472 bool caught_exception;
473 Handle<Object> result = Execution::TryCall(fun,
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000474 Top::builtins(),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000475 1,
476 argv,
477 &caught_exception);
478 return result;
479}
480
481
482Handle<JSFunction> Factory::NewFunction(Handle<String> name,
483 InstanceType type,
484 int instance_size,
485 Handle<Code> code,
486 bool force_initial_map) {
487 // Allocate the function
488 Handle<JSFunction> function = NewFunction(name, the_hole_value());
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000489
490 // Setup the code pointer in both the shared function info and in
491 // the function itself.
492 function->shared()->set_code(*code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000493 function->set_code(*code);
494
495 if (force_initial_map ||
496 type != JS_OBJECT_TYPE ||
497 instance_size != JSObject::kHeaderSize) {
498 Handle<Map> initial_map = NewMap(type, instance_size);
499 Handle<JSObject> prototype = NewFunctionPrototype(function);
500 initial_map->set_prototype(*prototype);
501 function->set_initial_map(*initial_map);
502 initial_map->set_constructor(*function);
503 } else {
504 ASSERT(!function->has_initial_map());
505 ASSERT(!function->has_prototype());
506 }
507
508 return function;
509}
510
511
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000512Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name,
513 InstanceType type,
514 int instance_size,
515 Handle<JSObject> prototype,
516 Handle<Code> code,
517 bool force_initial_map) {
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000518 // Allocate the function.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000519 Handle<JSFunction> function = NewFunction(name, prototype);
520
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000521 // Setup the code pointer in both the shared function info and in
522 // the function itself.
523 function->shared()->set_code(*code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000524 function->set_code(*code);
525
526 if (force_initial_map ||
527 type != JS_OBJECT_TYPE ||
528 instance_size != JSObject::kHeaderSize) {
529 Handle<Map> initial_map = NewMap(type, instance_size);
530 function->set_initial_map(*initial_map);
531 initial_map->set_constructor(*function);
532 }
533
534 // Set function.prototype and give the prototype a constructor
535 // property that refers to the function.
536 SetPrototypeProperty(function, prototype);
537 SetProperty(prototype, Factory::constructor_symbol(), function, DONT_ENUM);
538 return function;
539}
540
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000541
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000542Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
543 Handle<Code> code) {
544 Handle<JSFunction> function = NewFunctionWithoutPrototype(name);
vegorov@chromium.org26c16f82010-08-11 13:41:03 +0000545 function->shared()->set_code(*code);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000546 function->set_code(*code);
547 ASSERT(!function->has_initial_map());
548 ASSERT(!function->has_prototype());
549 return function;
550}
551
552
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000553Handle<Code> Factory::NewCode(const CodeDesc& desc,
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000554 Code::Flags flags,
555 Handle<Object> self_ref) {
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000556 CALL_HEAP_FUNCTION(Heap::CreateCode(desc, flags, self_ref), Code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000557}
558
559
560Handle<Code> Factory::CopyCode(Handle<Code> code) {
561 CALL_HEAP_FUNCTION(Heap::CopyCode(*code), Code);
562}
563
564
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000565Handle<Code> Factory::CopyCode(Handle<Code> code, Vector<byte> reloc_info) {
566 CALL_HEAP_FUNCTION(Heap::CopyCode(*code, reloc_info), Code);
567}
568
569
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000570static inline Object* DoCopyInsert(DescriptorArray* array,
571 String* key,
572 Object* value,
573 PropertyAttributes attributes) {
574 CallbacksDescriptor desc(key, value, attributes);
575 Object* obj = array->CopyInsert(&desc, REMOVE_TRANSITIONS);
576 return obj;
577}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000578
579
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000580// Allocate the new array.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000581Handle<DescriptorArray> Factory::CopyAppendProxyDescriptor(
582 Handle<DescriptorArray> array,
583 Handle<String> key,
584 Handle<Object> value,
585 PropertyAttributes attributes) {
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +0000586 CALL_HEAP_FUNCTION(DoCopyInsert(*array, *key, *value, attributes),
587 DescriptorArray);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000588}
589
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000590
591Handle<String> Factory::SymbolFromString(Handle<String> value) {
592 CALL_HEAP_FUNCTION(Heap::LookupSymbol(*value), String);
593}
594
595
596Handle<DescriptorArray> Factory::CopyAppendCallbackDescriptors(
597 Handle<DescriptorArray> array,
598 Handle<Object> descriptors) {
599 v8::NeanderArray callbacks(descriptors);
600 int nof_callbacks = callbacks.length();
601 Handle<DescriptorArray> result =
602 NewDescriptorArray(array->number_of_descriptors() + nof_callbacks);
603
604 // Number of descriptors added to the result so far.
605 int descriptor_count = 0;
606
607 // Copy the descriptors from the array.
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000608 for (int i = 0; i < array->number_of_descriptors(); i++) {
609 if (array->GetType(i) != NULL_DESCRIPTOR) {
610 result->CopyFrom(descriptor_count++, *array, i);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000611 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000612 }
613
614 // Number of duplicates detected.
615 int duplicates = 0;
616
617 // Fill in new callback descriptors. Process the callbacks from
618 // back to front so that the last callback with a given name takes
619 // precedence over previously added callbacks with that name.
620 for (int i = nof_callbacks - 1; i >= 0; i--) {
621 Handle<AccessorInfo> entry =
622 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i)));
623 // Ensure the key is a symbol before writing into the instance descriptor.
624 Handle<String> key =
625 SymbolFromString(Handle<String>(String::cast(entry->name())));
626 // Check if a descriptor with this name already exists before writing.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000627 if (result->LinearSearch(*key, descriptor_count) ==
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000628 DescriptorArray::kNotFound) {
629 CallbacksDescriptor desc(*key, *entry, entry->property_attributes());
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000630 result->Set(descriptor_count, &desc);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000631 descriptor_count++;
632 } else {
633 duplicates++;
634 }
635 }
636
637 // If duplicates were detected, allocate a result of the right size
638 // and transfer the elements.
639 if (duplicates > 0) {
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000640 int number_of_descriptors = result->number_of_descriptors() - duplicates;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000641 Handle<DescriptorArray> new_result =
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000642 NewDescriptorArray(number_of_descriptors);
643 for (int i = 0; i < number_of_descriptors; i++) {
644 new_result->CopyFrom(i, *result, i);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000645 }
646 result = new_result;
647 }
648
649 // Sort the result before returning.
650 result->Sort();
651 return result;
652}
653
654
655Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
656 PretenureFlag pretenure) {
657 CALL_HEAP_FUNCTION(Heap::AllocateJSObject(*constructor, pretenure), JSObject);
658}
659
660
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000661Handle<GlobalObject> Factory::NewGlobalObject(
662 Handle<JSFunction> constructor) {
663 CALL_HEAP_FUNCTION(Heap::AllocateGlobalObject(*constructor),
664 GlobalObject);
665}
666
667
668
ager@chromium.org236ad962008-09-25 09:45:57 +0000669Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map) {
670 CALL_HEAP_FUNCTION(Heap::AllocateJSObjectFromMap(*map, NOT_TENURED),
671 JSObject);
672}
673
674
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000675Handle<JSArray> Factory::NewJSArray(int length,
676 PretenureFlag pretenure) {
677 Handle<JSObject> obj = NewJSObject(Top::array_function(), pretenure);
678 CALL_HEAP_FUNCTION(Handle<JSArray>::cast(obj)->Initialize(length), JSArray);
679}
680
681
682Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArray> elements,
683 PretenureFlag pretenure) {
684 Handle<JSArray> result =
685 Handle<JSArray>::cast(NewJSObject(Top::array_function(), pretenure));
686 result->SetContent(*elements);
687 return result;
688}
689
690
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000691Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000692 Handle<String> name,
693 int number_of_literals,
694 Handle<Code> code,
ager@chromium.orgb5737492010-07-15 09:29:43 +0000695 Handle<SerializedScopeInfo> scope_info) {
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000696 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name);
697 shared->set_code(*code);
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000698 shared->set_scope_info(*scope_info);
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000699 int literals_array_size = number_of_literals;
700 // If the function contains object, regexp or array literals,
701 // allocate extra space for a literals array prefix containing the
702 // context.
703 if (number_of_literals > 0) {
704 literals_array_size += JSFunction::kLiteralsPrefixSize;
705 }
706 shared->set_num_literals(literals_array_size);
707 return shared;
708}
709
710
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000711Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(Handle<String> name) {
712 CALL_HEAP_FUNCTION(Heap::AllocateSharedFunctionInfo(*name),
713 SharedFunctionInfo);
714}
715
716
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000717Handle<String> Factory::NumberToString(Handle<Object> number) {
718 CALL_HEAP_FUNCTION(Heap::NumberToString(*number), String);
719}
720
721
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000722Handle<NumberDictionary> Factory::DictionaryAtNumberPut(
723 Handle<NumberDictionary> dictionary,
724 uint32_t key,
725 Handle<Object> value) {
726 CALL_HEAP_FUNCTION(dictionary->AtNumberPut(key, *value), NumberDictionary);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000727}
728
729
730Handle<JSFunction> Factory::NewFunctionHelper(Handle<String> name,
731 Handle<Object> prototype) {
732 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
733 CALL_HEAP_FUNCTION(Heap::AllocateFunction(*Top::function_map(),
734 *function_share,
735 *prototype),
736 JSFunction);
737}
738
739
740Handle<JSFunction> Factory::NewFunction(Handle<String> name,
741 Handle<Object> prototype) {
742 Handle<JSFunction> fun = NewFunctionHelper(name, prototype);
743 fun->set_context(Top::context()->global_context());
744 return fun;
745}
746
747
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000748Handle<JSFunction> Factory::NewFunctionWithoutPrototypeHelper(
749 Handle<String> name) {
750 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
751 CALL_HEAP_FUNCTION(Heap::AllocateFunction(
752 *Top::function_without_prototype_map(),
753 *function_share,
754 *the_hole_value()),
755 JSFunction);
756}
757
758
759Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name) {
760 Handle<JSFunction> fun = NewFunctionWithoutPrototypeHelper(name);
761 fun->set_context(Top::context()->global_context());
762 return fun;
763}
764
765
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000766Handle<Object> Factory::ToObject(Handle<Object> object) {
767 CALL_HEAP_FUNCTION(object->ToObject(), Object);
768}
769
770
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000771Handle<Object> Factory::ToObject(Handle<Object> object,
772 Handle<Context> global_context) {
773 CALL_HEAP_FUNCTION(object->ToObject(*global_context), Object);
774}
775
776
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000777#ifdef ENABLE_DEBUGGER_SUPPORT
v8.team.kasperl727e9952008-09-02 14:56:44 +0000778Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
779 // Get the original code of the function.
780 Handle<Code> code(shared->code());
781
782 // Create a copy of the code before allocating the debug info object to avoid
783 // allocation while setting up the debug info object.
784 Handle<Code> original_code(*Factory::CopyCode(code));
785
786 // Allocate initial fixed array for active break points before allocating the
787 // debug info object to avoid allocation while setting up the debug info
788 // object.
789 Handle<FixedArray> break_points(
790 Factory::NewFixedArray(Debug::kEstimatedNofBreakPointsInFunction));
791
792 // Create and set up the debug info object. Debug info contains function, a
793 // copy of the original code, the executing code and initial fixed array for
794 // active break points.
795 Handle<DebugInfo> debug_info =
796 Handle<DebugInfo>::cast(Factory::NewStruct(DEBUG_INFO_TYPE));
797 debug_info->set_shared(*shared);
798 debug_info->set_original_code(*original_code);
799 debug_info->set_code(*code);
800 debug_info->set_break_points(*break_points);
801
802 // Link debug info to function.
803 shared->set_debug_info(*debug_info);
804
805 return debug_info;
806}
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000807#endif
v8.team.kasperl727e9952008-09-02 14:56:44 +0000808
809
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000810Handle<JSObject> Factory::NewArgumentsObject(Handle<Object> callee,
811 int length) {
812 CALL_HEAP_FUNCTION(Heap::AllocateArgumentsObject(*callee, length), JSObject);
813}
814
815
816Handle<JSFunction> Factory::CreateApiFunction(
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000817 Handle<FunctionTemplateInfo> obj, ApiInstanceType instance_type) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000818 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::HandleApiCall));
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000819 Handle<Code> construct_stub =
820 Handle<Code>(Builtins::builtin(Builtins::JSConstructStubApi));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000821
kasper.lund212ac232008-07-16 07:07:30 +0000822 int internal_field_count = 0;
823 if (!obj->instance_template()->IsUndefined()) {
824 Handle<ObjectTemplateInfo> instance_template =
825 Handle<ObjectTemplateInfo>(
826 ObjectTemplateInfo::cast(obj->instance_template()));
827 internal_field_count =
828 Smi::cast(instance_template->internal_field_count())->value();
829 }
830
831 int instance_size = kPointerSize * internal_field_count;
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000832 InstanceType type = INVALID_TYPE;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000833 switch (instance_type) {
834 case JavaScriptObject:
835 type = JS_OBJECT_TYPE;
836 instance_size += JSObject::kHeaderSize;
837 break;
838 case InnerGlobalObject:
839 type = JS_GLOBAL_OBJECT_TYPE;
840 instance_size += JSGlobalObject::kSize;
841 break;
842 case OuterGlobalObject:
843 type = JS_GLOBAL_PROXY_TYPE;
844 instance_size += JSGlobalProxy::kSize;
845 break;
846 default:
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000847 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000848 }
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000849 ASSERT(type != INVALID_TYPE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000850
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000851 Handle<JSFunction> result =
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000852 Factory::NewFunction(Factory::empty_symbol(),
853 type,
854 instance_size,
855 code,
856 true);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000857 // Set class name.
858 Handle<Object> class_name = Handle<Object>(obj->class_name());
859 if (class_name->IsString()) {
860 result->shared()->set_instance_class_name(*class_name);
861 result->shared()->set_name(*class_name);
862 }
863
864 Handle<Map> map = Handle<Map>(result->initial_map());
865
866 // Mark as undetectable if needed.
867 if (obj->undetectable()) {
868 map->set_is_undetectable();
869 }
870
871 // Mark as hidden for the __proto__ accessor if needed.
872 if (obj->hidden_prototype()) {
873 map->set_is_hidden_prototype();
874 }
875
876 // Mark as needs_access_check if needed.
877 if (obj->needs_access_check()) {
ager@chromium.org870a0b62008-11-04 11:43:05 +0000878 map->set_is_access_check_needed(true);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000879 }
880
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000881 // Set interceptor information in the map.
882 if (!obj->named_property_handler()->IsUndefined()) {
883 map->set_has_named_interceptor();
884 }
885 if (!obj->indexed_property_handler()->IsUndefined()) {
886 map->set_has_indexed_interceptor();
887 }
888
889 // Set instance call-as-function information in the map.
890 if (!obj->instance_call_handler()->IsUndefined()) {
891 map->set_has_instance_call_handler();
892 }
893
894 result->shared()->set_function_data(*obj);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000895 result->shared()->set_construct_stub(*construct_stub);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000896 result->shared()->DontAdaptArguments();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000897
898 // Recursively copy parent templates' accessors, 'data' may be modified.
899 Handle<DescriptorArray> array =
900 Handle<DescriptorArray>(map->instance_descriptors());
901 while (true) {
902 Handle<Object> props = Handle<Object>(obj->property_accessors());
903 if (!props->IsUndefined()) {
904 array = Factory::CopyAppendCallbackDescriptors(array, props);
905 }
906 Handle<Object> parent = Handle<Object>(obj->parent_template());
907 if (parent->IsUndefined()) break;
908 obj = Handle<FunctionTemplateInfo>::cast(parent);
909 }
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000910 if (!array->IsEmpty()) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000911 map->set_instance_descriptors(*array);
912 }
913
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000914 ASSERT(result->shared()->IsApiFunction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000915 return result;
916}
917
918
ager@chromium.org236ad962008-09-25 09:45:57 +0000919Handle<MapCache> Factory::NewMapCache(int at_least_space_for) {
920 CALL_HEAP_FUNCTION(MapCache::Allocate(at_least_space_for), MapCache);
921}
922
923
924static Object* UpdateMapCacheWith(Context* context,
925 FixedArray* keys,
926 Map* map) {
927 Object* result = MapCache::cast(context->map_cache())->Put(keys, map);
928 if (!result->IsFailure()) context->set_map_cache(MapCache::cast(result));
929 return result;
930}
931
932
933Handle<MapCache> Factory::AddToMapCache(Handle<Context> context,
934 Handle<FixedArray> keys,
935 Handle<Map> map) {
936 CALL_HEAP_FUNCTION(UpdateMapCacheWith(*context, *keys, *map), MapCache);
937}
938
939
940Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
941 Handle<FixedArray> keys) {
942 if (context->map_cache()->IsUndefined()) {
943 // Allocate the new map cache for the global context.
944 Handle<MapCache> new_cache = NewMapCache(24);
945 context->set_map_cache(*new_cache);
946 }
ager@chromium.org32912102009-01-16 10:38:43 +0000947 // Check to see whether there is a matching element in the cache.
ager@chromium.org236ad962008-09-25 09:45:57 +0000948 Handle<MapCache> cache =
949 Handle<MapCache>(MapCache::cast(context->map_cache()));
950 Handle<Object> result = Handle<Object>(cache->Lookup(*keys));
951 if (result->IsMap()) return Handle<Map>::cast(result);
952 // Create a new map and add it to the cache.
953 Handle<Map> map =
ager@chromium.org32912102009-01-16 10:38:43 +0000954 CopyMap(Handle<Map>(context->object_function()->initial_map()),
955 keys->length());
ager@chromium.org236ad962008-09-25 09:45:57 +0000956 AddToMapCache(context, keys, map);
957 return Handle<Map>(map);
958}
959
960
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000961void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp,
962 JSRegExp::Type type,
963 Handle<String> source,
964 JSRegExp::Flags flags,
965 Handle<Object> data) {
966 Handle<FixedArray> store = NewFixedArray(JSRegExp::kAtomDataSize);
967
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000968 store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
969 store->set(JSRegExp::kSourceIndex, *source);
970 store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
971 store->set(JSRegExp::kAtomPatternIndex, *data);
972 regexp->set_data(*store);
973}
974
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000975void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp,
976 JSRegExp::Type type,
977 Handle<String> source,
978 JSRegExp::Flags flags,
979 int capture_count) {
980 Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize);
981
982 store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
983 store->set(JSRegExp::kSourceIndex, *source);
984 store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags.value()));
985 store->set(JSRegExp::kIrregexpASCIICodeIndex, Heap::the_hole_value());
986 store->set(JSRegExp::kIrregexpUC16CodeIndex, Heap::the_hole_value());
987 store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0));
988 store->set(JSRegExp::kIrregexpCaptureCountIndex,
989 Smi::FromInt(capture_count));
990 regexp->set_data(*store);
991}
992
993
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000994
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000995void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc,
996 Handle<JSObject> instance,
997 bool* pending_exception) {
998 // Configure the instance by adding the properties specified by the
999 // instance template.
1000 Handle<Object> instance_template = Handle<Object>(desc->instance_template());
1001 if (!instance_template->IsUndefined()) {
1002 Execution::ConfigureInstance(instance,
1003 instance_template,
1004 pending_exception);
1005 } else {
1006 *pending_exception = false;
1007 }
1008}
1009
1010
1011} } // namespace v8::internal