Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 // Used both for deserialized and from-scratch contexts to add the extensions | 337 // Used both for deserialized and from-scratch contexts to add the extensions |
| 338 // provided. | 338 // provided. |
| 339 static bool InstallExtensions(Handle<Context> global_context, | 339 static bool InstallExtensions(Handle<Context> global_context, |
| 340 v8::ExtensionConfiguration* extensions); | 340 v8::ExtensionConfiguration* extensions); |
| 341 static bool InstallExtension(const char* name); | 341 static bool InstallExtension(const char* name); |
| 342 static bool InstallExtension(v8::RegisteredExtension* current); | 342 static bool InstallExtension(v8::RegisteredExtension* current); |
| 343 static void InstallSpecialObjects(Handle<Context> global_context); | 343 static void InstallSpecialObjects(Handle<Context> global_context); |
| 344 bool ConfigureApiObject(Handle<JSObject> object, | 344 bool ConfigureApiObject(Handle<JSObject> object, |
| 345 Handle<ObjectTemplateInfo> object_template); | 345 Handle<ObjectTemplateInfo> object_template); |
| 346 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template); | 346 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template); |
| 347 void TransferMapsToDeserializedGlobals( | |
| 348 Handle<GlobalObject> inner_global_outside_snapshot, | |
| 349 Handle<GlobalObject> inner_global_from_snapshot); | |
| 347 | 350 |
| 348 // Migrates all properties from the 'from' object to the 'to' | 351 // Migrates all properties from the 'from' object to the 'to' |
| 349 // object and overrides the prototype in 'to' with the one from | 352 // object and overrides the prototype in 'to' with the one from |
| 350 // 'from'. | 353 // 'from'. |
| 351 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); | 354 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); |
| 352 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); | 355 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| 353 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); | 356 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| 354 | 357 |
| 355 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor( | 358 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor( |
| 356 bool make_prototype_read_only, | 359 bool make_prototype_read_only, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 v8::NeanderArray listeners; | 593 v8::NeanderArray listeners; |
| 591 global_context()->set_message_listeners(*listeners.value()); | 594 global_context()->set_message_listeners(*listeners.value()); |
| 592 } | 595 } |
| 593 } | 596 } |
| 594 | 597 |
| 595 | 598 |
| 596 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( | 599 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( |
| 597 v8::Handle<v8::ObjectTemplate> global_template, | 600 v8::Handle<v8::ObjectTemplate> global_template, |
| 598 Handle<Object> global_object, | 601 Handle<Object> global_object, |
| 599 Handle<GlobalObject>* inner_global_out) { | 602 Handle<GlobalObject>* inner_global_out) { |
| 603 // The argument global_template aka data is an ObjectTemplateInfo. | |
| 604 // It has a constructor pointer that points at global_constructor which is a | |
| 605 // FunctionTemplateInfo. | |
| 606 // The global_constructor is used to create or reinitialize the global_proxy. | |
| 607 // The global_constructor also has a prototype_template pointer that points at | |
| 608 // js_global_template which is an ObjectTemplateInfo. | |
| 609 // That in turn has a constructor pointer that points at | |
| 610 // js_global_constructor which is a FunctionTemplateInfo. | |
| 611 // js_global_constructor is used to make js_global_function | |
| 612 // js_global_function is used to make the new inner_global. | |
| 613 // | |
| 600 // --- G l o b a l --- | 614 // --- G l o b a l --- |
| 601 // Step 1: Create a fresh inner JSGlobalObject. | 615 // Step 1: Create a fresh inner JSGlobalObject. |
| 602 Handle<JSFunction> js_global_function; | 616 Handle<JSFunction> js_global_function; |
| 603 Handle<ObjectTemplateInfo> js_global_template; | 617 Handle<ObjectTemplateInfo> js_global_template; |
| 604 if (!global_template.IsEmpty()) { | 618 if (!global_template.IsEmpty()) { |
| 605 // Get prototype template of the global_template. | 619 // Get prototype template of the global_template. |
| 606 Handle<ObjectTemplateInfo> data = | 620 Handle<ObjectTemplateInfo> data = |
| 607 v8::Utils::OpenHandle(*global_template); | 621 v8::Utils::OpenHandle(*global_template); |
| 608 Handle<FunctionTemplateInfo> global_constructor = | 622 Handle<FunctionTemplateInfo> global_constructor = |
| 609 Handle<FunctionTemplateInfo>( | 623 Handle<FunctionTemplateInfo>( |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1376 false); | 1390 false); |
| 1377 ASSERT(Top::has_pending_exception() != result); | 1391 ASSERT(Top::has_pending_exception() != result); |
| 1378 if (!result) { | 1392 if (!result) { |
| 1379 Top::clear_pending_exception(); | 1393 Top::clear_pending_exception(); |
| 1380 } | 1394 } |
| 1381 current->set_state(v8::INSTALLED); | 1395 current->set_state(v8::INSTALLED); |
| 1382 return result; | 1396 return result; |
| 1383 } | 1397 } |
| 1384 | 1398 |
| 1385 | 1399 |
| 1400 void Genesis::TransferMapsToDeserializedGlobals( | |
|
Mads Ager (chromium)
2010/02/15 08:36:24
Maps -> Map?
Globals -> Global?
| |
| 1401 Handle<GlobalObject> inner_global_outside_snapshot, | |
| 1402 Handle<GlobalObject> inner_global_from_snapshot) { | |
| 1403 Handle<Map> from_map(inner_global_outside_snapshot->map()); | |
| 1404 #ifdef DEBUG | |
| 1405 Handle<Map> to_map(inner_global_from_snapshot->map()); | |
| 1406 ASSERT_EQ(to_map->instance_size(), from_map->instance_size()); | |
| 1407 ASSERT_EQ(0, to_map->inobject_properties()); | |
| 1408 ASSERT_EQ(0, from_map->inobject_properties()); | |
| 1409 #endif | |
| 1410 inner_global_from_snapshot->set_map(*from_map); | |
| 1411 } | |
| 1412 | |
| 1413 | |
| 1386 bool Genesis::ConfigureGlobalObjects( | 1414 bool Genesis::ConfigureGlobalObjects( |
| 1387 v8::Handle<v8::ObjectTemplate> global_proxy_template) { | 1415 v8::Handle<v8::ObjectTemplate> global_proxy_template) { |
| 1388 Handle<JSObject> global_proxy( | 1416 Handle<JSObject> global_proxy( |
| 1389 JSObject::cast(global_context()->global_proxy())); | 1417 JSObject::cast(global_context()->global_proxy())); |
| 1390 Handle<JSObject> js_global(JSObject::cast(global_context()->global())); | 1418 Handle<JSObject> js_global(JSObject::cast(global_context()->global())); |
| 1391 | 1419 |
| 1392 if (!global_proxy_template.IsEmpty()) { | 1420 if (!global_proxy_template.IsEmpty()) { |
| 1393 // Configure the global proxy object. | 1421 // Configure the global proxy object. |
| 1394 Handle<ObjectTemplateInfo> proxy_data = | 1422 Handle<ObjectTemplateInfo> proxy_data = |
| 1395 v8::Utils::OpenHandle(*global_proxy_template); | 1423 v8::Utils::OpenHandle(*global_proxy_template); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1452 Handle<JSFunction>(descs->GetConstantFunction(i)); | 1480 Handle<JSFunction>(descs->GetConstantFunction(i)); |
| 1453 SetProperty(to, key, fun, details.attributes()); | 1481 SetProperty(to, key, fun, details.attributes()); |
| 1454 break; | 1482 break; |
| 1455 } | 1483 } |
| 1456 case CALLBACKS: { | 1484 case CALLBACKS: { |
| 1457 LookupResult result; | 1485 LookupResult result; |
| 1458 to->LocalLookup(descs->GetKey(i), &result); | 1486 to->LocalLookup(descs->GetKey(i), &result); |
| 1459 // If the property is already there we skip it | 1487 // If the property is already there we skip it |
| 1460 if (result.IsValid()) continue; | 1488 if (result.IsValid()) continue; |
| 1461 HandleScope inner; | 1489 HandleScope inner; |
| 1462 Handle<DescriptorArray> inst_descs = | 1490 ASSERT(!to->HasFastProperties()); |
| 1463 Handle<DescriptorArray>(to->map()->instance_descriptors()); | 1491 // Add to dictionary. |
| 1464 Handle<String> key = Handle<String>(descs->GetKey(i)); | 1492 Handle<String> key = Handle<String>(descs->GetKey(i)); |
| 1465 Handle<Object> entry = Handle<Object>(descs->GetCallbacksObject(i)); | 1493 Handle<Object> callbacks(descs->GetCallbacksObject(i)); |
| 1466 inst_descs = Factory::CopyAppendProxyDescriptor(inst_descs, | 1494 PropertyDetails d = |
| 1467 key, | 1495 PropertyDetails(details.attributes(), CALLBACKS, details.index()); |
| 1468 entry, | 1496 SetNormalizedProperty(to, key, callbacks, d); |
| 1469 details.attributes()); | |
| 1470 to->map()->set_instance_descriptors(*inst_descs); | |
| 1471 break; | 1497 break; |
| 1472 } | 1498 } |
| 1473 case MAP_TRANSITION: | 1499 case MAP_TRANSITION: |
| 1474 case CONSTANT_TRANSITION: | 1500 case CONSTANT_TRANSITION: |
| 1475 case NULL_DESCRIPTOR: | 1501 case NULL_DESCRIPTOR: |
| 1476 // Ignore non-properties. | 1502 // Ignore non-properties. |
| 1477 break; | 1503 break; |
| 1478 case NORMAL: | 1504 case NORMAL: |
| 1479 // Do not occur since the from object has fast properties. | 1505 // Do not occur since the from object has fast properties. |
| 1480 case INTERCEPTOR: | 1506 case INTERCEPTOR: |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1605 v8::ExtensionConfiguration* extensions) { | 1631 v8::ExtensionConfiguration* extensions) { |
| 1606 result_ = Handle<Context>::null(); | 1632 result_ = Handle<Context>::null(); |
| 1607 // If V8 isn't running and cannot be initialized, just return. | 1633 // If V8 isn't running and cannot be initialized, just return. |
| 1608 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; | 1634 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; |
| 1609 | 1635 |
| 1610 // Before creating the roots we must save the context and restore it | 1636 // Before creating the roots we must save the context and restore it |
| 1611 // on all function exits. | 1637 // on all function exits. |
| 1612 HandleScope scope; | 1638 HandleScope scope; |
| 1613 SaveContext saved_context; | 1639 SaveContext saved_context; |
| 1614 | 1640 |
| 1615 if (global_template.IsEmpty()) { | 1641 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); |
| 1616 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); | 1642 if (!new_context.is_null()) { |
| 1617 if (!new_context.is_null()) { | 1643 global_context_ = |
| 1618 global_context_ = | 1644 Handle<Context>::cast(GlobalHandles::Create(*new_context)); |
| 1619 Handle<Context>::cast(GlobalHandles::Create(*new_context)); | 1645 Top::set_context(*global_context_); |
| 1620 Top::set_context(*global_context_); | 1646 i::Counters::contexts_created_by_snapshot.Increment(); |
| 1621 i::Counters::contexts_created_by_snapshot.Increment(); | 1647 result_ = global_context_; |
| 1622 result_ = global_context_; | 1648 JSFunction* empty_function = |
| 1623 JSFunction* empty_function = | 1649 JSFunction::cast(result_->function_map()->prototype()); |
| 1624 JSFunction::cast(result_->function_map()->prototype()); | 1650 empty_function_ = Handle<JSFunction>(empty_function); |
| 1625 empty_function_ = Handle<JSFunction>(empty_function); | 1651 Handle<GlobalObject> inner_global_outside_snapshot; |
| 1626 Handle<JSGlobalProxy> global_proxy = | 1652 Handle<JSGlobalProxy> global_proxy = |
| 1627 CreateNewGlobals(global_template, global_object, NULL); | 1653 CreateNewGlobals(global_template, |
| 1628 // CreateNewGlobals can return an inner global that it just made, but | 1654 global_object, |
| 1629 // we will ignore that because we want to hook up the global proxy to | 1655 &inner_global_outside_snapshot); |
| 1630 // the one from the snapshot. | 1656 // CreateNewGlobals returns an inner global that it just made, but |
| 1631 Handle<GlobalObject> inner_global( | 1657 // we won't give that to HookUpGlobalProxy because we want to hook |
| 1632 GlobalObject::cast(global_context_->extension())); | 1658 // up the global proxy to the one from the snapshot. |
| 1633 HookUpGlobalProxy(inner_global, global_proxy); | 1659 Handle<GlobalObject> inner_global( |
| 1634 if (!ConfigureGlobalObjects(global_template)) return; | 1660 GlobalObject::cast(global_context_->extension())); |
| 1635 } | 1661 HookUpGlobalProxy(inner_global, global_proxy); |
| 1636 } | 1662 TransferMapsToDeserializedGlobals(inner_global_outside_snapshot, |
| 1637 if (global_context_.is_null()) { | 1663 inner_global); |
| 1638 // We get here if there either was no context snapshot or we couldn't use | 1664 if (!ConfigureGlobalObjects(global_template)) return; |
| 1639 // the context snapshot because we were supplied with a global template. | 1665 } else { |
| 1666 // We get here if there was no context snapshot. | |
| 1640 CreateRoots(); | 1667 CreateRoots(); |
| 1641 Handle<JSFunction> empty_function = CreateEmptyFunction(); | 1668 Handle<JSFunction> empty_function = CreateEmptyFunction(); |
| 1642 Handle<GlobalObject> inner_global; | 1669 Handle<GlobalObject> inner_global; |
| 1643 Handle<JSGlobalProxy> global_proxy = | 1670 Handle<JSGlobalProxy> global_proxy = |
| 1644 CreateNewGlobals(global_template, global_object, &inner_global); | 1671 CreateNewGlobals(global_template, global_object, &inner_global); |
| 1645 HookUpGlobalProxy(inner_global, global_proxy); | 1672 HookUpGlobalProxy(inner_global, global_proxy); |
| 1646 InitializeGlobal(inner_global, empty_function); | 1673 InitializeGlobal(inner_global, empty_function); |
| 1647 if (!InstallNatives()) return; | 1674 if (!InstallNatives()) return; |
| 1648 | 1675 |
| 1649 MakeFunctionInstancePrototypeWritable(); | 1676 MakeFunctionInstancePrototypeWritable(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1697 } | 1724 } |
| 1698 | 1725 |
| 1699 | 1726 |
| 1700 // Restore statics that are thread local. | 1727 // Restore statics that are thread local. |
| 1701 char* BootstrapperActive::RestoreState(char* from) { | 1728 char* BootstrapperActive::RestoreState(char* from) { |
| 1702 nesting_ = *reinterpret_cast<int*>(from); | 1729 nesting_ = *reinterpret_cast<int*>(from); |
| 1703 return from + sizeof(nesting_); | 1730 return from + sizeof(nesting_); |
| 1704 } | 1731 } |
| 1705 | 1732 |
| 1706 } } // namespace v8::internal | 1733 } } // namespace v8::internal |
| OLD | NEW |