Revision: 18645
Author:   [email protected]
Date:     Thu Jan 16 13:18:28 2014 UTC
Log:      Robustified extension installation a bit.

Removed ADDRESS_SANITIZER #ifdefs, the extension is so tiny that it's
not worth the clutter.

[email protected]

Review URL: https://codereview.chromium.org/138143014
http://code.google.com/p/v8/source/detail?r=18645

Modified:
 /branches/bleeding_edge/src/bootstrapper.cc
 /branches/bleeding_edge/src/flag-definitions.h

=======================================
--- /branches/bleeding_edge/src/bootstrapper.cc Thu Jan 16 08:17:40 2014 UTC
+++ /branches/bleeding_edge/src/bootstrapper.cc Thu Jan 16 13:18:28 2014 UTC
@@ -102,9 +102,7 @@


 void Bootstrapper::InitializeOncePerProcess() {
-#ifdef ADDRESS_SANITIZER
   FreeBufferExtension::Register();
-#endif
   GCExtension::Register();
   ExternalizeStringExtension::Register();
   StatisticsExtension::Register();
@@ -238,13 +236,18 @@
   // provided.
   static bool InstallExtensions(Handle<Context> 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<Context> native_context);
+  static bool InstallSpecialObjects(Handle<Context> native_context);
   bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins);
   bool ConfigureApiObject(Handle<JSObject> object,
                           Handle<ObjectTemplateInfo> object_template);
@@ -2152,13 +2155,12 @@
   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<Context> native_context) {
+bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
   Isolate* isolate = native_context->GetIsolate();
   Factory* factory = isolate->factory();
   HandleScope scope(isolate);
@@ -2168,11 +2170,9 @@
if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
     Handle<String> natives =
         factory->InternalizeUtf8String(FLAG_expose_natives_as);
-    CHECK_NOT_EMPTY_HANDLE(isolate,
-                           JSObject::SetLocalPropertyIgnoreAttributes(
-                               global, natives,
-                               Handle<JSObject>(global->builtins()),
-                               DONT_ENUM));
+    JSObject::SetLocalPropertyIgnoreAttributes(
+        global, natives, Handle<JSObject>(global->builtins()), DONT_ENUM);
+    if (isolate->has_pending_exception()) return false;
   }

   Handle<Object> Error = GetProperty(global, "Error");
@@ -2181,10 +2181,9 @@
         STATIC_ASCII_VECTOR("stackTraceLimit"));
     Handle<Smi> stack_trace_limit(
         Smi::FromInt(FLAG_stack_trace_limit), isolate);
-    CHECK_NOT_EMPTY_HANDLE(isolate,
-                           JSObject::SetLocalPropertyIgnoreAttributes(
-                               Handle<JSObject>::cast(Error), name,
-                               stack_trace_limit, NONE));
+    JSObject::SetLocalPropertyIgnoreAttributes(
+        Handle<JSObject>::cast(Error), name, stack_trace_limit, NONE);
+    if (isolate->has_pending_exception()) return false;
   }

 #ifdef ENABLE_DEBUGGER_SUPPORT
@@ -2193,7 +2192,7 @@
     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 @@
         factory->InternalizeUtf8String(FLAG_expose_debug_as);
     Handle<Object> 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;
 }


@@ -2239,39 +2239,47 @@
   map_.Lookup(extension, Hash(extension), true)->value =
       reinterpret_cast<void*>(static_cast<intptr_t>(state));
 }
+

 bool Genesis::InstallExtensions(Handle<Context> 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::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");
 }


=======================================
--- /branches/bleeding_edge/src/flag-definitions.h Thu Jan 16 11:59:34 2014 UTC +++ /branches/bleeding_edge/src/flag-definitions.h Thu Jan 16 13:18:28 2014 UTC
@@ -398,9 +398,7 @@
 // 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")

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to