Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/factory.cc

Issue 237093006: Function allocators handlified. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing review comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/factory.h ('k') | src/handles.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "factory.h" 5 #include "factory.h"
6 6
7 #include "isolate-inl.h" 7 #include "isolate-inl.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 11
12
13 template<typename T>
14 Handle<T> Factory::New(Handle<Map> map, AllocationSpace space) {
15 CALL_HEAP_FUNCTION(
16 isolate(),
17 isolate()->heap()->Allocate(*map, space),
18 T);
19 }
20
21
22 template<typename T>
23 Handle<T> Factory::New(Handle<Map> map,
24 AllocationSpace space,
25 Handle<AllocationSite> allocation_site) {
26 CALL_HEAP_FUNCTION(
27 isolate(),
28 isolate()->heap()->Allocate(*map, space, *allocation_site),
29 T);
30 }
31
32
12 Handle<Box> Factory::NewBox(Handle<Object> value) { 33 Handle<Box> Factory::NewBox(Handle<Object> value) {
13 Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE)); 34 Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE));
14 result->set_value(*value); 35 result->set_value(*value);
15 return result; 36 return result;
16 } 37 }
17 38
18 39
19 Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) { 40 Handle<FixedArray> Factory::NewFixedArray(int size, PretenureFlag pretenure) {
20 ASSERT(0 <= size); 41 ASSERT(0 <= size);
21 CALL_HEAP_FUNCTION( 42 CALL_HEAP_FUNCTION(
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 SinkChar* sink = result->GetChars(); 361 SinkChar* sink = result->GetChars();
341 String::WriteToFlat(*first, sink, 0, first->length()); 362 String::WriteToFlat(*first, sink, 0, first->length());
342 String::WriteToFlat(*second, sink + first->length(), 0, second->length()); 363 String::WriteToFlat(*second, sink + first->length(), 0, second->length());
343 return result; 364 return result;
344 } 365 }
345 366
346 367
347 Handle<ConsString> Factory::NewRawConsString(String::Encoding encoding) { 368 Handle<ConsString> Factory::NewRawConsString(String::Encoding encoding) {
348 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING) 369 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING)
349 ? cons_ascii_string_map() : cons_string_map(); 370 ? cons_ascii_string_map() : cons_string_map();
350 CALL_HEAP_FUNCTION(isolate(), 371 return New<ConsString>(map, NEW_SPACE);
351 isolate()->heap()->Allocate(*map, NEW_SPACE),
352 ConsString);
353 } 372 }
354 373
355 374
356 MaybeHandle<String> Factory::NewConsString(Handle<String> left, 375 MaybeHandle<String> Factory::NewConsString(Handle<String> left,
357 Handle<String> right) { 376 Handle<String> right) {
358 int left_length = left->length(); 377 int left_length = left->length();
359 if (left_length == 0) return right; 378 if (left_length == 0) return right;
360 int right_length = right->length(); 379 int right_length = right->length();
361 if (right_length == 0) return left; 380 if (right_length == 0) return left;
362 381
363 int length = left_length + right_length; 382 int length = left_length + right_length;
364 383
365 if (length == 2) { 384 if (length == 2) {
366 uint16_t c1 = left->Get(0); 385 uint16_t c1 = left->Get(0);
367 uint16_t c2 = right->Get(0); 386 uint16_t c2 = right->Get(0);
368 return MakeOrFindTwoCharacterString(isolate(), c1, c2); 387 return MakeOrFindTwoCharacterString(isolate(), c1, c2);
369 } 388 }
370 389
371 // Make sure that an out of memory exception is thrown if the length 390 // Make sure that an out of memory exception is thrown if the length
372 // of the new cons string is too large. 391 // of the new cons string is too large.
373 if (length > String::kMaxLength || length < 0) { 392 if (length > String::kMaxLength || length < 0) {
374 return isolate()->Throw<String>( 393 return isolate()->Throw<String>(NewInvalidStringLengthError());
375 isolate()->factory()->NewInvalidStringLengthError());
376 } 394 }
377 395
378 bool left_is_one_byte = left->IsOneByteRepresentation(); 396 bool left_is_one_byte = left->IsOneByteRepresentation();
379 bool right_is_one_byte = right->IsOneByteRepresentation(); 397 bool right_is_one_byte = right->IsOneByteRepresentation();
380 bool is_one_byte = left_is_one_byte && right_is_one_byte; 398 bool is_one_byte = left_is_one_byte && right_is_one_byte;
381 bool is_one_byte_data_in_two_byte_string = false; 399 bool is_one_byte_data_in_two_byte_string = false;
382 if (!is_one_byte) { 400 if (!is_one_byte) {
383 // At least one of the strings uses two-byte representation so we 401 // At least one of the strings uses two-byte representation so we
384 // can't use the fast case code for short ASCII strings below, but 402 // can't use the fast case code for short ASCII strings below, but
385 // we can try to save memory if all chars actually fit in ASCII. 403 // we can try to save memory if all chars actually fit in ASCII.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } else { 466 } else {
449 return ConcatStringContent<uc16>( 467 return ConcatStringContent<uc16>(
450 NewRawTwoByteString(total_length).ToHandleChecked(), first, second); 468 NewRawTwoByteString(total_length).ToHandleChecked(), first, second);
451 } 469 }
452 } 470 }
453 471
454 472
455 Handle<SlicedString> Factory::NewRawSlicedString(String::Encoding encoding) { 473 Handle<SlicedString> Factory::NewRawSlicedString(String::Encoding encoding) {
456 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING) 474 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING)
457 ? sliced_ascii_string_map() : sliced_string_map(); 475 ? sliced_ascii_string_map() : sliced_string_map();
458 CALL_HEAP_FUNCTION(isolate(), 476 return New<SlicedString>(map, NEW_SPACE);
459 isolate()->heap()->Allocate(*map, NEW_SPACE),
460 SlicedString);
461 } 477 }
462 478
463 479
464 Handle<String> Factory::NewProperSubString(Handle<String> str, 480 Handle<String> Factory::NewProperSubString(Handle<String> str,
465 int begin, 481 int begin,
466 int end) { 482 int end) {
467 #if VERIFY_HEAP 483 #if VERIFY_HEAP
468 if (FLAG_verify_heap) str->StringVerify(); 484 if (FLAG_verify_heap) str->StringVerify();
469 #endif 485 #endif
470 ASSERT(begin > 0 || end < str->length()); 486 ASSERT(begin > 0 || end < str->length());
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); 905 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray);
890 } 906 }
891 907
892 908
893 Handle<ConstantPoolArray> Factory::CopyConstantPoolArray( 909 Handle<ConstantPoolArray> Factory::CopyConstantPoolArray(
894 Handle<ConstantPoolArray> array) { 910 Handle<ConstantPoolArray> array) {
895 CALL_HEAP_FUNCTION(isolate(), array->Copy(), ConstantPoolArray); 911 CALL_HEAP_FUNCTION(isolate(), array->Copy(), ConstantPoolArray);
896 } 912 }
897 913
898 914
899 Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo(
900 Handle<SharedFunctionInfo> function_info,
901 Handle<Map> function_map,
902 PretenureFlag pretenure) {
903 CALL_HEAP_FUNCTION(
904 isolate(),
905 isolate()->heap()->AllocateFunction(*function_map,
906 *function_info,
907 isolate()->heap()->the_hole_value(),
908 pretenure),
909 JSFunction);
910 }
911
912
913 static Handle<Map> MapForNewFunction(Isolate *isolate, 915 static Handle<Map> MapForNewFunction(Isolate *isolate,
914 Handle<SharedFunctionInfo> function_info) { 916 Handle<SharedFunctionInfo> function_info) {
915 Context *context = isolate->context()->native_context(); 917 Context *context = isolate->context()->native_context();
916 int map_index = Context::FunctionMapIndex(function_info->strict_mode(), 918 int map_index = Context::FunctionMapIndex(function_info->strict_mode(),
917 function_info->is_generator()); 919 function_info->is_generator());
918 return Handle<Map>(Map::cast(context->get(map_index))); 920 return Handle<Map>(Map::cast(context->get(map_index)));
919 } 921 }
920 922
921 923
922 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( 924 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
923 Handle<SharedFunctionInfo> function_info, 925 Handle<SharedFunctionInfo> function_info,
924 Handle<Context> context, 926 Handle<Context> context,
925 PretenureFlag pretenure) { 927 PretenureFlag pretenure) {
926 Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo( 928 Handle<JSFunction> result = NewFunctionHelper(
929 MapForNewFunction(isolate(), function_info),
927 function_info, 930 function_info,
928 MapForNewFunction(isolate(), function_info), 931 the_hole_value(),
929 pretenure); 932 pretenure);
930 933
931 if (function_info->ic_age() != isolate()->heap()->global_ic_age()) { 934 if (function_info->ic_age() != isolate()->heap()->global_ic_age()) {
932 function_info->ResetForNewContext(isolate()->heap()->global_ic_age()); 935 function_info->ResetForNewContext(isolate()->heap()->global_ic_age());
933 } 936 }
934 937
935 result->set_context(*context); 938 result->set_context(*context);
936 939
937 int index = function_info->SearchOptimizedCodeMap(context->native_context(), 940 int index = function_info->SearchOptimizedCodeMap(context->native_context(),
938 BailoutId::None()); 941 BailoutId::None());
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 static Handle<NameDictionary> NameDictionaryAdd(Handle<NameDictionary> dict, 1339 static Handle<NameDictionary> NameDictionaryAdd(Handle<NameDictionary> dict,
1337 Handle<Name> name, 1340 Handle<Name> name,
1338 Handle<Object> value, 1341 Handle<Object> value,
1339 PropertyDetails details) { 1342 PropertyDetails details) {
1340 CALL_HEAP_FUNCTION(dict->GetIsolate(), 1343 CALL_HEAP_FUNCTION(dict->GetIsolate(),
1341 dict->Add(*name, *value, details), 1344 dict->Add(*name, *value, details),
1342 NameDictionary); 1345 NameDictionary);
1343 } 1346 }
1344 1347
1345 1348
1346 static Handle<GlobalObject> NewGlobalObjectFromMap(Isolate* isolate,
1347 Handle<Map> map) {
1348 CALL_HEAP_FUNCTION(isolate,
1349 isolate->heap()->Allocate(*map, OLD_POINTER_SPACE),
1350 GlobalObject);
1351 }
1352
1353
1354 Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) { 1349 Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) {
1355 ASSERT(constructor->has_initial_map()); 1350 ASSERT(constructor->has_initial_map());
1356 Handle<Map> map(constructor->initial_map()); 1351 Handle<Map> map(constructor->initial_map());
1357 ASSERT(map->is_dictionary_map()); 1352 ASSERT(map->is_dictionary_map());
1358 1353
1359 // Make sure no field properties are described in the initial map. 1354 // Make sure no field properties are described in the initial map.
1360 // This guarantees us that normalizing the properties does not 1355 // This guarantees us that normalizing the properties does not
1361 // require us to change property values to PropertyCells. 1356 // require us to change property values to PropertyCells.
1362 ASSERT(map->NextFreePropertyIndex() == 0); 1357 ASSERT(map->NextFreePropertyIndex() == 0);
1363 1358
(...skipping 18 matching lines...) Expand all
1382 PropertyDetails details = descs->GetDetails(i); 1377 PropertyDetails details = descs->GetDetails(i);
1383 ASSERT(details.type() == CALLBACKS); // Only accessors are expected. 1378 ASSERT(details.type() == CALLBACKS); // Only accessors are expected.
1384 PropertyDetails d = PropertyDetails(details.attributes(), CALLBACKS, i + 1); 1379 PropertyDetails d = PropertyDetails(details.attributes(), CALLBACKS, i + 1);
1385 Handle<Name> name(descs->GetKey(i)); 1380 Handle<Name> name(descs->GetKey(i));
1386 Handle<Object> value(descs->GetCallbacksObject(i), isolate()); 1381 Handle<Object> value(descs->GetCallbacksObject(i), isolate());
1387 Handle<PropertyCell> cell = NewPropertyCell(value); 1382 Handle<PropertyCell> cell = NewPropertyCell(value);
1388 NameDictionaryAdd(dictionary, name, cell, d); 1383 NameDictionaryAdd(dictionary, name, cell, d);
1389 } 1384 }
1390 1385
1391 // Allocate the global object and initialize it with the backing store. 1386 // Allocate the global object and initialize it with the backing store.
1392 Handle<GlobalObject> global = NewGlobalObjectFromMap(isolate(), map); 1387 Handle<GlobalObject> global = New<GlobalObject>(map, OLD_POINTER_SPACE);
1393 isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map); 1388 isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map);
1394 1389
1395 // Create a new map for the global object. 1390 // Create a new map for the global object.
1396 Handle<Map> new_map = Map::CopyDropDescriptors(map); 1391 Handle<Map> new_map = Map::CopyDropDescriptors(map);
1397 new_map->set_dictionary_map(true); 1392 new_map->set_dictionary_map(true);
1398 1393
1399 // Set up the global object as a normalized object. 1394 // Set up the global object as a normalized object.
1400 global->set_map(*new_map); 1395 global->set_map(*new_map);
1401 global->set_properties(*dictionary); 1396 global->set_properties(*dictionary);
1402 1397
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 NewJSArrayStorage(array, length, capacity, mode); 1437 NewJSArrayStorage(array, length, capacity, mode);
1443 return array; 1438 return array;
1444 } 1439 }
1445 1440
1446 1441
1447 Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements, 1442 Handle<JSArray> Factory::NewJSArrayWithElements(Handle<FixedArrayBase> elements,
1448 ElementsKind elements_kind, 1443 ElementsKind elements_kind,
1449 int length, 1444 int length,
1450 PretenureFlag pretenure) { 1445 PretenureFlag pretenure) {
1451 ASSERT(length <= elements->length()); 1446 ASSERT(length <= elements->length());
1452 Handle<JSArray> array = 1447 Handle<JSArray> array = NewJSArray(elements_kind, pretenure);
1453 isolate()->factory()->NewJSArray(elements_kind, pretenure);
1454 1448
1455 array->set_elements(*elements); 1449 array->set_elements(*elements);
1456 array->set_length(Smi::FromInt(length)); 1450 array->set_length(Smi::FromInt(length));
1457 JSObject::ValidateElements(array); 1451 JSObject::ValidateElements(array);
1458 return array; 1452 return array;
1459 } 1453 }
1460 1454
1461 1455
1462 void Factory::NewJSArrayStorage(Handle<JSArray> array, 1456 void Factory::NewJSArrayStorage(Handle<JSArray> array,
1463 int length, 1457 int length,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 1552
1559 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, 1553 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
1560 Handle<Object> prototype) { 1554 Handle<Object> prototype) {
1561 CALL_HEAP_FUNCTION( 1555 CALL_HEAP_FUNCTION(
1562 isolate(), 1556 isolate(),
1563 isolate()->heap()->AllocateJSProxy(*handler, *prototype), 1557 isolate()->heap()->AllocateJSProxy(*handler, *prototype),
1564 JSProxy); 1558 JSProxy);
1565 } 1559 }
1566 1560
1567 1561
1562 void Factory::ReinitializeJSReceiver(Handle<JSReceiver> object,
1563 InstanceType type,
1564 int size) {
1565 ASSERT(type >= FIRST_JS_OBJECT_TYPE);
1566
1567 // Allocate fresh map.
1568 // TODO(rossberg): Once we optimize proxies, cache these maps.
1569 Handle<Map> map = NewMap(type, size);
1570
1571 // Check that the receiver has at least the size of the fresh object.
1572 int size_difference = object->map()->instance_size() - map->instance_size();
1573 ASSERT(size_difference >= 0);
1574
1575 map->set_prototype(object->map()->prototype());
1576
1577 // Allocate the backing storage for the properties.
1578 int prop_size = map->unused_property_fields() - map->inobject_properties();
1579 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED);
1580
1581 Heap* heap = isolate()->heap();
1582 MaybeHandle<SharedFunctionInfo> shared;
1583 if (type == JS_FUNCTION_TYPE) {
1584 OneByteStringKey key(STATIC_ASCII_VECTOR("<freezing call trap>"),
1585 heap->HashSeed());
1586 Handle<String> name = InternalizeStringWithKey(&key);
1587 shared = NewSharedFunctionInfo(name);
1588 }
1589
1590 // In order to keep heap in consistent state there must be no allocations
1591 // before object re-initialization is finished and filler object is installed.
1592 DisallowHeapAllocation no_allocation;
1593
1594 // Reset the map for the object.
1595 object->set_map(*map);
1596 Handle<JSObject> jsobj = Handle<JSObject>::cast(object);
1597
1598 // Reinitialize the object from the constructor map.
1599 heap->InitializeJSObjectFromMap(*jsobj, *properties, *map);
1600
1601 // Functions require some minimal initialization.
1602 if (type == JS_FUNCTION_TYPE) {
1603 map->set_function_with_prototype(true);
1604 Handle<JSFunction> js_function = Handle<JSFunction>::cast(object);
1605 InitializeFunction(js_function, shared.ToHandleChecked(), the_hole_value());
1606 js_function->set_context(isolate()->context()->native_context());
1607 }
1608
1609 // Put in filler if the new object is smaller than the old.
1610 if (size_difference > 0) {
1611 heap->CreateFillerObjectAt(
1612 object->address() + map->instance_size(), size_difference);
1613 }
1614 }
1615
1616
1617 void Factory::ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> object,
1618 Handle<JSFunction> constructor) {
1619 ASSERT(constructor->has_initial_map());
1620 Handle<Map> map(constructor->initial_map(), isolate());
1621
1622 // Check that the already allocated object has the same size and type as
1623 // objects allocated using the constructor.
1624 ASSERT(map->instance_size() == object->map()->instance_size());
1625 ASSERT(map->instance_type() == object->map()->instance_type());
1626
1627 // Allocate the backing storage for the properties.
1628 int prop_size = map->unused_property_fields() - map->inobject_properties();
1629 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED);
1630
1631 // In order to keep heap in consistent state there must be no allocations
1632 // before object re-initialization is finished.
1633 DisallowHeapAllocation no_allocation;
1634
1635 // Reset the map for the object.
1636 object->set_map(constructor->initial_map());
1637
1638 Heap* heap = isolate()->heap();
1639 // Reinitialize the object from the constructor map.
1640 heap->InitializeJSObjectFromMap(*object, *properties, *map);
1641 }
1642
1643
1568 void Factory::BecomeJSObject(Handle<JSReceiver> object) { 1644 void Factory::BecomeJSObject(Handle<JSReceiver> object) {
1569 CALL_HEAP_FUNCTION_VOID( 1645 ReinitializeJSReceiver(object, JS_OBJECT_TYPE, JSObject::kHeaderSize);
1570 isolate(),
1571 isolate()->heap()->ReinitializeJSReceiver(
1572 *object, JS_OBJECT_TYPE, JSObject::kHeaderSize));
1573 } 1646 }
1574 1647
1575 1648
1576 void Factory::BecomeJSFunction(Handle<JSReceiver> object) { 1649 void Factory::BecomeJSFunction(Handle<JSReceiver> object) {
1577 CALL_HEAP_FUNCTION_VOID( 1650 ReinitializeJSReceiver(object, JS_FUNCTION_TYPE, JSFunction::kSize);
1578 isolate(),
1579 isolate()->heap()->ReinitializeJSReceiver(
1580 *object, JS_FUNCTION_TYPE, JSFunction::kSize));
1581 } 1651 }
1582 1652
1583 1653
1584 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( 1654 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
1585 Handle<String> name, 1655 Handle<String> name,
1586 int number_of_literals, 1656 int number_of_literals,
1587 bool is_generator, 1657 bool is_generator,
1588 Handle<Code> code, 1658 Handle<Code> code,
1589 Handle<ScopeInfo> scope_info) { 1659 Handle<ScopeInfo> scope_info) {
1590 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name); 1660 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 Handle<UnseededNumberDictionary> Factory::DictionaryAtNumberPut( 1726 Handle<UnseededNumberDictionary> Factory::DictionaryAtNumberPut(
1657 Handle<UnseededNumberDictionary> dictionary, 1727 Handle<UnseededNumberDictionary> dictionary,
1658 uint32_t key, 1728 uint32_t key,
1659 Handle<Object> value) { 1729 Handle<Object> value) {
1660 CALL_HEAP_FUNCTION(isolate(), 1730 CALL_HEAP_FUNCTION(isolate(),
1661 dictionary->AtNumberPut(key, *value), 1731 dictionary->AtNumberPut(key, *value),
1662 UnseededNumberDictionary); 1732 UnseededNumberDictionary);
1663 } 1733 }
1664 1734
1665 1735
1666 Handle<JSFunction> Factory::NewFunctionHelper(Handle<String> name, 1736 void Factory::InitializeFunction(Handle<JSFunction> function,
1667 Handle<Object> prototype) { 1737 Handle<SharedFunctionInfo> shared,
1668 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); 1738 Handle<Object> prototype) {
1669 CALL_HEAP_FUNCTION( 1739 ASSERT(!prototype->IsMap());
1670 isolate(), 1740 function->initialize_properties();
1671 isolate()->heap()->AllocateFunction(*isolate()->sloppy_function_map(), 1741 function->initialize_elements();
1672 *function_share, 1742 function->set_shared(*shared);
1673 *prototype), 1743 function->set_code(shared->code());
1674 JSFunction); 1744 function->set_prototype_or_initial_map(*prototype);
1745 function->set_context(*undefined_value());
1746 function->set_literals_or_bindings(*empty_fixed_array());
1747 function->set_next_function_link(*undefined_value());
1748 }
1749
1750
1751 Handle<JSFunction> Factory::NewFunctionHelper(Handle<Map> function_map,
1752 Handle<SharedFunctionInfo> shared,
1753 Handle<Object> prototype,
1754 PretenureFlag pretenure) {
1755 AllocationSpace space =
1756 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
1757 Handle<JSFunction> fun = New<JSFunction>(function_map, space);
1758 InitializeFunction(fun, shared, prototype);
1759 return fun;
1675 } 1760 }
1676 1761
1677 1762
1678 Handle<JSFunction> Factory::NewFunction(Handle<String> name, 1763 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
1679 Handle<Object> prototype) { 1764 Handle<Object> prototype) {
1680 Handle<JSFunction> fun = NewFunctionHelper(name, prototype); 1765 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
1766 Handle<JSFunction> fun = NewFunctionHelper(
1767 isolate()->sloppy_function_map(), function_share, prototype);
1681 fun->set_context(isolate()->context()->native_context()); 1768 fun->set_context(isolate()->context()->native_context());
1682 return fun; 1769 return fun;
1683 } 1770 }
1684 1771
1685 1772
1686 Handle<JSFunction> Factory::NewFunctionWithoutPrototypeHelper( 1773 Handle<JSFunction> Factory::NewFunctionWithoutPrototype(
1687 Handle<String> name, 1774 Handle<String> name,
1688 StrictMode strict_mode) { 1775 StrictMode strict_mode) {
1689 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); 1776 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
1690 Handle<Map> map = strict_mode == SLOPPY 1777 Handle<Map> map = strict_mode == SLOPPY
1691 ? isolate()->sloppy_function_without_prototype_map() 1778 ? isolate()->sloppy_function_without_prototype_map()
1692 : isolate()->strict_function_without_prototype_map(); 1779 : isolate()->strict_function_without_prototype_map();
1693 CALL_HEAP_FUNCTION(isolate(), 1780 Handle<JSFunction> fun =
1694 isolate()->heap()->AllocateFunction( 1781 NewFunctionHelper(map, function_share, the_hole_value());
1695 *map,
1696 *function_share,
1697 *the_hole_value()),
1698 JSFunction);
1699 }
1700
1701
1702 Handle<JSFunction> Factory::NewFunctionWithoutPrototype(
1703 Handle<String> name,
1704 StrictMode strict_mode) {
1705 Handle<JSFunction> fun = NewFunctionWithoutPrototypeHelper(name, strict_mode);
1706 fun->set_context(isolate()->context()->native_context()); 1782 fun->set_context(isolate()->context()->native_context());
1707 return fun; 1783 return fun;
1708 } 1784 }
1709 1785
1710 1786
1711 #ifdef ENABLE_DEBUGGER_SUPPORT 1787 #ifdef ENABLE_DEBUGGER_SUPPORT
1712 Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) { 1788 Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) {
1713 // Get the original code of the function. 1789 // Get the original code of the function.
1714 Handle<Code> code(shared->code()); 1790 Handle<Code> code(shared->code());
1715 1791
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 if (String::Equals(name, infinity_string())) return infinity_value(); 2093 if (String::Equals(name, infinity_string())) return infinity_value();
2018 return Handle<Object>::null(); 2094 return Handle<Object>::null();
2019 } 2095 }
2020 2096
2021 2097
2022 Handle<Object> Factory::ToBoolean(bool value) { 2098 Handle<Object> Factory::ToBoolean(bool value) {
2023 return value ? true_value() : false_value(); 2099 return value ? true_value() : false_value();
2024 } 2100 }
2025 2101
2026 } } // namespace v8::internal 2102 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/handles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698