Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 } else { | 467 } else { |
| 449 return ConcatStringContent<uc16>( | 468 return ConcatStringContent<uc16>( |
| 450 NewRawTwoByteString(total_length).ToHandleChecked(), first, second); | 469 NewRawTwoByteString(total_length).ToHandleChecked(), first, second); |
| 451 } | 470 } |
| 452 } | 471 } |
| 453 | 472 |
| 454 | 473 |
| 455 Handle<SlicedString> Factory::NewRawSlicedString(String::Encoding encoding) { | 474 Handle<SlicedString> Factory::NewRawSlicedString(String::Encoding encoding) { |
| 456 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING) | 475 Handle<Map> map = (encoding == String::ONE_BYTE_ENCODING) |
| 457 ? sliced_ascii_string_map() : sliced_string_map(); | 476 ? sliced_ascii_string_map() : sliced_string_map(); |
| 458 CALL_HEAP_FUNCTION(isolate(), | 477 return New<SlicedString>(map, NEW_SPACE); |
| 459 isolate()->heap()->Allocate(*map, NEW_SPACE), | |
| 460 SlicedString); | |
| 461 } | 478 } |
| 462 | 479 |
| 463 | 480 |
| 464 Handle<String> Factory::NewProperSubString(Handle<String> str, | 481 Handle<String> Factory::NewProperSubString(Handle<String> str, |
| 465 int begin, | 482 int begin, |
| 466 int end) { | 483 int end) { |
| 467 #if VERIFY_HEAP | 484 #if VERIFY_HEAP |
| 468 if (FLAG_verify_heap) str->StringVerify(); | 485 if (FLAG_verify_heap) str->StringVerify(); |
| 469 #endif | 486 #endif |
| 470 ASSERT(begin > 0 || end < str->length()); | 487 ASSERT(begin > 0 || end < str->length()); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); | 906 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); |
| 890 } | 907 } |
| 891 | 908 |
| 892 | 909 |
| 893 Handle<ConstantPoolArray> Factory::CopyConstantPoolArray( | 910 Handle<ConstantPoolArray> Factory::CopyConstantPoolArray( |
| 894 Handle<ConstantPoolArray> array) { | 911 Handle<ConstantPoolArray> array) { |
| 895 CALL_HEAP_FUNCTION(isolate(), array->Copy(), ConstantPoolArray); | 912 CALL_HEAP_FUNCTION(isolate(), array->Copy(), ConstantPoolArray); |
| 896 } | 913 } |
| 897 | 914 |
| 898 | 915 |
| 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, | 916 static Handle<Map> MapForNewFunction(Isolate *isolate, |
| 914 Handle<SharedFunctionInfo> function_info) { | 917 Handle<SharedFunctionInfo> function_info) { |
| 915 Context *context = isolate->context()->native_context(); | 918 Context *context = isolate->context()->native_context(); |
| 916 int map_index = Context::FunctionMapIndex(function_info->strict_mode(), | 919 int map_index = Context::FunctionMapIndex(function_info->strict_mode(), |
| 917 function_info->is_generator()); | 920 function_info->is_generator()); |
| 918 return Handle<Map>(Map::cast(context->get(map_index))); | 921 return Handle<Map>(Map::cast(context->get(map_index))); |
| 919 } | 922 } |
| 920 | 923 |
| 921 | 924 |
| 922 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( | 925 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
| 923 Handle<SharedFunctionInfo> function_info, | 926 Handle<SharedFunctionInfo> function_info, |
| 924 Handle<Context> context, | 927 Handle<Context> context, |
| 925 PretenureFlag pretenure) { | 928 PretenureFlag pretenure) { |
| 926 Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo( | 929 Handle<JSFunction> result = NewFunctionHelper( |
| 930 MapForNewFunction(isolate(), function_info), | |
| 927 function_info, | 931 function_info, |
| 928 MapForNewFunction(isolate(), function_info), | 932 the_hole_value(), |
| 929 pretenure); | 933 pretenure); |
| 930 | 934 |
| 931 if (function_info->ic_age() != isolate()->heap()->global_ic_age()) { | 935 if (function_info->ic_age() != isolate()->heap()->global_ic_age()) { |
| 932 function_info->ResetForNewContext(isolate()->heap()->global_ic_age()); | 936 function_info->ResetForNewContext(isolate()->heap()->global_ic_age()); |
| 933 } | 937 } |
| 934 | 938 |
| 935 result->set_context(*context); | 939 result->set_context(*context); |
| 936 | 940 |
| 937 int index = function_info->SearchOptimizedCodeMap(context->native_context(), | 941 int index = function_info->SearchOptimizedCodeMap(context->native_context(), |
| 938 BailoutId::None()); | 942 BailoutId::None()); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1336 static Handle<NameDictionary> NameDictionaryAdd(Handle<NameDictionary> dict, | 1340 static Handle<NameDictionary> NameDictionaryAdd(Handle<NameDictionary> dict, |
| 1337 Handle<Name> name, | 1341 Handle<Name> name, |
| 1338 Handle<Object> value, | 1342 Handle<Object> value, |
| 1339 PropertyDetails details) { | 1343 PropertyDetails details) { |
| 1340 CALL_HEAP_FUNCTION(dict->GetIsolate(), | 1344 CALL_HEAP_FUNCTION(dict->GetIsolate(), |
| 1341 dict->Add(*name, *value, details), | 1345 dict->Add(*name, *value, details), |
| 1342 NameDictionary); | 1346 NameDictionary); |
| 1343 } | 1347 } |
| 1344 | 1348 |
| 1345 | 1349 |
| 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) { | 1350 Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) { |
| 1355 ASSERT(constructor->has_initial_map()); | 1351 ASSERT(constructor->has_initial_map()); |
| 1356 Handle<Map> map(constructor->initial_map()); | 1352 Handle<Map> map(constructor->initial_map()); |
| 1357 ASSERT(map->is_dictionary_map()); | 1353 ASSERT(map->is_dictionary_map()); |
| 1358 | 1354 |
| 1359 // Make sure no field properties are described in the initial map. | 1355 // Make sure no field properties are described in the initial map. |
| 1360 // This guarantees us that normalizing the properties does not | 1356 // This guarantees us that normalizing the properties does not |
| 1361 // require us to change property values to PropertyCells. | 1357 // require us to change property values to PropertyCells. |
| 1362 ASSERT(map->NextFreePropertyIndex() == 0); | 1358 ASSERT(map->NextFreePropertyIndex() == 0); |
| 1363 | 1359 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1382 PropertyDetails details = descs->GetDetails(i); | 1378 PropertyDetails details = descs->GetDetails(i); |
| 1383 ASSERT(details.type() == CALLBACKS); // Only accessors are expected. | 1379 ASSERT(details.type() == CALLBACKS); // Only accessors are expected. |
| 1384 PropertyDetails d = PropertyDetails(details.attributes(), CALLBACKS, i + 1); | 1380 PropertyDetails d = PropertyDetails(details.attributes(), CALLBACKS, i + 1); |
| 1385 Handle<Name> name(descs->GetKey(i)); | 1381 Handle<Name> name(descs->GetKey(i)); |
| 1386 Handle<Object> value(descs->GetCallbacksObject(i), isolate()); | 1382 Handle<Object> value(descs->GetCallbacksObject(i), isolate()); |
| 1387 Handle<PropertyCell> cell = NewPropertyCell(value); | 1383 Handle<PropertyCell> cell = NewPropertyCell(value); |
| 1388 NameDictionaryAdd(dictionary, name, cell, d); | 1384 NameDictionaryAdd(dictionary, name, cell, d); |
| 1389 } | 1385 } |
| 1390 | 1386 |
| 1391 // Allocate the global object and initialize it with the backing store. | 1387 // Allocate the global object and initialize it with the backing store. |
| 1392 Handle<GlobalObject> global = NewGlobalObjectFromMap(isolate(), map); | 1388 Handle<GlobalObject> global = New<GlobalObject>(map, OLD_POINTER_SPACE); |
| 1393 isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map); | 1389 isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map); |
| 1394 | 1390 |
| 1395 // Create a new map for the global object. | 1391 // Create a new map for the global object. |
| 1396 Handle<Map> new_map = Map::CopyDropDescriptors(map); | 1392 Handle<Map> new_map = Map::CopyDropDescriptors(map); |
| 1397 new_map->set_dictionary_map(true); | 1393 new_map->set_dictionary_map(true); |
| 1398 | 1394 |
| 1399 // Set up the global object as a normalized object. | 1395 // Set up the global object as a normalized object. |
| 1400 global->set_map(*new_map); | 1396 global->set_map(*new_map); |
| 1401 global->set_properties(*dictionary); | 1397 global->set_properties(*dictionary); |
| 1402 | 1398 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1558 | 1554 |
| 1559 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, | 1555 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, |
| 1560 Handle<Object> prototype) { | 1556 Handle<Object> prototype) { |
| 1561 CALL_HEAP_FUNCTION( | 1557 CALL_HEAP_FUNCTION( |
| 1562 isolate(), | 1558 isolate(), |
| 1563 isolate()->heap()->AllocateJSProxy(*handler, *prototype), | 1559 isolate()->heap()->AllocateJSProxy(*handler, *prototype), |
| 1564 JSProxy); | 1560 JSProxy); |
| 1565 } | 1561 } |
| 1566 | 1562 |
| 1567 | 1563 |
| 1564 void Factory::ReinitializeJSReceiver(Handle<JSReceiver> object, | |
| 1565 InstanceType type, | |
| 1566 int size) { | |
| 1567 ASSERT(type >= FIRST_JS_OBJECT_TYPE); | |
| 1568 | |
| 1569 // Allocate fresh map. | |
| 1570 // TODO(rossberg): Once we optimize proxies, cache these maps. | |
| 1571 Handle<Map> map = NewMap(type, size); | |
| 1572 | |
| 1573 // Check that the receiver has at least the size of the fresh object. | |
| 1574 int size_difference = object->map()->instance_size() - map->instance_size(); | |
| 1575 ASSERT(size_difference >= 0); | |
| 1576 | |
| 1577 map->set_prototype(object->map()->prototype()); | |
| 1578 | |
| 1579 // Allocate the backing storage for the properties. | |
| 1580 int prop_size = map->unused_property_fields() - map->inobject_properties(); | |
| 1581 Handle<FixedArray> properties = NewFixedArray(prop_size, TENURED); | |
| 1582 | |
| 1583 // Reset the map for the object. | |
| 1584 object->set_map(*map); | |
| 1585 Handle<JSObject> jsobj = Handle<JSObject>::cast(object); | |
| 1586 | |
| 1587 Heap* heap = isolate()->heap(); | |
|
Michael Starzinger
2014/04/15 09:54:59
nit: There should be Factory::heap() IIRC, I think
Igor Sheludko
2014/04/15 11:03:42
There's no heap() method. Lets address this in a s
| |
| 1588 // Reinitialize the object from the constructor map. | |
| 1589 heap->InitializeJSObjectFromMap(*jsobj, FixedArray::cast(*properties), *map); | |
|
Michael Starzinger
2014/04/15 09:54:59
nit: No need to cast the FixedArray anymore, it is
Igor Sheludko
2014/04/15 11:03:42
Done.
| |
| 1590 | |
| 1591 // Functions require some minimal initialization. | |
| 1592 if (type == JS_FUNCTION_TYPE) { | |
| 1593 OneByteStringKey key(STATIC_ASCII_VECTOR("<freezing call trap>"), | |
| 1594 heap->HashSeed()); | |
| 1595 Handle<String> name = InternalizeStringWithKey(&key); | |
| 1596 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name); | |
| 1597 | |
| 1598 map->set_function_with_prototype(true); | |
| 1599 Handle<JSFunction> js_function = Handle<JSFunction>::cast(object); | |
| 1600 InitializeFunction(js_function, shared, the_hole_value()); | |
|
Michael Starzinger
2014/04/15 09:54:59
Same comment as below goes for the call to Initial
Igor Sheludko
2014/04/15 11:03:42
Done.
| |
| 1601 js_function->set_context(isolate()->context()->native_context()); | |
| 1602 } | |
| 1603 | |
| 1604 // Put in filler if the new object is smaller than the old. | |
| 1605 if (size_difference > 0) { | |
| 1606 heap->CreateFillerObjectAt( | |
|
Michael Starzinger
2014/04/15 09:54:59
Creating the filler object needs to happen right a
Igor Sheludko
2014/04/15 11:03:42
I fixed this in a little bit different way than yo
| |
| 1607 object->address() + map->instance_size(), size_difference); | |
| 1608 } | |
| 1609 } | |
| 1610 | |
| 1611 | |
| 1612 void Factory::ReinitializeJSGlobalProxy(Handle<JSFunction> constructor, | |
| 1613 Handle<JSGlobalProxy> object) { | |
| 1614 ASSERT(constructor->has_initial_map()); | |
| 1615 Handle<Map> map(constructor->initial_map(), isolate()); | |
| 1616 | |
| 1617 // Check that the already allocated object has the same size and type as | |
| 1618 // objects allocated using the constructor. | |
| 1619 ASSERT(map->instance_size() == object->map()->instance_size()); | |
| 1620 ASSERT(map->instance_type() == object->map()->instance_type()); | |
| 1621 | |
| 1622 // Allocate the backing storage for the properties. | |
| 1623 int prop_size = map->unused_property_fields() - map->inobject_properties(); | |
| 1624 Handle<FixedArray> properties = | |
| 1625 isolate()->factory()->NewFixedArray(prop_size, TENURED); | |
|
Michael Starzinger
2014/04/15 09:54:59
nit: We are already inside the Factory, just call
Igor Sheludko
2014/04/15 11:03:42
Fixed here and in all other places in the file.
| |
| 1626 | |
| 1627 // Reset the map for the object. | |
| 1628 object->set_map(constructor->initial_map()); | |
| 1629 | |
| 1630 Heap* heap = isolate()->heap(); | |
|
Michael Starzinger
2014/04/15 09:54:59
nit: There should be Factory::heap() IIRC, I think
Igor Sheludko
2014/04/15 11:03:42
Done.
| |
| 1631 // Reinitialize the object from the constructor map. | |
| 1632 heap->InitializeJSObjectFromMap(*object, FixedArray::cast(*properties), *map); | |
|
Michael Starzinger
2014/04/15 09:54:59
nit: No need to cast the FixedArray anymore, it is
Igor Sheludko
2014/04/15 11:03:42
Done.
| |
| 1633 } | |
| 1634 | |
| 1635 | |
| 1568 void Factory::BecomeJSObject(Handle<JSReceiver> object) { | 1636 void Factory::BecomeJSObject(Handle<JSReceiver> object) { |
| 1569 CALL_HEAP_FUNCTION_VOID( | 1637 ReinitializeJSReceiver(object, JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 1570 isolate(), | |
| 1571 isolate()->heap()->ReinitializeJSReceiver( | |
| 1572 *object, JS_OBJECT_TYPE, JSObject::kHeaderSize)); | |
| 1573 } | 1638 } |
| 1574 | 1639 |
| 1575 | 1640 |
| 1576 void Factory::BecomeJSFunction(Handle<JSReceiver> object) { | 1641 void Factory::BecomeJSFunction(Handle<JSReceiver> object) { |
| 1577 CALL_HEAP_FUNCTION_VOID( | 1642 ReinitializeJSReceiver(object, JS_FUNCTION_TYPE, JSFunction::kSize); |
| 1578 isolate(), | |
| 1579 isolate()->heap()->ReinitializeJSReceiver( | |
| 1580 *object, JS_FUNCTION_TYPE, JSFunction::kSize)); | |
| 1581 } | 1643 } |
| 1582 | 1644 |
| 1583 | 1645 |
| 1584 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( | 1646 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( |
| 1585 Handle<String> name, | 1647 Handle<String> name, |
| 1586 int number_of_literals, | 1648 int number_of_literals, |
| 1587 bool is_generator, | 1649 bool is_generator, |
| 1588 Handle<Code> code, | 1650 Handle<Code> code, |
| 1589 Handle<ScopeInfo> scope_info) { | 1651 Handle<ScopeInfo> scope_info) { |
| 1590 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name); | 1652 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo(name); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1656 Handle<UnseededNumberDictionary> Factory::DictionaryAtNumberPut( | 1718 Handle<UnseededNumberDictionary> Factory::DictionaryAtNumberPut( |
| 1657 Handle<UnseededNumberDictionary> dictionary, | 1719 Handle<UnseededNumberDictionary> dictionary, |
| 1658 uint32_t key, | 1720 uint32_t key, |
| 1659 Handle<Object> value) { | 1721 Handle<Object> value) { |
| 1660 CALL_HEAP_FUNCTION(isolate(), | 1722 CALL_HEAP_FUNCTION(isolate(), |
| 1661 dictionary->AtNumberPut(key, *value), | 1723 dictionary->AtNumberPut(key, *value), |
| 1662 UnseededNumberDictionary); | 1724 UnseededNumberDictionary); |
| 1663 } | 1725 } |
| 1664 | 1726 |
| 1665 | 1727 |
| 1666 Handle<JSFunction> Factory::NewFunctionHelper(Handle<String> name, | 1728 void Factory::InitializeFunction(Handle<JSFunction> function, |
|
Igor Sheludko
2014/04/15 08:33:32
one usage, inlined
| |
| 1667 Handle<Object> prototype) { | 1729 Handle<SharedFunctionInfo> shared, |
| 1668 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); | 1730 Handle<Object> prototype) { |
| 1669 CALL_HEAP_FUNCTION( | 1731 ASSERT(!prototype->IsMap()); |
| 1670 isolate(), | 1732 function->initialize_properties(); |
| 1671 isolate()->heap()->AllocateFunction(*isolate()->sloppy_function_map(), | 1733 function->initialize_elements(); |
| 1672 *function_share, | 1734 function->set_shared(*shared); |
| 1673 *prototype), | 1735 function->set_code(shared->code()); |
| 1674 JSFunction); | 1736 function->set_prototype_or_initial_map(*prototype); |
| 1737 function->set_context(*undefined_value()); | |
| 1738 function->set_literals_or_bindings(*empty_fixed_array()); | |
| 1739 function->set_next_function_link(*undefined_value()); | |
| 1740 } | |
| 1741 | |
| 1742 | |
| 1743 Handle<JSFunction> Factory::NewFunctionHelper(Handle<Map> function_map, | |
|
Igor Sheludko
2014/04/15 08:33:32
Handlified Heap::AllocateFunction()
| |
| 1744 Handle<SharedFunctionInfo> shared, | |
| 1745 Handle<Object> prototype, | |
| 1746 PretenureFlag pretenure) { | |
| 1747 AllocationSpace space = | |
| 1748 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; | |
| 1749 Handle<JSFunction> fun = New<JSFunction>(function_map, space); | |
| 1750 InitializeFunction(fun, shared, prototype); | |
| 1751 return fun; | |
| 1675 } | 1752 } |
| 1676 | 1753 |
| 1677 | 1754 |
| 1678 Handle<JSFunction> Factory::NewFunction(Handle<String> name, | 1755 Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
| 1679 Handle<Object> prototype) { | 1756 Handle<Object> prototype) { |
| 1680 Handle<JSFunction> fun = NewFunctionHelper(name, prototype); | 1757 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); |
| 1758 Handle<JSFunction> fun = NewFunctionHelper( | |
| 1759 isolate()->sloppy_function_map(), function_share, prototype); | |
| 1681 fun->set_context(isolate()->context()->native_context()); | 1760 fun->set_context(isolate()->context()->native_context()); |
| 1682 return fun; | 1761 return fun; |
| 1683 } | 1762 } |
| 1684 | 1763 |
| 1685 | 1764 |
| 1686 Handle<JSFunction> Factory::NewFunctionWithoutPrototypeHelper( | 1765 Handle<JSFunction> Factory::NewFunctionWithoutPrototype( |
|
Igor Sheludko
2014/04/15 08:33:32
one usage, inlined
| |
| 1687 Handle<String> name, | 1766 Handle<String> name, |
| 1688 StrictMode strict_mode) { | 1767 StrictMode strict_mode) { |
| 1689 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); | 1768 Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name); |
| 1690 Handle<Map> map = strict_mode == SLOPPY | 1769 Handle<Map> map = strict_mode == SLOPPY |
| 1691 ? isolate()->sloppy_function_without_prototype_map() | 1770 ? isolate()->sloppy_function_without_prototype_map() |
| 1692 : isolate()->strict_function_without_prototype_map(); | 1771 : isolate()->strict_function_without_prototype_map(); |
| 1693 CALL_HEAP_FUNCTION(isolate(), | 1772 Handle<JSFunction> fun = |
| 1694 isolate()->heap()->AllocateFunction( | 1773 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()); | 1774 fun->set_context(isolate()->context()->native_context()); |
| 1707 return fun; | 1775 return fun; |
| 1708 } | 1776 } |
| 1709 | 1777 |
| 1710 | 1778 |
| 1711 #ifdef ENABLE_DEBUGGER_SUPPORT | 1779 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1712 Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) { | 1780 Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) { |
| 1713 // Get the original code of the function. | 1781 // Get the original code of the function. |
| 1714 Handle<Code> code(shared->code()); | 1782 Handle<Code> code(shared->code()); |
| 1715 | 1783 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2017 if (String::Equals(name, infinity_string())) return infinity_value(); | 2085 if (String::Equals(name, infinity_string())) return infinity_value(); |
| 2018 return Handle<Object>::null(); | 2086 return Handle<Object>::null(); |
| 2019 } | 2087 } |
| 2020 | 2088 |
| 2021 | 2089 |
| 2022 Handle<Object> Factory::ToBoolean(bool value) { | 2090 Handle<Object> Factory::ToBoolean(bool value) { |
| 2023 return value ? true_value() : false_value(); | 2091 return value ? true_value() : false_value(); |
| 2024 } | 2092 } |
| 2025 | 2093 |
| 2026 } } // namespace v8::internal | 2094 } } // namespace v8::internal |
| OLD | NEW |