Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: src/isolate.cc

Issue 1309673003: Small MessageLocation related refactoring. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: keep old default values Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/isolate.h ('k') | src/messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/isolate.h" 5 #include "src/isolate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <fstream> // NOLINT(readability/streams) 9 #include <fstream> // NOLINT(readability/streams)
10 #include <sstream> 10 #include <sstream>
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 986
987 thread_local_top()->rethrowing_message_ = false; 987 thread_local_top()->rethrowing_message_ = false;
988 988
989 // Notify debugger of exception. 989 // Notify debugger of exception.
990 if (is_catchable_by_javascript(exception)) { 990 if (is_catchable_by_javascript(exception)) {
991 debug()->OnThrow(exception_handle); 991 debug()->OnThrow(exception_handle);
992 } 992 }
993 993
994 // Generate the message if required. 994 // Generate the message if required.
995 if (requires_message && !rethrowing_message) { 995 if (requires_message && !rethrowing_message) {
996 MessageLocation potential_computed_location; 996 MessageLocation computed_location;
997 if (location == NULL) { 997 // If no location was specified we try to use a computed one instead.
998 // If no location was specified we use a computed one instead. 998 if (location == NULL && ComputeLocation(&computed_location)) {
999 ComputeLocation(&potential_computed_location); 999 location = &computed_location;
1000 location = &potential_computed_location;
1001 } 1000 }
1002 1001
1003 if (bootstrapper()->IsActive()) { 1002 if (bootstrapper()->IsActive()) {
1004 // It's not safe to try to make message objects or collect stack traces 1003 // It's not safe to try to make message objects or collect stack traces
1005 // while the bootstrapper is active since the infrastructure may not have 1004 // while the bootstrapper is active since the infrastructure may not have
1006 // been properly initialized. 1005 // been properly initialized.
1007 ReportBootstrappingException(exception_handle, location); 1006 ReportBootstrappingException(exception_handle, location);
1008 } else { 1007 } else {
1009 Handle<Object> message_obj = CreateMessage(exception_handle, location); 1008 Handle<Object> message_obj = CreateMessage(exception_handle, location);
1010 thread_local_top()->pending_message_obj_ = *message_obj; 1009 thread_local_top()->pending_message_obj_ = *message_obj;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 Handle<String> line = 1250 Handle<String> line =
1252 Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level); 1251 Execution::GetStackTraceLine(recv, fun, pos_obj, is_top_level);
1253 if (line->length() > 0) { 1252 if (line->length() > 0) {
1254 line->PrintOn(out); 1253 line->PrintOn(out);
1255 PrintF(out, "\n"); 1254 PrintF(out, "\n");
1256 } 1255 }
1257 } 1256 }
1258 } 1257 }
1259 1258
1260 1259
1261 void Isolate::ComputeLocation(MessageLocation* target) { 1260 bool Isolate::ComputeLocation(MessageLocation* target) {
1262 *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1);
1263 StackTraceFrameIterator it(this); 1261 StackTraceFrameIterator it(this);
1264 if (!it.done()) { 1262 if (!it.done()) {
1265 JavaScriptFrame* frame = it.frame(); 1263 JavaScriptFrame* frame = it.frame();
1266 JSFunction* fun = frame->function(); 1264 JSFunction* fun = frame->function();
1267 Object* script = fun->shared()->script(); 1265 Object* script = fun->shared()->script();
1268 if (script->IsScript() && 1266 if (script->IsScript() &&
1269 !(Script::cast(script)->source()->IsUndefined())) { 1267 !(Script::cast(script)->source()->IsUndefined())) {
1270 int pos = frame->LookupCode()->SourcePosition(frame->pc()); 1268 int pos = frame->LookupCode()->SourcePosition(frame->pc());
1271 // Compute the location from the function and the reloc info. 1269 // Compute the location from the function and the reloc info.
1272 Handle<Script> casted_script(Script::cast(script)); 1270 Handle<Script> casted_script(Script::cast(script));
1273 *target = MessageLocation(casted_script, pos, pos + 1, handle(fun)); 1271 *target = MessageLocation(casted_script, pos, pos + 1, handle(fun));
1272 return true;
1274 } 1273 }
1275 } 1274 }
1275 return false;
1276 } 1276 }
1277 1277
1278 1278
1279 bool Isolate::ComputeLocationFromException(MessageLocation* target, 1279 bool Isolate::ComputeLocationFromException(MessageLocation* target,
1280 Handle<Object> exception) { 1280 Handle<Object> exception) {
1281 if (!exception->IsJSObject()) return false; 1281 if (!exception->IsJSObject()) return false;
1282 1282
1283 Handle<Name> start_pos_symbol = factory()->error_start_pos_symbol(); 1283 Handle<Name> start_pos_symbol = factory()->error_start_pos_symbol();
1284 Handle<Object> start_pos = JSReceiver::GetDataProperty( 1284 Handle<Object> start_pos = JSReceiver::GetDataProperty(
1285 Handle<JSObject>::cast(exception), start_pos_symbol); 1285 Handle<JSObject>::cast(exception), start_pos_symbol);
(...skipping 12 matching lines...) Expand all
1298 if (!script->IsScript()) return false; 1298 if (!script->IsScript()) return false;
1299 1299
1300 Handle<Script> cast_script(Script::cast(*script)); 1300 Handle<Script> cast_script(Script::cast(*script));
1301 *target = MessageLocation(cast_script, start_pos_value, end_pos_value); 1301 *target = MessageLocation(cast_script, start_pos_value, end_pos_value);
1302 return true; 1302 return true;
1303 } 1303 }
1304 1304
1305 1305
1306 bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target, 1306 bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
1307 Handle<Object> exception) { 1307 Handle<Object> exception) {
1308 *target = MessageLocation(Handle<Script>(heap_.empty_script()), -1, -1);
1309
1310 if (!exception->IsJSObject()) return false; 1308 if (!exception->IsJSObject()) return false;
1311 Handle<Name> key = factory()->stack_trace_symbol(); 1309 Handle<Name> key = factory()->stack_trace_symbol();
1312 Handle<Object> property = 1310 Handle<Object> property =
1313 JSReceiver::GetDataProperty(Handle<JSObject>::cast(exception), key); 1311 JSReceiver::GetDataProperty(Handle<JSObject>::cast(exception), key);
1314 if (!property->IsJSArray()) return false; 1312 if (!property->IsJSArray()) return false;
1315 Handle<JSArray> simple_stack_trace = Handle<JSArray>::cast(property); 1313 Handle<JSArray> simple_stack_trace = Handle<JSArray>::cast(property);
1316 1314
1317 Handle<FixedArray> elements(FixedArray::cast(simple_stack_trace->elements())); 1315 Handle<FixedArray> elements(FixedArray::cast(simple_stack_trace->elements()));
1318 int elements_limit = Smi::cast(simple_stack_trace->length())->value(); 1316 int elements_limit = Smi::cast(simple_stack_trace->length())->value();
1319 1317
(...skipping 29 matching lines...) Expand all
1349 return true; 1347 return true;
1350 } 1348 }
1351 } 1349 }
1352 return false; 1350 return false;
1353 } 1351 }
1354 1352
1355 1353
1356 Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception, 1354 Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception,
1357 MessageLocation* location) { 1355 MessageLocation* location) {
1358 Handle<JSArray> stack_trace_object; 1356 Handle<JSArray> stack_trace_object;
1359 MessageLocation potential_computed_location;
1360 if (capture_stack_trace_for_uncaught_exceptions_) { 1357 if (capture_stack_trace_for_uncaught_exceptions_) {
1361 if (IsErrorObject(exception)) { 1358 if (IsErrorObject(exception)) {
1362 // We fetch the stack trace that corresponds to this error object. 1359 // We fetch the stack trace that corresponds to this error object.
1363 // If the lookup fails, the exception is probably not a valid Error 1360 // If the lookup fails, the exception is probably not a valid Error
1364 // object. In that case, we fall through and capture the stack trace 1361 // object. In that case, we fall through and capture the stack trace
1365 // at this throw site. 1362 // at this throw site.
1366 stack_trace_object = 1363 stack_trace_object =
1367 GetDetailedStackTrace(Handle<JSObject>::cast(exception)); 1364 GetDetailedStackTrace(Handle<JSObject>::cast(exception));
1368 } 1365 }
1369 if (stack_trace_object.is_null()) { 1366 if (stack_trace_object.is_null()) {
1370 // Not an error object, we capture stack and location at throw site. 1367 // Not an error object, we capture stack and location at throw site.
1371 stack_trace_object = CaptureCurrentStackTrace( 1368 stack_trace_object = CaptureCurrentStackTrace(
1372 stack_trace_for_uncaught_exceptions_frame_limit_, 1369 stack_trace_for_uncaught_exceptions_frame_limit_,
1373 stack_trace_for_uncaught_exceptions_options_); 1370 stack_trace_for_uncaught_exceptions_options_);
1374 } 1371 }
1375 } 1372 }
1376 if (!location) { 1373 MessageLocation computed_location;
1377 if (!ComputeLocationFromException(&potential_computed_location, 1374 if (location == NULL &&
1378 exception)) { 1375 (ComputeLocationFromException(&computed_location, exception) ||
1379 if (!ComputeLocationFromStackTrace(&potential_computed_location, 1376 ComputeLocationFromStackTrace(&computed_location, exception) ||
1380 exception)) { 1377 ComputeLocation(&computed_location))) {
1381 ComputeLocation(&potential_computed_location); 1378 location = &computed_location;
1382 }
1383 }
1384 location = &potential_computed_location;
1385 } 1379 }
1386 1380
1387 return MessageHandler::MakeMessageObject( 1381 return MessageHandler::MakeMessageObject(
1388 this, MessageTemplate::kUncaughtException, location, exception, 1382 this, MessageTemplate::kUncaughtException, location, exception,
1389 stack_trace_object); 1383 stack_trace_object);
1390 } 1384 }
1391 1385
1392 1386
1393 bool Isolate::IsJavaScriptHandlerOnTop(Object* exception) { 1387 bool Isolate::IsJavaScriptHandlerOnTop(Object* exception) {
1394 DCHECK_NE(heap()->the_hole_value(), exception); 1388 DCHECK_NE(heap()->the_hole_value(), exception);
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after
2810 // Then check whether this scope intercepts. 2804 // Then check whether this scope intercepts.
2811 if ((flag & intercept_mask_)) { 2805 if ((flag & intercept_mask_)) {
2812 intercepted_flags_ |= flag; 2806 intercepted_flags_ |= flag;
2813 return true; 2807 return true;
2814 } 2808 }
2815 return false; 2809 return false;
2816 } 2810 }
2817 2811
2818 } // namespace internal 2812 } // namespace internal
2819 } // namespace v8 2813 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698