| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 // Allocate the native context FixedArray first and then patch the | 666 // Allocate the native context FixedArray first and then patch the |
| 667 // closure and extension object later (we need the empty function | 667 // closure and extension object later (we need the empty function |
| 668 // and the global object, but in order to create those, we need the | 668 // and the global object, but in order to create those, we need the |
| 669 // native context). | 669 // native context). |
| 670 native_context_ = factory()->NewNativeContext(); | 670 native_context_ = factory()->NewNativeContext(); |
| 671 AddToWeakNativeContextList(*native_context()); | 671 AddToWeakNativeContextList(*native_context()); |
| 672 isolate()->set_context(*native_context()); | 672 isolate()->set_context(*native_context()); |
| 673 | 673 |
| 674 // Allocate the message listeners object. | 674 // Allocate the message listeners object. |
| 675 { | 675 { |
| 676 v8::NeanderArray listeners; | 676 v8::NeanderArray listeners(isolate()); |
| 677 native_context()->set_message_listeners(*listeners.value()); | 677 native_context()->set_message_listeners(*listeners.value()); |
| 678 } | 678 } |
| 679 } | 679 } |
| 680 | 680 |
| 681 | 681 |
| 682 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( | 682 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( |
| 683 v8::Handle<v8::ObjectTemplate> global_template, | 683 v8::Handle<v8::ObjectTemplate> global_template, |
| 684 Handle<Object> global_object, | 684 Handle<Object> global_object, |
| 685 Handle<GlobalObject>* inner_global_out) { | 685 Handle<GlobalObject>* inner_global_out) { |
| 686 // The argument global_template aka data is an ObjectTemplateInfo. | 686 // The argument global_template aka data is an ObjectTemplateInfo. |
| (...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 builtins_fun->initial_map()->set_dictionary_map(true); | 1662 builtins_fun->initial_map()->set_dictionary_map(true); |
| 1663 builtins_fun->initial_map()->set_prototype(heap()->null_value()); | 1663 builtins_fun->initial_map()->set_prototype(heap()->null_value()); |
| 1664 | 1664 |
| 1665 // Allocate the builtins object. | 1665 // Allocate the builtins object. |
| 1666 Handle<JSBuiltinsObject> builtins = | 1666 Handle<JSBuiltinsObject> builtins = |
| 1667 Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun)); | 1667 Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun)); |
| 1668 builtins->set_builtins(*builtins); | 1668 builtins->set_builtins(*builtins); |
| 1669 builtins->set_native_context(*native_context()); | 1669 builtins->set_native_context(*native_context()); |
| 1670 builtins->set_global_context(*native_context()); | 1670 builtins->set_global_context(*native_context()); |
| 1671 builtins->set_global_receiver(*builtins); | 1671 builtins->set_global_receiver(*builtins); |
| 1672 builtins->set_global_receiver(native_context()->global_proxy()); |
| 1673 |
| 1672 | 1674 |
| 1673 // Set up the 'global' properties of the builtins object. The | 1675 // Set up the 'global' properties of the builtins object. The |
| 1674 // 'global' property that refers to the global object is the only | 1676 // 'global' property that refers to the global object is the only |
| 1675 // way to get from code running in the builtins context to the | 1677 // way to get from code running in the builtins context to the |
| 1676 // global object. | 1678 // global object. |
| 1677 static const PropertyAttributes attributes = | 1679 static const PropertyAttributes attributes = |
| 1678 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | 1680 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 1679 Handle<String> global_string = | 1681 Handle<String> global_string = |
| 1680 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("global")); | 1682 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("global")); |
| 1681 Handle<Object> global_obj(native_context()->global_object(), isolate()); | 1683 Handle<Object> global_obj(native_context()->global_object(), isolate()); |
| 1682 CHECK_NOT_EMPTY_HANDLE(isolate(), | 1684 CHECK_NOT_EMPTY_HANDLE(isolate(), |
| 1683 JSObject::SetLocalPropertyIgnoreAttributes( | 1685 JSObject::SetLocalPropertyIgnoreAttributes( |
| 1684 builtins, global_string, global_obj, attributes)); | 1686 builtins, global_string, global_obj, attributes)); |
| 1687 Handle<String> builtins_string = |
| 1688 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("builtins")); |
| 1689 CHECK_NOT_EMPTY_HANDLE(isolate(), |
| 1690 JSObject::SetLocalPropertyIgnoreAttributes( |
| 1691 builtins, builtins_string, builtins, attributes)); |
| 1685 | 1692 |
| 1686 // Set up the reference from the global object to the builtins object. | 1693 // Set up the reference from the global object to the builtins object. |
| 1687 JSGlobalObject::cast(native_context()->global_object())-> | 1694 JSGlobalObject::cast(native_context()->global_object())-> |
| 1688 set_builtins(*builtins); | 1695 set_builtins(*builtins); |
| 1689 | 1696 |
| 1690 // Create a bridge function that has context in the native context. | 1697 // Create a bridge function that has context in the native context. |
| 1691 Handle<JSFunction> bridge = | 1698 Handle<JSFunction> bridge = |
| 1692 factory()->NewFunction(factory()->empty_string(), | 1699 factory()->NewFunction(factory()->empty_string(), |
| 1693 factory()->undefined_value()); | 1700 factory()->undefined_value()); |
| 1694 ASSERT(bridge->context() == *isolate()->native_context()); | 1701 ASSERT(bridge->context() == *isolate()->native_context()); |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2279 bool Genesis::InstallExtension(Isolate* isolate, | 2286 bool Genesis::InstallExtension(Isolate* isolate, |
| 2280 const char* name, | 2287 const char* name, |
| 2281 ExtensionStates* extension_states) { | 2288 ExtensionStates* extension_states) { |
| 2282 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); | 2289 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); |
| 2283 // Loop until we find the relevant extension | 2290 // Loop until we find the relevant extension |
| 2284 while (current != NULL) { | 2291 while (current != NULL) { |
| 2285 if (strcmp(name, current->extension()->name()) == 0) break; | 2292 if (strcmp(name, current->extension()->name()) == 0) break; |
| 2286 current = current->next(); | 2293 current = current->next(); |
| 2287 } | 2294 } |
| 2288 // Didn't find the extension; fail. | 2295 // Didn't find the extension; fail. |
| 2289 if (current == NULL) { | 2296 if (!Utils::ApiCheck(current != NULL, |
| 2290 v8::Utils::ReportApiFailure( | 2297 "v8::Context::New()", |
| 2291 "v8::Context::New()", "Cannot find required extension"); | 2298 "Cannot find required extension")) { |
| 2292 return false; | 2299 return false; |
| 2293 } | 2300 } |
| 2294 return InstallExtension(isolate, current, extension_states); | 2301 return InstallExtension(isolate, current, extension_states); |
| 2295 } | 2302 } |
| 2296 | 2303 |
| 2297 | 2304 |
| 2298 bool Genesis::InstallExtension(Isolate* isolate, | 2305 bool Genesis::InstallExtension(Isolate* isolate, |
| 2299 v8::RegisteredExtension* current, | 2306 v8::RegisteredExtension* current, |
| 2300 ExtensionStates* extension_states) { | 2307 ExtensionStates* extension_states) { |
| 2301 HandleScope scope(isolate); | 2308 HandleScope scope(isolate); |
| 2302 | 2309 |
| 2303 if (extension_states->get_state(current) == INSTALLED) return true; | 2310 if (extension_states->get_state(current) == INSTALLED) return true; |
| 2304 // The current node has already been visited so there must be a | 2311 // The current node has already been visited so there must be a |
| 2305 // cycle in the dependency graph; fail. | 2312 // cycle in the dependency graph; fail. |
| 2306 if (extension_states->get_state(current) == VISITED) { | 2313 if (!Utils::ApiCheck(extension_states->get_state(current) != VISITED, |
| 2307 v8::Utils::ReportApiFailure( | 2314 "v8::Context::New()", |
| 2308 "v8::Context::New()", "Circular extension dependency"); | 2315 "Circular extension dependency")) { |
| 2309 return false; | 2316 return false; |
| 2310 } | 2317 } |
| 2311 ASSERT(extension_states->get_state(current) == UNVISITED); | 2318 ASSERT(extension_states->get_state(current) == UNVISITED); |
| 2312 extension_states->set_state(current, VISITED); | 2319 extension_states->set_state(current, VISITED); |
| 2313 v8::Extension* extension = current->extension(); | 2320 v8::Extension* extension = current->extension(); |
| 2314 // Install the extension's dependencies | 2321 // Install the extension's dependencies |
| 2315 for (int i = 0; i < extension->dependency_count(); i++) { | 2322 for (int i = 0; i < extension->dependency_count(); i++) { |
| 2316 if (!InstallExtension(isolate, | 2323 if (!InstallExtension(isolate, |
| 2317 extension->dependencies()[i], | 2324 extension->dependencies()[i], |
| 2318 extension_states)) { | 2325 extension_states)) { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2574 isolate->set_context(*native_context()); | 2581 isolate->set_context(*native_context()); |
| 2575 isolate->counters()->contexts_created_by_snapshot()->Increment(); | 2582 isolate->counters()->contexts_created_by_snapshot()->Increment(); |
| 2576 Handle<GlobalObject> inner_global; | 2583 Handle<GlobalObject> inner_global; |
| 2577 Handle<JSGlobalProxy> global_proxy = | 2584 Handle<JSGlobalProxy> global_proxy = |
| 2578 CreateNewGlobals(global_template, | 2585 CreateNewGlobals(global_template, |
| 2579 global_object, | 2586 global_object, |
| 2580 &inner_global); | 2587 &inner_global); |
| 2581 | 2588 |
| 2582 HookUpGlobalProxy(inner_global, global_proxy); | 2589 HookUpGlobalProxy(inner_global, global_proxy); |
| 2583 HookUpInnerGlobal(inner_global); | 2590 HookUpInnerGlobal(inner_global); |
| 2591 native_context()->builtins()->set_global_receiver( |
| 2592 native_context()->global_proxy()); |
| 2584 | 2593 |
| 2585 if (!ConfigureGlobalObjects(global_template)) return; | 2594 if (!ConfigureGlobalObjects(global_template)) return; |
| 2586 } else { | 2595 } else { |
| 2587 // We get here if there was no context snapshot. | 2596 // We get here if there was no context snapshot. |
| 2588 CreateRoots(); | 2597 CreateRoots(); |
| 2589 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); | 2598 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); |
| 2590 CreateStrictModeFunctionMaps(empty_function); | 2599 CreateStrictModeFunctionMaps(empty_function); |
| 2591 Handle<GlobalObject> inner_global; | 2600 Handle<GlobalObject> inner_global; |
| 2592 Handle<JSGlobalProxy> global_proxy = | 2601 Handle<JSGlobalProxy> global_proxy = |
| 2593 CreateNewGlobals(global_template, global_object, &inner_global); | 2602 CreateNewGlobals(global_template, global_object, &inner_global); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2697 return from + sizeof(NestingCounterType); | 2706 return from + sizeof(NestingCounterType); |
| 2698 } | 2707 } |
| 2699 | 2708 |
| 2700 | 2709 |
| 2701 // Called when the top-level V8 mutex is destroyed. | 2710 // Called when the top-level V8 mutex is destroyed. |
| 2702 void Bootstrapper::FreeThreadResources() { | 2711 void Bootstrapper::FreeThreadResources() { |
| 2703 ASSERT(!IsActive()); | 2712 ASSERT(!IsActive()); |
| 2704 } | 2713 } |
| 2705 | 2714 |
| 2706 } } // namespace v8::internal | 2715 } } // namespace v8::internal |
| OLD | NEW |