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
parent 83e27375
...@@ -102,9 +102,7 @@ void Bootstrapper::Initialize(bool create_heap_objects) { ...@@ -102,9 +102,7 @@ void Bootstrapper::Initialize(bool create_heap_objects) {
void Bootstrapper::InitializeOncePerProcess() { void Bootstrapper::InitializeOncePerProcess() {
#ifdef ADDRESS_SANITIZER
FreeBufferExtension::Register(); FreeBufferExtension::Register();
#endif
GCExtension::Register(); GCExtension::Register();
ExternalizeStringExtension::Register(); ExternalizeStringExtension::Register();
StatisticsExtension::Register(); StatisticsExtension::Register();
...@@ -238,13 +236,18 @@ class Genesis BASE_EMBEDDED { ...@@ -238,13 +236,18 @@ class Genesis BASE_EMBEDDED {
// provided. // provided.
static bool InstallExtensions(Handle<Context> native_context, static bool InstallExtensions(Handle<Context> native_context,
v8::ExtensionConfiguration* extensions); 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, static bool InstallExtension(Isolate* isolate,
const char* name, const char* name,
ExtensionStates* extension_states); ExtensionStates* extension_states);
static bool InstallExtension(Isolate* isolate, static bool InstallExtension(Isolate* isolate,
v8::RegisteredExtension* current, v8::RegisteredExtension* current,
ExtensionStates* extension_states); ExtensionStates* extension_states);
static void InstallSpecialObjects(Handle<Context> native_context); static bool InstallSpecialObjects(Handle<Context> native_context);
bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins); bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins);
bool ConfigureApiObject(Handle<JSObject> object, bool ConfigureApiObject(Handle<JSObject> object,
Handle<ObjectTemplateInfo> object_template); Handle<ObjectTemplateInfo> object_template);
...@@ -2152,13 +2155,12 @@ bool Bootstrapper::InstallExtensions(Handle<Context> native_context, ...@@ -2152,13 +2155,12 @@ bool Bootstrapper::InstallExtensions(Handle<Context> native_context,
BootstrapperActive active(this); BootstrapperActive active(this);
SaveContext saved_context(isolate_); SaveContext saved_context(isolate_);
isolate_->set_context(*native_context); isolate_->set_context(*native_context);
if (!Genesis::InstallExtensions(native_context, extensions)) return false; return Genesis::InstallExtensions(native_context, extensions) &&
Genesis::InstallSpecialObjects(native_context); Genesis::InstallSpecialObjects(native_context);
return true;
} }
void Genesis::InstallSpecialObjects(Handle<Context> native_context) { bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
Isolate* isolate = native_context->GetIsolate(); Isolate* isolate = native_context->GetIsolate();
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
HandleScope scope(isolate); HandleScope scope(isolate);
...@@ -2168,11 +2170,9 @@ void Genesis::InstallSpecialObjects(Handle<Context> native_context) { ...@@ -2168,11 +2170,9 @@ void Genesis::InstallSpecialObjects(Handle<Context> native_context) {
if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
Handle<String> natives = Handle<String> natives =
factory->InternalizeUtf8String(FLAG_expose_natives_as); factory->InternalizeUtf8String(FLAG_expose_natives_as);
CHECK_NOT_EMPTY_HANDLE(isolate, JSObject::SetLocalPropertyIgnoreAttributes(
JSObject::SetLocalPropertyIgnoreAttributes( global, natives, Handle<JSObject>(global->builtins()), DONT_ENUM);
global, natives, if (isolate->has_pending_exception()) return false;
Handle<JSObject>(global->builtins()),
DONT_ENUM));
} }
Handle<Object> Error = GetProperty(global, "Error"); Handle<Object> Error = GetProperty(global, "Error");
...@@ -2181,10 +2181,9 @@ void Genesis::InstallSpecialObjects(Handle<Context> native_context) { ...@@ -2181,10 +2181,9 @@ void Genesis::InstallSpecialObjects(Handle<Context> native_context) {
STATIC_ASCII_VECTOR("stackTraceLimit")); STATIC_ASCII_VECTOR("stackTraceLimit"));
Handle<Smi> stack_trace_limit( Handle<Smi> stack_trace_limit(
Smi::FromInt(FLAG_stack_trace_limit), isolate); Smi::FromInt(FLAG_stack_trace_limit), isolate);
CHECK_NOT_EMPTY_HANDLE(isolate, JSObject::SetLocalPropertyIgnoreAttributes(
JSObject::SetLocalPropertyIgnoreAttributes( Handle<JSObject>::cast(Error), name, stack_trace_limit, NONE);
Handle<JSObject>::cast(Error), name, if (isolate->has_pending_exception()) return false;
stack_trace_limit, NONE));
} }
#ifdef ENABLE_DEBUGGER_SUPPORT #ifdef ENABLE_DEBUGGER_SUPPORT
...@@ -2193,7 +2192,7 @@ void Genesis::InstallSpecialObjects(Handle<Context> native_context) { ...@@ -2193,7 +2192,7 @@ void Genesis::InstallSpecialObjects(Handle<Context> native_context) {
Debug* debug = isolate->debug(); Debug* debug = isolate->debug();
// If loading fails we just bail out without installing the // If loading fails we just bail out without installing the
// debugger but without tanking the whole context. // 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 // Set the security token for the debugger context to the same as
// the shell native context to allow calling between these (otherwise // the shell native context to allow calling between these (otherwise
// exposing debug global object doesn't make much sense). // exposing debug global object doesn't make much sense).
...@@ -2204,11 +2203,12 @@ void Genesis::InstallSpecialObjects(Handle<Context> native_context) { ...@@ -2204,11 +2203,12 @@ void Genesis::InstallSpecialObjects(Handle<Context> native_context) {
factory->InternalizeUtf8String(FLAG_expose_debug_as); factory->InternalizeUtf8String(FLAG_expose_debug_as);
Handle<Object> global_proxy( Handle<Object> global_proxy(
debug->debug_context()->global_proxy(), isolate); debug->debug_context()->global_proxy(), isolate);
CHECK_NOT_EMPTY_HANDLE(isolate, JSObject::SetLocalPropertyIgnoreAttributes(
JSObject::SetLocalPropertyIgnoreAttributes( global, debug_string, global_proxy, DONT_ENUM);
global, debug_string, global_proxy, DONT_ENUM)); if (isolate->has_pending_exception()) return false;
} }
#endif #endif
return true;
} }
...@@ -2240,38 +2240,46 @@ void Genesis::ExtensionStates::set_state(RegisteredExtension* extension, ...@@ -2240,38 +2240,46 @@ void Genesis::ExtensionStates::set_state(RegisteredExtension* extension,
reinterpret_cast<void*>(static_cast<intptr_t>(state)); reinterpret_cast<void*>(static_cast<intptr_t>(state));
} }
bool Genesis::InstallExtensions(Handle<Context> native_context, bool Genesis::InstallExtensions(Handle<Context> native_context,
v8::ExtensionConfiguration* extensions) { v8::ExtensionConfiguration* extensions) {
Isolate* isolate = native_context->GetIsolate(); Isolate* isolate = native_context->GetIsolate();
ExtensionStates extension_states; // All extensions have state UNVISITED. ExtensionStates extension_states; // All extensions have state UNVISITED.
// Install auto extensions. return InstallAutoExtensions(isolate, &extension_states) &&
v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); (!FLAG_expose_free_buffer ||
while (current != NULL) { InstallExtension(isolate, "v8/free-buffer", &extension_states)) &&
if (current->extension()->auto_enable()) (!FLAG_expose_gc ||
InstallExtension(isolate, current, &extension_states); InstallExtension(isolate, "v8/gc", &extension_states)) &&
current = current->next(); (!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) { 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; return true;
} }
...@@ -2281,19 +2289,16 @@ bool Genesis::InstallExtensions(Handle<Context> native_context, ...@@ -2281,19 +2289,16 @@ bool Genesis::InstallExtensions(Handle<Context> native_context,
bool Genesis::InstallExtension(Isolate* isolate, bool Genesis::InstallExtension(Isolate* isolate,
const char* name, const char* name,
ExtensionStates* extension_states) { ExtensionStates* extension_states) {
v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); for (v8::RegisteredExtension* it = v8::RegisteredExtension::first_extension();
// Loop until we find the relevant extension it != NULL;
while (current != NULL) { it = it->next()) {
if (strcmp(name, current->extension()->name()) == 0) break; if (strcmp(name, it->extension()->name()) == 0) {
current = current->next(); return InstallExtension(isolate, it, extension_states);
} }
// Didn't find the extension; fail.
if (!Utils::ApiCheck(current != NULL,
"v8::Context::New()",
"Cannot find required extension")) {
return false;
} }
return InstallExtension(isolate, current, extension_states); return Utils::ApiCheck(false,
"v8::Context::New()",
"Cannot find required extension");
} }
......
...@@ -398,9 +398,7 @@ DEFINE_bool(enable_vldr_imm, false, ...@@ -398,9 +398,7 @@ DEFINE_bool(enable_vldr_imm, false,
// bootstrapper.cc // bootstrapper.cc
DEFINE_string(expose_natives_as, NULL, "expose natives in global object") DEFINE_string(expose_natives_as, NULL, "expose natives in global object")
DEFINE_string(expose_debug_as, NULL, "expose debug 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") DEFINE_bool(expose_free_buffer, false, "expose freeBuffer extension")
#endif
DEFINE_bool(expose_gc, false, "expose gc extension") DEFINE_bool(expose_gc, false, "expose gc extension")
DEFINE_string(expose_gc_as, NULL, DEFINE_string(expose_gc_as, NULL,
"expose gc extension under the specified name") "expose gc extension under the specified name")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment