OLD | NEW |
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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 if (!FLAG_builtins_in_stack_traces) { | 346 if (!FLAG_builtins_in_stack_traces) { |
347 if (frame->receiver()->IsJSBuiltinsObject() || | 347 if (frame->receiver()->IsJSBuiltinsObject() || |
348 (fun->IsBuiltin() && !fun->shared()->native())) { | 348 (fun->IsBuiltin() && !fun->shared()->native())) { |
349 return false; | 349 return false; |
350 } | 350 } |
351 } | 351 } |
352 return true; | 352 return true; |
353 } | 353 } |
354 | 354 |
355 | 355 |
356 Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object, | 356 Handle<JSArray> Isolate::CaptureSimpleStackTrace(Handle<JSObject> error_object, |
357 Handle<Object> caller) { | 357 Handle<Object> caller, |
358 // Get stack trace limit. | 358 int limit) { |
359 Handle<Object> error = Object::GetProperty( | |
360 this, js_builtins_object(), "$Error").ToHandleChecked(); | |
361 if (!error->IsJSObject()) return factory()->undefined_value(); | |
362 | |
363 Handle<String> stackTraceLimit = | |
364 factory()->InternalizeUtf8String("stackTraceLimit"); | |
365 ASSERT(!stackTraceLimit.is_null()); | |
366 Handle<Object> stack_trace_limit = | |
367 JSObject::GetDataProperty(Handle<JSObject>::cast(error), | |
368 stackTraceLimit); | |
369 if (!stack_trace_limit->IsNumber()) return factory()->undefined_value(); | |
370 int limit = FastD2IChecked(stack_trace_limit->Number()); | |
371 limit = Max(limit, 0); // Ensure that limit is not negative. | 359 limit = Max(limit, 0); // Ensure that limit is not negative. |
372 | |
373 int initial_size = Min(limit, 10); | 360 int initial_size = Min(limit, 10); |
374 Handle<FixedArray> elements = | 361 Handle<FixedArray> elements = |
375 factory()->NewFixedArrayWithHoles(initial_size * 4 + 1); | 362 factory()->NewFixedArrayWithHoles(initial_size * 4 + 1); |
376 | 363 |
377 // If the caller parameter is a function we skip frames until we're | 364 // If the caller parameter is a function we skip frames until we're |
378 // under it before starting to collect. | 365 // under it before starting to collect. |
379 bool seen_caller = !caller->IsJSFunction(); | 366 bool seen_caller = !caller->IsJSFunction(); |
380 // First element is reserved to store the number of sloppy frames. | 367 // First element is reserved to store the number of sloppy frames. |
381 int cursor = 1; | 368 int cursor = 1; |
382 int frames_seen = 0; | 369 int frames_seen = 0; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 elements->set(0, Smi::FromInt(sloppy_frames)); | 419 elements->set(0, Smi::FromInt(sloppy_frames)); |
433 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements); | 420 Handle<JSArray> result = factory()->NewJSArrayWithElements(elements); |
434 result->set_length(Smi::FromInt(cursor)); | 421 result->set_length(Smi::FromInt(cursor)); |
435 return result; | 422 return result; |
436 } | 423 } |
437 | 424 |
438 | 425 |
439 void Isolate::CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object) { | 426 void Isolate::CaptureAndSetDetailedStackTrace(Handle<JSObject> error_object) { |
440 if (capture_stack_trace_for_uncaught_exceptions_) { | 427 if (capture_stack_trace_for_uncaught_exceptions_) { |
441 // Capture stack trace for a detailed exception message. | 428 // Capture stack trace for a detailed exception message. |
442 Handle<Name> key = factory()->detailed_stack_trace_symbol(); | 429 Handle<String> key = factory()->hidden_stack_trace_string(); |
443 Handle<JSArray> stack_trace = CaptureCurrentStackTrace( | 430 Handle<JSArray> stack_trace = CaptureCurrentStackTrace( |
444 stack_trace_for_uncaught_exceptions_frame_limit_, | 431 stack_trace_for_uncaught_exceptions_frame_limit_, |
445 stack_trace_for_uncaught_exceptions_options_); | 432 stack_trace_for_uncaught_exceptions_options_); |
446 JSObject::SetProperty( | 433 JSObject::SetHiddenProperty(error_object, key, stack_trace); |
447 error_object, key, stack_trace, NONE, STRICT).Assert(); | |
448 } | 434 } |
449 } | 435 } |
450 | 436 |
451 | 437 |
452 void Isolate::CaptureAndSetSimpleStackTrace(Handle<JSObject> error_object, | |
453 Handle<Object> caller) { | |
454 // Capture stack trace for simple stack trace string formatting. | |
455 Handle<Name> key = factory()->stack_trace_symbol(); | |
456 Handle<Object> stack_trace = CaptureSimpleStackTrace(error_object, caller); | |
457 JSObject::SetProperty(error_object, key, stack_trace, NONE, STRICT).Assert(); | |
458 } | |
459 | |
460 | |
461 Handle<JSArray> Isolate::CaptureCurrentStackTrace( | 438 Handle<JSArray> Isolate::CaptureCurrentStackTrace( |
462 int frame_limit, StackTrace::StackTraceOptions options) { | 439 int frame_limit, StackTrace::StackTraceOptions options) { |
463 // Ensure no negative values. | 440 // Ensure no negative values. |
464 int limit = Max(frame_limit, 0); | 441 int limit = Max(frame_limit, 0); |
465 Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit); | 442 Handle<JSArray> stack_trace = factory()->NewJSArray(frame_limit); |
466 | 443 |
467 Handle<String> column_key = | 444 Handle<String> column_key = |
468 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("column")); | 445 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("column")); |
469 Handle<String> line_key = | 446 Handle<String> line_key = |
470 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("lineNumber")); | 447 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("lineNumber")); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 HandleScope scope(this); | 773 HandleScope scope(this); |
797 // At this point we cannot create an Error object using its javascript | 774 // At this point we cannot create an Error object using its javascript |
798 // constructor. Instead, we copy the pre-constructed boilerplate and | 775 // constructor. Instead, we copy the pre-constructed boilerplate and |
799 // attach the stack trace as a hidden property. | 776 // attach the stack trace as a hidden property. |
800 Handle<String> key = factory()->stack_overflow_string(); | 777 Handle<String> key = factory()->stack_overflow_string(); |
801 Handle<JSObject> boilerplate = Handle<JSObject>::cast( | 778 Handle<JSObject> boilerplate = Handle<JSObject>::cast( |
802 Object::GetProperty(js_builtins_object(), key).ToHandleChecked()); | 779 Object::GetProperty(js_builtins_object(), key).ToHandleChecked()); |
803 Handle<JSObject> exception = factory()->CopyJSObject(boilerplate); | 780 Handle<JSObject> exception = factory()->CopyJSObject(boilerplate); |
804 DoThrow(*exception, NULL); | 781 DoThrow(*exception, NULL); |
805 | 782 |
806 CaptureAndSetSimpleStackTrace(exception, factory()->undefined_value()); | 783 // Get stack trace limit. |
| 784 Handle<Object> error = Object::GetProperty( |
| 785 this, js_builtins_object(), "$Error").ToHandleChecked(); |
| 786 if (!error->IsJSObject()) return heap()->exception(); |
| 787 |
| 788 Handle<String> stackTraceLimit = |
| 789 factory()->InternalizeUtf8String("stackTraceLimit"); |
| 790 ASSERT(!stackTraceLimit.is_null()); |
| 791 Handle<Object> stack_trace_limit = |
| 792 JSObject::GetDataProperty(Handle<JSObject>::cast(error), |
| 793 stackTraceLimit); |
| 794 if (!stack_trace_limit->IsNumber()) return heap()->exception(); |
| 795 int limit = FastD2IChecked(stack_trace_limit->Number()); |
| 796 if (limit < 0) limit = 0; |
| 797 Handle<JSArray> stack_trace = CaptureSimpleStackTrace( |
| 798 exception, factory()->undefined_value(), limit); |
| 799 JSObject::SetHiddenProperty(exception, |
| 800 factory()->hidden_stack_trace_string(), |
| 801 stack_trace); |
807 return heap()->exception(); | 802 return heap()->exception(); |
808 } | 803 } |
809 | 804 |
810 | 805 |
811 Object* Isolate::TerminateExecution() { | 806 Object* Isolate::TerminateExecution() { |
812 DoThrow(heap_.termination_exception(), NULL); | 807 DoThrow(heap_.termination_exception(), NULL); |
813 return heap()->exception(); | 808 return heap()->exception(); |
814 } | 809 } |
815 | 810 |
816 | 811 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 location = &potential_computed_location; | 1047 location = &potential_computed_location; |
1053 } | 1048 } |
1054 // It's not safe to try to make message objects or collect stack traces | 1049 // It's not safe to try to make message objects or collect stack traces |
1055 // while the bootstrapper is active since the infrastructure may not have | 1050 // while the bootstrapper is active since the infrastructure may not have |
1056 // been properly initialized. | 1051 // been properly initialized. |
1057 if (!bootstrapping) { | 1052 if (!bootstrapping) { |
1058 Handle<JSArray> stack_trace_object; | 1053 Handle<JSArray> stack_trace_object; |
1059 if (capture_stack_trace_for_uncaught_exceptions_) { | 1054 if (capture_stack_trace_for_uncaught_exceptions_) { |
1060 if (IsErrorObject(exception_handle)) { | 1055 if (IsErrorObject(exception_handle)) { |
1061 // We fetch the stack trace that corresponds to this error object. | 1056 // We fetch the stack trace that corresponds to this error object. |
1062 Handle<Name> key = factory()->detailed_stack_trace_symbol(); | 1057 Handle<String> key = factory()->hidden_stack_trace_string(); |
1063 // Look up as own property. If the lookup fails, the exception is | 1058 Object* stack_property = |
1064 // probably not a valid Error object. In that case, we fall through | 1059 JSObject::cast(*exception_handle)->GetHiddenProperty(key); |
1065 // and capture the stack trace at this throw site. | 1060 // Property lookup may have failed. In this case it's probably not |
1066 LookupIterator lookup( | 1061 // a valid Error object. |
1067 exception_handle, key, LookupIterator::CHECK_OWN_REAL); | 1062 if (stack_property->IsJSArray()) { |
1068 Handle<Object> stack_trace_property; | 1063 stack_trace_object = Handle<JSArray>(JSArray::cast(stack_property)); |
1069 if (Object::GetProperty(&lookup).ToHandle(&stack_trace_property) && | |
1070 stack_trace_property->IsJSArray()) { | |
1071 stack_trace_object = Handle<JSArray>::cast(stack_trace_property); | |
1072 } | 1064 } |
1073 } | 1065 } |
1074 if (stack_trace_object.is_null()) { | 1066 if (stack_trace_object.is_null()) { |
1075 // Not an error object, we capture at throw site. | 1067 // Not an error object, we capture at throw site. |
1076 stack_trace_object = CaptureCurrentStackTrace( | 1068 stack_trace_object = CaptureCurrentStackTrace( |
1077 stack_trace_for_uncaught_exceptions_frame_limit_, | 1069 stack_trace_for_uncaught_exceptions_frame_limit_, |
1078 stack_trace_for_uncaught_exceptions_options_); | 1070 stack_trace_for_uncaught_exceptions_options_); |
1079 } | 1071 } |
1080 } | 1072 } |
1081 | 1073 |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2373 // The simulator uses a separate JS stack. | 2365 // The simulator uses a separate JS stack. |
2374 Address jssp_address = Simulator::current(isolate_)->get_sp(); | 2366 Address jssp_address = Simulator::current(isolate_)->get_sp(); |
2375 uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address); | 2367 uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address); |
2376 if (jssp < stack_guard->real_jslimit()) return true; | 2368 if (jssp < stack_guard->real_jslimit()) return true; |
2377 #endif // USE_SIMULATOR | 2369 #endif // USE_SIMULATOR |
2378 return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit(); | 2370 return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit(); |
2379 } | 2371 } |
2380 | 2372 |
2381 | 2373 |
2382 } } // namespace v8::internal | 2374 } } // namespace v8::internal |
OLD | NEW |