From c8475cf1b13966e201dc156e0fc117a670a4cf08 Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Thu, 16 Jan 2014 13:18:28 +0000 Subject: [PATCH] Robustified extension installation a bit. Removed ADDRESS_SANITIZER #ifdefs, the extension is so tiny that it's not worth the clutter. R=dcarney@chromium.org Review URL: https://codereview.chromium.org/138143014 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18645 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/bootstrapper.cc | 115 ++++++++++++++++++++++++++----------------------- src/flag-definitions.h | 2 - 2 files changed, 60 insertions(+), 57 deletions(-) diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index d039ac0..288cac2 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -102,9 +102,7 @@ void Bootstrapper::Initialize(bool create_heap_objects) { void Bootstrapper::InitializeOncePerProcess() { -#ifdef ADDRESS_SANITIZER FreeBufferExtension::Register(); -#endif GCExtension::Register(); ExternalizeStringExtension::Register(); StatisticsExtension::Register(); @@ -238,13 +236,18 @@ class Genesis BASE_EMBEDDED { // provided. static bool InstallExtensions(Handle native_context, v8::ExtensionConfiguration* extensions); + static bool InstallAutoExtensions(Isolate* isolate, + ExtensionStates* extension_states); + static bool InstallRequestedExtensions(Isolate* isolate, + v8::ExtensionConfiguration* extensions, + ExtensionStates* extension_states); static bool InstallExtension(Isolate* isolate, const char* name, ExtensionStates* extension_states); static bool InstallExtension(Isolate* isolate, v8::RegisteredExtension* current, ExtensionStates* extension_states); - static void InstallSpecialObjects(Handle native_context); + static bool InstallSpecialObjects(Handle native_context); bool InstallJSBuiltins(Handle builtins); bool ConfigureApiObject(Handle object, Handle object_template); @@ -2152,13 +2155,12 @@ bool Bootstrapper::InstallExtensions(Handle native_context, BootstrapperActive active(this); SaveContext saved_context(isolate_); isolate_->set_context(*native_context); - if (!Genesis::InstallExtensions(native_context, extensions)) return false; - Genesis::InstallSpecialObjects(native_context); - return true; + return Genesis::InstallExtensions(native_context, extensions) && + Genesis::InstallSpecialObjects(native_context); } -void Genesis::InstallSpecialObjects(Handle native_context) { +bool Genesis::InstallSpecialObjects(Handle native_context) { Isolate* isolate = native_context->GetIsolate(); Factory* factory = isolate->factory(); HandleScope scope(isolate); @@ -2168,11 +2170,9 @@ void Genesis::InstallSpecialObjects(Handle native_context) { if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { Handle natives = factory->InternalizeUtf8String(FLAG_expose_natives_as); - CHECK_NOT_EMPTY_HANDLE(isolate, - JSObject::SetLocalPropertyIgnoreAttributes( - global, natives, - Handle(global->builtins()), - DONT_ENUM)); + JSObject::SetLocalPropertyIgnoreAttributes( + global, natives, Handle(global->builtins()), DONT_ENUM); + if (isolate->has_pending_exception()) return false; } Handle Error = GetProperty(global, "Error"); @@ -2181,10 +2181,9 @@ void Genesis::InstallSpecialObjects(Handle native_context) { STATIC_ASCII_VECTOR("stackTraceLimit")); Handle stack_trace_limit( Smi::FromInt(FLAG_stack_trace_limit), isolate); - CHECK_NOT_EMPTY_HANDLE(isolate, - JSObject::SetLocalPropertyIgnoreAttributes( - Handle::cast(Error), name, - stack_trace_limit, NONE)); + JSObject::SetLocalPropertyIgnoreAttributes( + Handle::cast(Error), name, stack_trace_limit, NONE); + if (isolate->has_pending_exception()) return false; } #ifdef ENABLE_DEBUGGER_SUPPORT @@ -2193,7 +2192,7 @@ void Genesis::InstallSpecialObjects(Handle native_context) { Debug* debug = isolate->debug(); // If loading fails we just bail out without installing the // debugger but without tanking the whole context. - if (!debug->Load()) return; + if (!debug->Load()) return true; // Set the security token for the debugger context to the same as // the shell native context to allow calling between these (otherwise // exposing debug global object doesn't make much sense). @@ -2204,11 +2203,12 @@ void Genesis::InstallSpecialObjects(Handle native_context) { factory->InternalizeUtf8String(FLAG_expose_debug_as); Handle global_proxy( debug->debug_context()->global_proxy(), isolate); - CHECK_NOT_EMPTY_HANDLE(isolate, - JSObject::SetLocalPropertyIgnoreAttributes( - global, debug_string, global_proxy, DONT_ENUM)); + JSObject::SetLocalPropertyIgnoreAttributes( + global, debug_string, global_proxy, DONT_ENUM); + if (isolate->has_pending_exception()) return false; } #endif + return true; } @@ -2240,38 +2240,46 @@ void Genesis::ExtensionStates::set_state(RegisteredExtension* extension, reinterpret_cast(static_cast(state)); } + bool Genesis::InstallExtensions(Handle native_context, v8::ExtensionConfiguration* extensions) { Isolate* isolate = native_context->GetIsolate(); ExtensionStates extension_states; // All extensions have state UNVISITED. - // Install auto extensions. - v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); - while (current != NULL) { - if (current->extension()->auto_enable()) - InstallExtension(isolate, current, &extension_states); - current = current->next(); + return InstallAutoExtensions(isolate, &extension_states) && + (!FLAG_expose_free_buffer || + InstallExtension(isolate, "v8/free-buffer", &extension_states)) && + (!FLAG_expose_gc || + InstallExtension(isolate, "v8/gc", &extension_states)) && + (!FLAG_expose_externalize_string || + InstallExtension(isolate, "v8/externalize", &extension_states)) && + (!FLAG_track_gc_object_stats || + InstallExtension(isolate, "v8/statistics", &extension_states)) && + (!FLAG_expose_trigger_failure || + InstallExtension(isolate, "v8/trigger-failure", &extension_states)) && + InstallRequestedExtensions(isolate, extensions, &extension_states); +} + + +bool Genesis::InstallAutoExtensions(Isolate* isolate, + ExtensionStates* extension_states) { + for (v8::RegisteredExtension* it = v8::RegisteredExtension::first_extension(); + it != NULL; + it = it->next()) { + if (it->extension()->auto_enable() && + !InstallExtension(isolate, it, extension_states)) { + return false; + } } + return true; +} -#ifdef ADDRESS_SANITIZER - if (FLAG_expose_free_buffer) { - InstallExtension(isolate, "v8/free-buffer", &extension_states); - } -#endif - if (FLAG_expose_gc) InstallExtension(isolate, "v8/gc", &extension_states); - if (FLAG_expose_externalize_string) { - InstallExtension(isolate, "v8/externalize", &extension_states); - } - if (FLAG_track_gc_object_stats) { - InstallExtension(isolate, "v8/statistics", &extension_states); - } - if (FLAG_expose_trigger_failure) { - InstallExtension(isolate, "v8/trigger-failure", &extension_states); - } +bool Genesis::InstallRequestedExtensions(Isolate* isolate, + v8::ExtensionConfiguration* extensions, + ExtensionStates* extension_states) { for (const char** it = extensions->begin(); it != extensions->end(); ++it) { - if (!InstallExtension(isolate, *it, &extension_states)) return false; + if (!InstallExtension(isolate, *it, extension_states)) return false; } - return true; } @@ -2281,19 +2289,16 @@ bool Genesis::InstallExtensions(Handle native_context, bool Genesis::InstallExtension(Isolate* isolate, const char* name, ExtensionStates* extension_states) { - v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); - // Loop until we find the relevant extension - while (current != NULL) { - if (strcmp(name, current->extension()->name()) == 0) break; - current = current->next(); - } - // Didn't find the extension; fail. - if (!Utils::ApiCheck(current != NULL, - "v8::Context::New()", - "Cannot find required extension")) { - return false; + for (v8::RegisteredExtension* it = v8::RegisteredExtension::first_extension(); + it != NULL; + it = it->next()) { + if (strcmp(name, it->extension()->name()) == 0) { + return InstallExtension(isolate, it, extension_states); + } } - return InstallExtension(isolate, current, extension_states); + return Utils::ApiCheck(false, + "v8::Context::New()", + "Cannot find required extension"); } diff --git a/src/flag-definitions.h b/src/flag-definitions.h index c10bf79..1136daa 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -398,9 +398,7 @@ DEFINE_bool(enable_vldr_imm, false, // bootstrapper.cc DEFINE_string(expose_natives_as, NULL, "expose natives in global object") DEFINE_string(expose_debug_as, NULL, "expose debug in global object") -#ifdef ADDRESS_SANITIZER DEFINE_bool(expose_free_buffer, false, "expose freeBuffer extension") -#endif DEFINE_bool(expose_gc, false, "expose gc extension") DEFINE_string(expose_gc_as, NULL, "expose gc extension under the specified name") -- 2.7.4