| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // rest of the context snapshot. | 210 // rest of the context snapshot. |
| 211 Handle<JSGlobalProxy> CreateNewGlobals( | 211 Handle<JSGlobalProxy> CreateNewGlobals( |
| 212 v8::Handle<v8::ObjectTemplate> global_template, | 212 v8::Handle<v8::ObjectTemplate> global_template, |
| 213 Handle<Object> global_object, | 213 Handle<Object> global_object, |
| 214 Handle<GlobalObject>* global_proxy_out); | 214 Handle<GlobalObject>* global_proxy_out); |
| 215 // Hooks the given global proxy into the context. If the context was created | 215 // Hooks the given global proxy into the context. If the context was created |
| 216 // by deserialization then this will unhook the global proxy that was | 216 // by deserialization then this will unhook the global proxy that was |
| 217 // deserialized, leaving the GC to pick it up. | 217 // deserialized, leaving the GC to pick it up. |
| 218 void HookUpGlobalProxy(Handle<GlobalObject> inner_global, | 218 void HookUpGlobalProxy(Handle<GlobalObject> inner_global, |
| 219 Handle<JSGlobalProxy> global_proxy); | 219 Handle<JSGlobalProxy> global_proxy); |
| 220 // Similarly, we want to use the inner global that has been created by the |
| 221 // templates passed through the API. The inner global from the snapshot is |
| 222 // detached from the other objects in the snapshot. |
| 223 void HookUpInnerGlobal(Handle<GlobalObject> inner_global); |
| 220 // New context initialization. Used for creating a context from scratch. | 224 // New context initialization. Used for creating a context from scratch. |
| 221 void InitializeGlobal(Handle<GlobalObject> inner_global, | 225 void InitializeGlobal(Handle<GlobalObject> inner_global, |
| 222 Handle<JSFunction> empty_function); | 226 Handle<JSFunction> empty_function); |
| 223 // Installs the contents of the native .js files on the global objects. | 227 // Installs the contents of the native .js files on the global objects. |
| 224 // Used for creating a context from scratch. | 228 // Used for creating a context from scratch. |
| 225 void InstallNativeFunctions(); | 229 void InstallNativeFunctions(); |
| 226 bool InstallNatives(); | 230 bool InstallNatives(); |
| 227 // Used both for deserialized and from-scratch contexts to add the extensions | 231 // Used both for deserialized and from-scratch contexts to add the extensions |
| 228 // provided. | 232 // provided. |
| 229 static bool InstallExtensions(Handle<Context> global_context, | 233 static bool InstallExtensions(Handle<Context> global_context, |
| 230 v8::ExtensionConfiguration* extensions); | 234 v8::ExtensionConfiguration* extensions); |
| 231 static bool InstallExtension(const char* name); | 235 static bool InstallExtension(const char* name); |
| 232 static bool InstallExtension(v8::RegisteredExtension* current); | 236 static bool InstallExtension(v8::RegisteredExtension* current); |
| 233 static void InstallSpecialObjects(Handle<Context> global_context); | 237 static void InstallSpecialObjects(Handle<Context> global_context); |
| 234 bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins); | 238 bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins); |
| 235 bool ConfigureApiObject(Handle<JSObject> object, | 239 bool ConfigureApiObject(Handle<JSObject> object, |
| 236 Handle<ObjectTemplateInfo> object_template); | 240 Handle<ObjectTemplateInfo> object_template); |
| 237 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template); | 241 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template); |
| 238 void TransferMapsToDeserializedGlobals( | |
| 239 Handle<GlobalObject> inner_global_outside_snapshot, | |
| 240 Handle<GlobalObject> inner_global_from_snapshot); | |
| 241 | 242 |
| 242 // Migrates all properties from the 'from' object to the 'to' | 243 // Migrates all properties from the 'from' object to the 'to' |
| 243 // object and overrides the prototype in 'to' with the one from | 244 // object and overrides the prototype in 'to' with the one from |
| 244 // 'from'. | 245 // 'from'. |
| 245 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); | 246 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); |
| 246 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); | 247 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| 247 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); | 248 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| 248 | 249 |
| 249 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor( | 250 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor( |
| 250 bool make_prototype_read_only, | 251 bool make_prototype_read_only, |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global, | 580 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global, |
| 580 Handle<JSGlobalProxy> global_proxy) { | 581 Handle<JSGlobalProxy> global_proxy) { |
| 581 // Set the global context for the global object. | 582 // Set the global context for the global object. |
| 582 inner_global->set_global_context(*global_context()); | 583 inner_global->set_global_context(*global_context()); |
| 583 inner_global->set_global_receiver(*global_proxy); | 584 inner_global->set_global_receiver(*global_proxy); |
| 584 global_proxy->set_context(*global_context()); | 585 global_proxy->set_context(*global_context()); |
| 585 global_context()->set_global_proxy(*global_proxy); | 586 global_context()->set_global_proxy(*global_proxy); |
| 586 } | 587 } |
| 587 | 588 |
| 588 | 589 |
| 590 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) { |
| 591 Handle<GlobalObject> inner_global_from_snapshot( |
| 592 GlobalObject::cast(global_context_->extension())); |
| 593 Handle<JSBuiltinsObject> builtins_global(global_context_->builtins()); |
| 594 global_context_->set_extension(*inner_global); |
| 595 global_context_->set_global(*inner_global); |
| 596 global_context_->set_security_token(*inner_global); |
| 597 static const PropertyAttributes attributes = |
| 598 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 599 ForceSetProperty(builtins_global, |
| 600 Factory::LookupAsciiSymbol("global"), |
| 601 inner_global, |
| 602 attributes); |
| 603 // Setup the reference from the global object to the builtins object. |
| 604 JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global); |
| 605 TransferNamedProperties(inner_global_from_snapshot, inner_global); |
| 606 TransferIndexedProperties(inner_global_from_snapshot, inner_global); |
| 607 } |
| 608 |
| 609 |
| 610 // This is only called if we are not using snapshots. The equivalent |
| 611 // work in the snapshot case is done in HookUpInnerGlobal. |
| 589 void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, | 612 void Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, |
| 590 Handle<JSFunction> empty_function) { | 613 Handle<JSFunction> empty_function) { |
| 591 // --- G l o b a l C o n t e x t --- | 614 // --- G l o b a l C o n t e x t --- |
| 592 // Use the empty function as closure (no scope info). | 615 // Use the empty function as closure (no scope info). |
| 593 global_context()->set_closure(*empty_function); | 616 global_context()->set_closure(*empty_function); |
| 594 global_context()->set_fcontext(*global_context()); | 617 global_context()->set_fcontext(*global_context()); |
| 595 global_context()->set_previous(NULL); | 618 global_context()->set_previous(NULL); |
| 596 // Set extension and global object. | 619 // Set extension and global object. |
| 597 global_context()->set_extension(*inner_global); | 620 global_context()->set_extension(*inner_global); |
| 598 global_context()->set_global(*inner_global); | 621 global_context()->set_global(*inner_global); |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 false); | 1298 false); |
| 1276 ASSERT(Top::has_pending_exception() != result); | 1299 ASSERT(Top::has_pending_exception() != result); |
| 1277 if (!result) { | 1300 if (!result) { |
| 1278 Top::clear_pending_exception(); | 1301 Top::clear_pending_exception(); |
| 1279 } | 1302 } |
| 1280 current->set_state(v8::INSTALLED); | 1303 current->set_state(v8::INSTALLED); |
| 1281 return result; | 1304 return result; |
| 1282 } | 1305 } |
| 1283 | 1306 |
| 1284 | 1307 |
| 1285 void Genesis::TransferMapsToDeserializedGlobals( | |
| 1286 Handle<GlobalObject> inner_global_outside_snapshot, | |
| 1287 Handle<GlobalObject> inner_global_from_snapshot) { | |
| 1288 Handle<Map> from_map(inner_global_outside_snapshot->map()); | |
| 1289 #ifdef DEBUG | |
| 1290 Handle<Map> to_map(inner_global_from_snapshot->map()); | |
| 1291 ASSERT_EQ(to_map->instance_size(), from_map->instance_size()); | |
| 1292 ASSERT_EQ(0, to_map->inobject_properties()); | |
| 1293 ASSERT_EQ(0, from_map->inobject_properties()); | |
| 1294 #endif | |
| 1295 inner_global_from_snapshot->set_map(*from_map); | |
| 1296 } | |
| 1297 | |
| 1298 | |
| 1299 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { | 1308 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { |
| 1300 HandleScope scope; | 1309 HandleScope scope; |
| 1301 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { | 1310 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { |
| 1302 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); | 1311 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); |
| 1303 Handle<String> name = Factory::LookupAsciiSymbol(Builtins::GetName(id)); | 1312 Handle<String> name = Factory::LookupAsciiSymbol(Builtins::GetName(id)); |
| 1304 Handle<JSFunction> function | 1313 Handle<JSFunction> function |
| 1305 = Handle<JSFunction>(JSFunction::cast(builtins->GetProperty(*name))); | 1314 = Handle<JSFunction>(JSFunction::cast(builtins->GetProperty(*name))); |
| 1306 builtins->set_javascript_builtin(id, *function); | 1315 builtins->set_javascript_builtin(id, *function); |
| 1307 Handle<SharedFunctionInfo> shared | 1316 Handle<SharedFunctionInfo> shared |
| 1308 = Handle<SharedFunctionInfo>(function->shared()); | 1317 = Handle<SharedFunctionInfo>(function->shared()); |
| 1309 if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) return false; | 1318 if (!EnsureCompiled(shared, CLEAR_EXCEPTION)) return false; |
| 1310 } | 1319 } |
| 1311 return true; | 1320 return true; |
| 1312 } | 1321 } |
| 1313 | 1322 |
| 1314 | 1323 |
| 1315 bool Genesis::ConfigureGlobalObjects( | 1324 bool Genesis::ConfigureGlobalObjects( |
| 1316 v8::Handle<v8::ObjectTemplate> global_proxy_template) { | 1325 v8::Handle<v8::ObjectTemplate> global_proxy_template) { |
| 1317 Handle<JSObject> global_proxy( | 1326 Handle<JSObject> global_proxy( |
| 1318 JSObject::cast(global_context()->global_proxy())); | 1327 JSObject::cast(global_context()->global_proxy())); |
| 1319 Handle<JSObject> js_global(JSObject::cast(global_context()->global())); | 1328 Handle<JSObject> inner_global(JSObject::cast(global_context()->global())); |
| 1320 | 1329 |
| 1321 if (!global_proxy_template.IsEmpty()) { | 1330 if (!global_proxy_template.IsEmpty()) { |
| 1322 // Configure the global proxy object. | 1331 // Configure the global proxy object. |
| 1323 Handle<ObjectTemplateInfo> proxy_data = | 1332 Handle<ObjectTemplateInfo> proxy_data = |
| 1324 v8::Utils::OpenHandle(*global_proxy_template); | 1333 v8::Utils::OpenHandle(*global_proxy_template); |
| 1325 if (!ConfigureApiObject(global_proxy, proxy_data)) return false; | 1334 if (!ConfigureApiObject(global_proxy, proxy_data)) return false; |
| 1326 | 1335 |
| 1327 // Configure the inner global object. | 1336 // Configure the inner global object. |
| 1328 Handle<FunctionTemplateInfo> proxy_constructor( | 1337 Handle<FunctionTemplateInfo> proxy_constructor( |
| 1329 FunctionTemplateInfo::cast(proxy_data->constructor())); | 1338 FunctionTemplateInfo::cast(proxy_data->constructor())); |
| 1330 if (!proxy_constructor->prototype_template()->IsUndefined()) { | 1339 if (!proxy_constructor->prototype_template()->IsUndefined()) { |
| 1331 Handle<ObjectTemplateInfo> inner_data( | 1340 Handle<ObjectTemplateInfo> inner_data( |
| 1332 ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); | 1341 ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); |
| 1333 if (!ConfigureApiObject(js_global, inner_data)) return false; | 1342 if (!ConfigureApiObject(inner_global, inner_data)) return false; |
| 1334 } | 1343 } |
| 1335 } | 1344 } |
| 1336 | 1345 |
| 1337 SetObjectPrototype(global_proxy, js_global); | 1346 SetObjectPrototype(global_proxy, inner_global); |
| 1338 return true; | 1347 return true; |
| 1339 } | 1348 } |
| 1340 | 1349 |
| 1341 | 1350 |
| 1342 bool Genesis::ConfigureApiObject(Handle<JSObject> object, | 1351 bool Genesis::ConfigureApiObject(Handle<JSObject> object, |
| 1343 Handle<ObjectTemplateInfo> object_template) { | 1352 Handle<ObjectTemplateInfo> object_template) { |
| 1344 ASSERT(!object_template.is_null()); | 1353 ASSERT(!object_template.is_null()); |
| 1345 ASSERT(object->IsInstanceOf( | 1354 ASSERT(object->IsInstanceOf( |
| 1346 FunctionTemplateInfo::cast(object_template->constructor()))); | 1355 FunctionTemplateInfo::cast(object_template->constructor()))); |
| 1347 | 1356 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); | 1559 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); |
| 1551 if (!new_context.is_null()) { | 1560 if (!new_context.is_null()) { |
| 1552 global_context_ = | 1561 global_context_ = |
| 1553 Handle<Context>::cast(GlobalHandles::Create(*new_context)); | 1562 Handle<Context>::cast(GlobalHandles::Create(*new_context)); |
| 1554 Top::set_context(*global_context_); | 1563 Top::set_context(*global_context_); |
| 1555 i::Counters::contexts_created_by_snapshot.Increment(); | 1564 i::Counters::contexts_created_by_snapshot.Increment(); |
| 1556 result_ = global_context_; | 1565 result_ = global_context_; |
| 1557 JSFunction* empty_function = | 1566 JSFunction* empty_function = |
| 1558 JSFunction::cast(result_->function_map()->prototype()); | 1567 JSFunction::cast(result_->function_map()->prototype()); |
| 1559 empty_function_ = Handle<JSFunction>(empty_function); | 1568 empty_function_ = Handle<JSFunction>(empty_function); |
| 1560 Handle<GlobalObject> inner_global_outside_snapshot; | 1569 Handle<GlobalObject> inner_global; |
| 1561 Handle<JSGlobalProxy> global_proxy = | 1570 Handle<JSGlobalProxy> global_proxy = |
| 1562 CreateNewGlobals(global_template, | 1571 CreateNewGlobals(global_template, |
| 1563 global_object, | 1572 global_object, |
| 1564 &inner_global_outside_snapshot); | 1573 &inner_global); |
| 1565 // CreateNewGlobals returns an inner global that it just made, but | 1574 |
| 1566 // we won't give that to HookUpGlobalProxy because we want to hook | |
| 1567 // up the global proxy to the one from the snapshot. | |
| 1568 Handle<GlobalObject> inner_global( | |
| 1569 GlobalObject::cast(global_context_->extension())); | |
| 1570 HookUpGlobalProxy(inner_global, global_proxy); | 1575 HookUpGlobalProxy(inner_global, global_proxy); |
| 1571 TransferMapsToDeserializedGlobals(inner_global_outside_snapshot, | 1576 HookUpInnerGlobal(inner_global); |
| 1572 inner_global); | 1577 |
| 1573 if (!ConfigureGlobalObjects(global_template)) return; | 1578 if (!ConfigureGlobalObjects(global_template)) return; |
| 1574 } else { | 1579 } else { |
| 1575 // We get here if there was no context snapshot. | 1580 // We get here if there was no context snapshot. |
| 1576 CreateRoots(); | 1581 CreateRoots(); |
| 1577 Handle<JSFunction> empty_function = CreateEmptyFunction(); | 1582 Handle<JSFunction> empty_function = CreateEmptyFunction(); |
| 1578 Handle<GlobalObject> inner_global; | 1583 Handle<GlobalObject> inner_global; |
| 1579 Handle<JSGlobalProxy> global_proxy = | 1584 Handle<JSGlobalProxy> global_proxy = |
| 1580 CreateNewGlobals(global_template, global_object, &inner_global); | 1585 CreateNewGlobals(global_template, global_object, &inner_global); |
| 1581 HookUpGlobalProxy(inner_global, global_proxy); | 1586 HookUpGlobalProxy(inner_global, global_proxy); |
| 1582 InitializeGlobal(inner_global, empty_function); | 1587 InitializeGlobal(inner_global, empty_function); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 } | 1638 } |
| 1634 | 1639 |
| 1635 | 1640 |
| 1636 // Restore statics that are thread local. | 1641 // Restore statics that are thread local. |
| 1637 char* BootstrapperActive::RestoreState(char* from) { | 1642 char* BootstrapperActive::RestoreState(char* from) { |
| 1638 nesting_ = *reinterpret_cast<int*>(from); | 1643 nesting_ = *reinterpret_cast<int*>(from); |
| 1639 return from + sizeof(nesting_); | 1644 return from + sizeof(nesting_); |
| 1640 } | 1645 } |
| 1641 | 1646 |
| 1642 } } // namespace v8::internal | 1647 } } // namespace v8::internal |
| OLD | NEW |