Chromium Code Reviews| Index: src/bootstrapper.cc |
| =================================================================== |
| --- src/bootstrapper.cc (revision 3800) |
| +++ src/bootstrapper.cc (working copy) |
| @@ -319,10 +319,11 @@ |
| Handle<Object> global_object); |
| void InstallNativeFunctions(); |
| bool InstallNatives(); |
| - bool InstallExtensions(v8::ExtensionConfiguration* extensions); |
| - bool InstallExtension(const char* name); |
| - bool InstallExtension(v8::RegisteredExtension* current); |
| - bool InstallSpecialObjects(); |
| + static bool InstallExtensions(Handle<Context> global_context, |
| + v8::ExtensionConfiguration* extensions); |
| + static bool InstallExtension(const char* name); |
| + static bool InstallExtension(v8::RegisteredExtension* current); |
| + static void InstallSpecialObjects(Handle<Context> global_context); |
| bool ConfigureApiObject(Handle<JSObject> object, |
| Handle<ObjectTemplateInfo> object_template); |
| bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template); |
| @@ -351,9 +352,11 @@ |
| Handle<String> source, |
| SourceCodeCache* cache, |
| v8::Extension* extension, |
| + Handle<Context> top_context, |
| bool use_runtime_context); |
| Handle<Context> result_; |
| + friend class Bootstrapper; |
| }; |
| Genesis* Genesis::current_ = NULL; |
| @@ -375,7 +378,7 @@ |
| bool Bootstrapper::IsActive() { |
| - return Genesis::current() != NULL; |
| + return active_ != 0 || Genesis::current() != NULL; |
|
Mads Ager (chromium)
2010/02/05 08:57:09
Can we get rid of the Genesis::current() check and
|
| } |
| @@ -383,7 +386,13 @@ |
| Handle<Object> global_object, |
| v8::Handle<v8::ObjectTemplate> global_template, |
| v8::ExtensionConfiguration* extensions) { |
| + HandleScope scope; |
| Genesis genesis(global_object, global_template, extensions); |
| + if (!genesis.result().is_null()) { |
| + if (!InstallExtensions(genesis.result(), extensions)) { |
| + return Handle<Context>(); |
| + } |
| + } |
| return genesis.result(); |
| } |
| @@ -900,8 +909,12 @@ |
| #ifdef ENABLE_DEBUGGER_SUPPORT |
| Debugger::set_compiling_natives(true); |
| #endif |
| - bool result = |
| - CompileScriptCached(name, source, NULL, NULL, true); |
| + bool result = CompileScriptCached(name, |
| + source, |
| + NULL, |
| + NULL, |
| + Handle<Context>(Top::context()), |
| + true); |
| ASSERT(Top::has_pending_exception() != result); |
| if (!result) Top::clear_pending_exception(); |
| #ifdef ENABLE_DEBUGGER_SUPPORT |
| @@ -915,6 +928,7 @@ |
| Handle<String> source, |
| SourceCodeCache* cache, |
| v8::Extension* extension, |
| + Handle<Context> top_context, |
| bool use_runtime_context) { |
| HandleScope scope; |
| Handle<JSFunction> boilerplate; |
| @@ -939,11 +953,11 @@ |
| // Setup the function context. Conceptually, we should clone the |
| // function before overwriting the context but since we're in a |
| // single-threaded environment it is not strictly necessary. |
| - ASSERT(Top::context()->IsGlobalContext()); |
| + ASSERT(top_context->IsGlobalContext()); |
| Handle<Context> context = |
| Handle<Context>(use_runtime_context |
| - ? Top::context()->runtime_context() |
| - : Top::context()); |
| + ? Handle<Context>(top_context->runtime_context()) |
| + : top_context); |
| Handle<JSFunction> fun = |
| Factory::NewFunctionFromBoilerplate(boilerplate, context); |
| @@ -951,14 +965,14 @@ |
| // object as the receiver. Provide no parameters. |
| Handle<Object> receiver = |
| Handle<Object>(use_runtime_context |
| - ? Top::context()->builtins() |
| - : Top::context()->global()); |
| + ? top_context->builtins() |
| + : top_context->global()); |
| bool has_pending_exception; |
| Handle<Object> result = |
| Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); |
| if (has_pending_exception) return false; |
| return PendingFixups::Process( |
| - Handle<JSBuiltinsObject>(Top::context()->builtins())); |
| + Handle<JSBuiltinsObject>(top_context->builtins())); |
| } |
| @@ -1210,10 +1224,24 @@ |
| } |
| -bool Genesis::InstallSpecialObjects() { |
| +int Bootstrapper::active_ = 0; |
| + |
| + |
| +bool Bootstrapper::InstallExtensions(Handle<Context> global_context, |
| + v8::ExtensionConfiguration* extensions) { |
| + BootstrapperActive active; |
| + SaveContext saved_context; |
| + Top::set_context(*global_context); |
| + if (!Genesis::InstallExtensions(global_context, extensions)) return false; |
| + Genesis::InstallSpecialObjects(global_context); |
| + return true; |
| +} |
| + |
| + |
| +void Genesis::InstallSpecialObjects(Handle<Context> global_context) { |
| HandleScope scope; |
| Handle<JSGlobalObject> js_global( |
| - JSGlobalObject::cast(global_context()->global())); |
| + JSGlobalObject::cast(global_context->global())); |
| // Expose the natives in global if a name for it is specified. |
| if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { |
| Handle<String> natives_string = |
| @@ -1237,12 +1265,12 @@ |
| // If loading fails we just bail out without installing the |
| // debugger but without tanking the whole context. |
| if (!Debug::Load()) |
|
Mads Ager (chromium)
2010/02/05 08:57:09
Either make this a one-liner or use braces around
|
| - return true; |
| + return; |
| // Set the security token for the debugger context to the same as |
| // the shell global context to allow calling between these (otherwise |
| // exposing debug global object doesn't make much sense). |
| Debug::debug_context()->set_security_token( |
| - global_context()->security_token()); |
| + global_context->security_token()); |
| Handle<String> debug_string = |
| Factory::LookupAsciiSymbol(FLAG_expose_debug_as); |
| @@ -1250,19 +1278,18 @@ |
| Handle<Object>(Debug::debug_context()->global_proxy()), DONT_ENUM); |
| } |
| #endif |
| - |
| - return true; |
| } |
| -bool Genesis::InstallExtensions(v8::ExtensionConfiguration* extensions) { |
| +bool Genesis::InstallExtensions(Handle<Context> global_context, |
| + v8::ExtensionConfiguration* extensions) { |
| // Clear coloring of extension list |
| v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); |
| while (current != NULL) { |
| current->set_state(v8::UNVISITED); |
| current = current->next(); |
| } |
| - // Install auto extensions. Coordinate with AutoExtensionsExist below. |
| + // Install auto extensions. |
| current = v8::RegisteredExtension::first_extension(); |
| while (current != NULL) { |
| if (current->extension()->auto_enable()) |
| @@ -1326,7 +1353,9 @@ |
| Handle<String> source_code = Factory::NewStringFromAscii(source); |
| bool result = CompileScriptCached(CStrVector(extension->name()), |
| source_code, |
| - &extensions_cache, extension, |
| + &extensions_cache, |
| + extension, |
| + Handle<Context>(Top::context()), |
| false); |
| ASSERT(Top::has_pending_exception() != result); |
| if (!result) { |
| @@ -1570,7 +1599,7 @@ |
| // Before creating the roots we must save the context and restore it |
| // on all function exits. |
| HandleScope scope; |
| - SaveContext context; |
| + SaveContext saved_context; |
| CreateRoots(global_template, global_object); |
| @@ -1581,10 +1610,6 @@ |
| if (!ConfigureGlobalObjects(global_template)) return; |
| - if (!InstallExtensions(extensions)) return; |
| - |
| - if (!InstallSpecialObjects()) return; |
| - |
| result_ = global_context_; |
| } |
| @@ -1615,19 +1640,6 @@ |
| } |
| -// Are there extensions that should be installed even if no extension was |
| -// specified? |
| -bool Bootstrapper::AutoExtensionsExist() { |
| - // Find auto extensions. |
| - v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); |
| - while (current != NULL) { |
| - if (current->extension()->auto_enable()) return true; |
| - current = current->next(); |
| - } |
| - return FLAG_expose_gc; |
| -} |
| - |
| - |
| // Reserve space for statics needing saving and restoring. |
| int Genesis::ArchiveSpacePerThread() { |
| return sizeof(current_); |