Commit 1cdcae94 authored by yangguo's avatar yangguo Committed by Commit bot

Small MessageLocation related refactoring.

R=cbruni@chromium.org

Review URL: https://codereview.chromium.org/1309673003

Cr-Commit-Position: refs/heads/master@{#30305}
parent d6ef00b9
......@@ -993,11 +993,10 @@ Object* Isolate::Throw(Object* exception, MessageLocation* location) {
// Generate the message if required.
if (requires_message && !rethrowing_message) {
MessageLocation potential_computed_location;
if (location == NULL) {
// If no location was specified we use a computed one instead.
ComputeLocation(&potential_computed_location);
location = &potential_computed_location;
MessageLocation computed_location;
// If no location was specified we try to use a computed one instead.
if (location == NULL && ComputeLocation(&computed_location)) {
location = &computed_location;
}
if (bootstrapper()->IsActive()) {
......@@ -1258,8 +1257,7 @@ void Isolate::PrintCurrentStackTrace(FILE* out) {
}
void Isolate::ComputeLocation(MessageLocation* target) {
*target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1);
bool Isolate::ComputeLocation(MessageLocation* target) {
StackTraceFrameIterator it(this);
if (!it.done()) {
JavaScriptFrame* frame = it.frame();
......@@ -1271,8 +1269,10 @@ void Isolate::ComputeLocation(MessageLocation* target) {
// Compute the location from the function and the reloc info.
Handle<Script> casted_script(Script::cast(script));
*target = MessageLocation(casted_script, pos, pos + 1, handle(fun));
return true;
}
}
return false;
}
......@@ -1305,8 +1305,6 @@ bool Isolate::ComputeLocationFromException(MessageLocation* target,
bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
Handle<Object> exception) {
*target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1);
if (!exception->IsJSObject()) return false;
Handle<Name> key = factory()->stack_trace_symbol();
Handle<Object> property =
......@@ -1356,7 +1354,6 @@ bool Isolate::IsErrorObject(Handle<Object> obj) {
Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception,
MessageLocation* location) {
Handle<JSArray> stack_trace_object;
MessageLocation potential_computed_location;
if (capture_stack_trace_for_uncaught_exceptions_) {
if (IsErrorObject(exception)) {
// We fetch the stack trace that corresponds to this error object.
......@@ -1373,15 +1370,12 @@ Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception,
stack_trace_for_uncaught_exceptions_options_);
}
}
if (!location) {
if (!ComputeLocationFromException(&potential_computed_location,
exception)) {
if (!ComputeLocationFromStackTrace(&potential_computed_location,
exception)) {
ComputeLocation(&potential_computed_location);
}
}
location = &potential_computed_location;
MessageLocation computed_location;
if (location == NULL &&
(ComputeLocationFromException(&computed_location, exception) ||
ComputeLocationFromStackTrace(&computed_location, exception) ||
ComputeLocation(&computed_location))) {
location = &computed_location;
}
return MessageHandler::MakeMessageObject(
......
......@@ -772,7 +772,7 @@ class Isolate {
// Attempts to compute the current source location, storing the
// result in the target out parameter.
void ComputeLocation(MessageLocation* target);
bool ComputeLocation(MessageLocation* target);
bool ComputeLocationFromException(MessageLocation* target,
Handle<Object> exception);
bool ComputeLocationFromStackTrace(MessageLocation* target,
......
......@@ -33,17 +33,20 @@ void MessageHandler::DefaultMessageReport(Isolate* isolate,
Handle<JSMessageObject> MessageHandler::MakeMessageObject(
Isolate* isolate, MessageTemplate::Template message, MessageLocation* loc,
Handle<Object> argument, Handle<JSArray> stack_frames) {
Isolate* isolate, MessageTemplate::Template message,
MessageLocation* location, Handle<Object> argument,
Handle<JSArray> stack_frames) {
Factory* factory = isolate->factory();
int start = 0;
int end = 0;
int start = -1;
int end = -1;
Handle<Object> script_handle = factory->undefined_value();
if (loc) {
start = loc->start_pos();
end = loc->end_pos();
script_handle = Script::GetWrapper(loc->script());
if (location != NULL) {
start = location->start_pos();
end = location->end_pos();
script_handle = Script::GetWrapper(location->script());
} else {
script_handle = Script::GetWrapper(isolate->factory()->empty_script());
}
Handle<Object> stack_frames_handle = stack_frames.is_null()
......
......@@ -430,8 +430,9 @@ class MessageHandler {
public:
// Returns a message object for the API to use.
static Handle<JSMessageObject> MakeMessageObject(
Isolate* isolate, MessageTemplate::Template type, MessageLocation* loc,
Handle<Object> argument, Handle<JSArray> stack_frames);
Isolate* isolate, MessageTemplate::Template type,
MessageLocation* location, Handle<Object> argument,
Handle<JSArray> stack_frames);
// Report a formatted message (needs JS allocation).
static void ReportMessage(Isolate* isolate, MessageLocation* loc,
......
......@@ -256,8 +256,9 @@ RUNTIME_FUNCTION(Runtime_RenderCallSite) {
HandleScope scope(isolate);
DCHECK(args.length() == 0);
MessageLocation location;
isolate->ComputeLocation(&location);
if (location.start_pos() == -1) return isolate->heap()->empty_string();
if (!isolate->ComputeLocation(&location)) {
return isolate->heap()->empty_string();
}
Zone zone;
base::SmartPointer<ParseInfo> info(
......
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