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.

Review URL: http://codereview.chromium.org/194070


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2867 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 39a3c9c6
......@@ -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));
}
......
......@@ -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() };
......
......@@ -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.
......
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