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