Reviewers: Mads Ager, Description: Fix crash during error reporting during bootstrapping. Instead of crashing or reporting a fatal v8 error if an error occurs during context initialization we now survive and return an empty handle.
Please review this at http://codereview.chromium.org/194070 Affected files: M src/api.cc M src/factory.cc M src/top.cc Index: src/api.cc diff --git a/src/api.cc b/src/api.cc index 1128d3e0222ff72bcb585ce5f92a5ddbdafa1d00..052e875169dca83423298c5e63d84c2e747ea92d 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2672,9 +2672,7 @@ Persistent<Context> v8::Context::New( } // Leave V8. - if (!ApiCheck(!env.is_null(), - "v8::Context::New()", - "Could not initialize environment")) + if (env.is_null()) return Persistent<Context>(); return Persistent<Context>(Utils::ToLocal(env)); } Index: src/factory.cc diff --git a/src/factory.cc b/src/factory.cc index bb6987bb8cc36abecbe03c14c84fa53363f19a9c..d91b2662a169bfc4304c0006bdd7ba27949b1652 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -401,10 +401,12 @@ Handle<Object> Factory::NewError(const char* maker, const char* type, Handle<JSArray> args) { Handle<String> make_str = Factory::LookupAsciiSymbol(maker); - Handle<JSFunction> fun = - Handle<JSFunction>( - JSFunction::cast( - Top::builtins()->GetProperty(*make_str))); + Handle<Object> fun_obj(Top::builtins()->GetProperty(*make_str)); + // If the builtins haven't been properly configured yet this error + // constructor may not have been defined. Bail out. + if (!fun_obj->IsJSFunction()) + return Factory::undefined_value(); + Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); Handle<Object> type_obj = Factory::LookupAsciiSymbol(type); Object** argv[2] = { type_obj.location(), Handle<Object>::cast(args).location() }; Index: src/top.cc diff --git a/src/top.cc b/src/top.cc index 5c22bcf3cd0ef9037a1c02c14607c206040d5aa1..039c29268f490ffa5a2c3b3d0c767ca3cccddb44 100644 --- a/src/top.cc +++ b/src/top.cc @@ -690,12 +690,17 @@ void Top::ComputeLocation(MessageLocation* target) { void Top::ReportUncaughtException(Handle<Object> exception, MessageLocation* location, Handle<String> stack_trace) { - Handle<Object> message = - MessageHandler::MakeMessageObject("uncaught_exception", - location, - HandleVector<Object>(&exception, 1), - stack_trace); - + Handle<Object> message; + if (!Bootstrapper::IsActive()) { + // It's not safe to try to make message objects while the bootstrapper + // is active since the infrastructure may not have been properly + // initialized. + message = + MessageHandler::MakeMessageObject("uncaught_exception", + location, + HandleVector<Object>(&exception, 1), + stack_trace); + } // Report the uncaught exception. MessageHandler::ReportMessage(location, message); } @@ -769,10 +774,15 @@ void Top::DoThrow(Object* exception, ComputeLocation(&potential_computed_location); location = &potential_computed_location; } - Handle<String> stack_trace; - if (FLAG_trace_exception) stack_trace = StackTrace(); - message_obj = MessageHandler::MakeMessageObject("uncaught_exception", - location, HandleVector<Object>(&exception_handle, 1), stack_trace); + if (!Bootstrapper::IsActive()) { + // It's not safe to try to make message objects or collect stack + // traces while the bootstrapper is active since the infrastructure + // may not have been properly initialized. + Handle<String> stack_trace; + if (FLAG_trace_exception) stack_trace = StackTrace(); + message_obj = MessageHandler::MakeMessageObject("uncaught_exception", + location, HandleVector<Object>(&exception_handle, 1), stack_trace); + } } // Save the message for reporting if the the exception remains uncaught. --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
