| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 v8::TryCatch* ThreadLocalTop::TryCatchHandler() { | 65 v8::TryCatch* ThreadLocalTop::TryCatchHandler() { |
| 66 return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); | 66 return TRY_CATCH_FROM_ADDRESS(try_catch_handler_address()); |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 void ThreadLocalTop::Initialize() { | 70 void ThreadLocalTop::Initialize() { |
| 71 c_entry_fp_ = 0; | 71 c_entry_fp_ = 0; |
| 72 handler_ = 0; | 72 handler_ = 0; |
| 73 #ifdef USE_SIMULATOR | 73 #ifdef USE_SIMULATOR |
| 74 #ifdef V8_TARGET_ARCH_ARM | 74 #ifdef V8_TARGET_ARCH_ARM |
| 75 simulator_ = assembler::arm::Simulator::current(); | 75 simulator_ = Simulator::current(); |
| 76 #elif V8_TARGET_ARCH_MIPS | 76 #elif V8_TARGET_ARCH_MIPS |
| 77 simulator_ = assembler::mips::Simulator::current(); | 77 simulator_ = assembler::mips::Simulator::current(); |
| 78 #endif | 78 #endif |
| 79 #endif | 79 #endif |
| 80 #ifdef ENABLE_LOGGING_AND_PROFILING | 80 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 81 js_entry_sp_ = NULL; | 81 js_entry_sp_ = NULL; |
| 82 external_callback_ = NULL; | 82 external_callback_ = NULL; |
| 83 #endif | 83 #endif |
| 84 #ifdef ENABLE_VMSTATE_TRACKING | 84 #ifdef ENABLE_VMSTATE_TRACKING |
| 85 current_vm_state_ = EXTERNAL; | 85 current_vm_state_ = EXTERNAL; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 | 375 |
| 376 | 376 |
| 377 Handle<JSArray> Top::CaptureCurrentStackTrace( | 377 Handle<JSArray> Top::CaptureCurrentStackTrace( |
| 378 int frame_limit, StackTrace::StackTraceOptions options) { | 378 int frame_limit, StackTrace::StackTraceOptions options) { |
| 379 // Ensure no negative values. | 379 // Ensure no negative values. |
| 380 int limit = Max(frame_limit, 0); | 380 int limit = Max(frame_limit, 0); |
| 381 Handle<JSArray> stack_trace = Factory::NewJSArray(frame_limit); | 381 Handle<JSArray> stack_trace = Factory::NewJSArray(frame_limit); |
| 382 | 382 |
| 383 Handle<String> column_key = Factory::LookupAsciiSymbol("column"); | 383 Handle<String> column_key = Factory::LookupAsciiSymbol("column"); |
| 384 Handle<String> line_key = Factory::LookupAsciiSymbol("lineNumber"); | 384 Handle<String> line_key = Factory::LookupAsciiSymbol("lineNumber"); |
| 385 Handle<String> script_key = Factory::LookupAsciiSymbol("scriptName"); | 385 Handle<String> script_key = Factory::LookupAsciiSymbol("scriptName"); |
| 386 Handle<String> name_or_source_url_key = | 386 Handle<String> name_or_source_url_key = |
| 387 Factory::LookupAsciiSymbol("nameOrSourceURL"); | 387 Factory::LookupAsciiSymbol("nameOrSourceURL"); |
| 388 Handle<String> script_name_or_source_url_key = | 388 Handle<String> script_name_or_source_url_key = |
| 389 Factory::LookupAsciiSymbol("scriptNameOrSourceURL"); | 389 Factory::LookupAsciiSymbol("scriptNameOrSourceURL"); |
| 390 Handle<String> function_key = Factory::LookupAsciiSymbol("functionName"); | 390 Handle<String> function_key = Factory::LookupAsciiSymbol("functionName"); |
| 391 Handle<String> eval_key = Factory::LookupAsciiSymbol("isEval"); | 391 Handle<String> eval_key = Factory::LookupAsciiSymbol("isEval"); |
| 392 Handle<String> constructor_key = Factory::LookupAsciiSymbol("isConstructor"); | 392 Handle<String> constructor_key = Factory::LookupAsciiSymbol("isConstructor"); |
| 393 | 393 |
| 394 StackTraceFrameIterator it; | 394 StackTraceFrameIterator it; |
| 395 int frames_seen = 0; | 395 int frames_seen = 0; |
| 396 while (!it.done() && (frames_seen < limit)) { | 396 while (!it.done() && (frames_seen < limit)) { |
| 397 JavaScriptFrame* frame = it.frame(); | 397 JavaScriptFrame* frame = it.frame(); |
| 398 | 398 |
| 399 List<FrameSummary> frames(3); // Max 2 levels of inlining. | 399 List<FrameSummary> frames(3); // Max 2 levels of inlining. |
| 400 frame->Summarize(&frames); | 400 frame->Summarize(&frames); |
| 401 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { | 401 for (int i = frames.length() - 1; i >= 0 && frames_seen < limit; i--) { |
| 402 // Create a JSObject to hold the information for the StackFrame. | 402 // Create a JSObject to hold the information for the StackFrame. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 414 if (options & StackTrace::kColumnOffset && relative_line_number >= 0) { | 414 if (options & StackTrace::kColumnOffset && relative_line_number >= 0) { |
| 415 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); | 415 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
| 416 int start = (relative_line_number == 0) ? 0 : | 416 int start = (relative_line_number == 0) ? 0 : |
| 417 Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1; | 417 Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1; |
| 418 int column_offset = position - start; | 418 int column_offset = position - start; |
| 419 if (relative_line_number == 0) { | 419 if (relative_line_number == 0) { |
| 420 // For the case where the code is on the same line as the script | 420 // For the case where the code is on the same line as the script |
| 421 // tag. | 421 // tag. |
| 422 column_offset += script->column_offset()->value(); | 422 column_offset += script->column_offset()->value(); |
| 423 } | 423 } |
| 424 SetProperty(stackFrame, column_key, | 424 SetLocalPropertyNoThrow(stackFrame, column_key, |
| 425 Handle<Smi>(Smi::FromInt(column_offset + 1)), NONE); | 425 Handle<Smi>(Smi::FromInt(column_offset + 1))); |
| 426 } | 426 } |
| 427 SetProperty(stackFrame, line_key, | 427 SetLocalPropertyNoThrow(stackFrame, line_key, |
| 428 Handle<Smi>(Smi::FromInt(line_number + 1)), NONE); | 428 Handle<Smi>(Smi::FromInt(line_number + 1))); |
| 429 } | 429 } |
| 430 | 430 |
| 431 if (options & StackTrace::kScriptName) { | 431 if (options & StackTrace::kScriptName) { |
| 432 Handle<Object> script_name(script->name()); | 432 Handle<Object> script_name(script->name()); |
| 433 SetProperty(stackFrame, script_key, script_name, NONE); | 433 SetLocalPropertyNoThrow(stackFrame, script_key, script_name); |
| 434 } | 434 } |
| 435 | 435 |
| 436 if (options & StackTrace::kScriptNameOrSourceURL) { | 436 if (options & StackTrace::kScriptNameOrSourceURL) { |
| 437 Handle<Object> script_name(script->name()); | 437 Handle<Object> script_name(script->name()); |
| 438 Handle<JSValue> script_wrapper = GetScriptWrapper(script); | 438 Handle<JSValue> script_wrapper = GetScriptWrapper(script); |
| 439 Handle<Object> property = GetProperty(script_wrapper, | 439 Handle<Object> property = GetProperty(script_wrapper, |
| 440 name_or_source_url_key); | 440 name_or_source_url_key); |
| 441 ASSERT(property->IsJSFunction()); | 441 ASSERT(property->IsJSFunction()); |
| 442 Handle<JSFunction> method = Handle<JSFunction>::cast(property); | 442 Handle<JSFunction> method = Handle<JSFunction>::cast(property); |
| 443 bool caught_exception; | 443 bool caught_exception; |
| 444 Handle<Object> result = Execution::TryCall(method, script_wrapper, 0, | 444 Handle<Object> result = Execution::TryCall(method, script_wrapper, 0, |
| 445 NULL, &caught_exception); | 445 NULL, &caught_exception); |
| 446 if (caught_exception) { | 446 if (caught_exception) { |
| 447 result = Factory::undefined_value(); | 447 result = Factory::undefined_value(); |
| 448 } | 448 } |
| 449 SetProperty(stackFrame, script_name_or_source_url_key, result, NONE); | 449 SetLocalPropertyNoThrow(stackFrame, script_name_or_source_url_key, |
| 450 result); |
| 450 } | 451 } |
| 451 | 452 |
| 452 if (options & StackTrace::kFunctionName) { | 453 if (options & StackTrace::kFunctionName) { |
| 453 Handle<Object> fun_name(fun->shared()->name()); | 454 Handle<Object> fun_name(fun->shared()->name()); |
| 454 if (fun_name->ToBoolean()->IsFalse()) { | 455 if (fun_name->ToBoolean()->IsFalse()) { |
| 455 fun_name = Handle<Object>(fun->shared()->inferred_name()); | 456 fun_name = Handle<Object>(fun->shared()->inferred_name()); |
| 456 } | 457 } |
| 457 SetProperty(stackFrame, function_key, fun_name, NONE); | 458 SetLocalPropertyNoThrow(stackFrame, function_key, fun_name); |
| 458 } | 459 } |
| 459 | 460 |
| 460 if (options & StackTrace::kIsEval) { | 461 if (options & StackTrace::kIsEval) { |
| 461 int type = Smi::cast(script->compilation_type())->value(); | 462 int type = Smi::cast(script->compilation_type())->value(); |
| 462 Handle<Object> is_eval = (type == Script::COMPILATION_TYPE_EVAL) ? | 463 Handle<Object> is_eval = (type == Script::COMPILATION_TYPE_EVAL) ? |
| 463 Factory::true_value() : Factory::false_value(); | 464 Factory::true_value() : Factory::false_value(); |
| 464 SetProperty(stackFrame, eval_key, is_eval, NONE); | 465 SetLocalPropertyNoThrow(stackFrame, eval_key, is_eval); |
| 465 } | 466 } |
| 466 | 467 |
| 467 if (options & StackTrace::kIsConstructor) { | 468 if (options & StackTrace::kIsConstructor) { |
| 468 Handle<Object> is_constructor = (frames[i].is_constructor()) ? | 469 Handle<Object> is_constructor = (frames[i].is_constructor()) ? |
| 469 Factory::true_value() : Factory::false_value(); | 470 Factory::true_value() : Factory::false_value(); |
| 470 SetProperty(stackFrame, constructor_key, is_constructor, NONE); | 471 SetLocalPropertyNoThrow(stackFrame, constructor_key, is_constructor); |
| 471 } | 472 } |
| 472 | 473 |
| 473 FixedArray::cast(stack_trace->elements())->set(frames_seen, *stackFrame); | 474 FixedArray::cast(stack_trace->elements())->set(frames_seen, *stackFrame); |
| 474 frames_seen++; | 475 frames_seen++; |
| 475 } | 476 } |
| 476 it.Advance(); | 477 it.Advance(); |
| 477 } | 478 } |
| 478 | 479 |
| 479 stack_trace->set_length(Smi::FromInt(frames_seen)); | 480 stack_trace->set_length(Smi::FromInt(frames_seen)); |
| 480 return stack_trace; | 481 return stack_trace; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 !(Script::cast(script)->source()->IsUndefined())) { | 800 !(Script::cast(script)->source()->IsUndefined())) { |
| 800 int pos = frame->code()->SourcePosition(frame->pc()); | 801 int pos = frame->code()->SourcePosition(frame->pc()); |
| 801 // Compute the location from the function and the reloc info. | 802 // Compute the location from the function and the reloc info. |
| 802 Handle<Script> casted_script(Script::cast(script)); | 803 Handle<Script> casted_script(Script::cast(script)); |
| 803 *target = MessageLocation(casted_script, pos, pos + 1); | 804 *target = MessageLocation(casted_script, pos, pos + 1); |
| 804 } | 805 } |
| 805 } | 806 } |
| 806 } | 807 } |
| 807 | 808 |
| 808 | 809 |
| 809 bool Top::ShouldReturnException(bool* is_caught_externally, | 810 bool Top::ShouldReportException(bool* is_caught_externally, |
| 810 bool catchable_by_javascript) { | 811 bool catchable_by_javascript) { |
| 811 // Find the top-most try-catch handler. | 812 // Find the top-most try-catch handler. |
| 812 StackHandler* handler = | 813 StackHandler* handler = |
| 813 StackHandler::FromAddress(Top::handler(Top::GetCurrentThread())); | 814 StackHandler::FromAddress(Top::handler(Top::GetCurrentThread())); |
| 814 while (handler != NULL && !handler->is_try_catch()) { | 815 while (handler != NULL && !handler->is_try_catch()) { |
| 815 handler = handler->next(); | 816 handler = handler->next(); |
| 816 } | 817 } |
| 817 | 818 |
| 818 // Get the address of the external handler so we can compare the address to | 819 // Get the address of the external handler so we can compare the address to |
| 819 // determine which one is closer to the top of the stack. | 820 // determine which one is closer to the top of the stack. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 840 MessageLocation* location, | 841 MessageLocation* location, |
| 841 const char* message) { | 842 const char* message) { |
| 842 ASSERT(!has_pending_exception()); | 843 ASSERT(!has_pending_exception()); |
| 843 | 844 |
| 844 HandleScope scope; | 845 HandleScope scope; |
| 845 Object* exception_object = Smi::FromInt(0); | 846 Object* exception_object = Smi::FromInt(0); |
| 846 bool is_object = exception->ToObject(&exception_object); | 847 bool is_object = exception->ToObject(&exception_object); |
| 847 Handle<Object> exception_handle(exception_object); | 848 Handle<Object> exception_handle(exception_object); |
| 848 | 849 |
| 849 // Determine reporting and whether the exception is caught externally. | 850 // Determine reporting and whether the exception is caught externally. |
| 850 bool is_caught_externally = false; | |
| 851 bool is_out_of_memory = exception == Failure::OutOfMemoryException(); | 851 bool is_out_of_memory = exception == Failure::OutOfMemoryException(); |
| 852 bool is_termination_exception = exception == Heap::termination_exception(); | 852 bool is_termination_exception = exception == Heap::termination_exception(); |
| 853 bool catchable_by_javascript = !is_termination_exception && !is_out_of_memory; | 853 bool catchable_by_javascript = !is_termination_exception && !is_out_of_memory; |
| 854 // Only real objects can be caught by JS. | 854 // Only real objects can be caught by JS. |
| 855 ASSERT(!catchable_by_javascript || is_object); | 855 ASSERT(!catchable_by_javascript || is_object); |
| 856 bool should_return_exception = | 856 bool is_caught_externally = false; |
| 857 ShouldReturnException(&is_caught_externally, catchable_by_javascript); | 857 bool should_report_exception = |
| 858 bool report_exception = catchable_by_javascript && should_return_exception; | 858 ShouldReportException(&is_caught_externally, catchable_by_javascript); |
| 859 bool report_exception = catchable_by_javascript && should_report_exception; |
| 859 | 860 |
| 860 #ifdef ENABLE_DEBUGGER_SUPPORT | 861 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 861 // Notify debugger of exception. | 862 // Notify debugger of exception. |
| 862 if (catchable_by_javascript) { | 863 if (catchable_by_javascript) { |
| 863 Debugger::OnException(exception_handle, report_exception); | 864 Debugger::OnException(exception_handle, report_exception); |
| 864 } | 865 } |
| 865 #endif | 866 #endif |
| 866 | 867 |
| 867 // Generate the message. | 868 // Generate the message. |
| 868 Handle<Object> message_obj; | 869 Handle<Object> message_obj; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 return to + sizeof(thread_local_); | 1089 return to + sizeof(thread_local_); |
| 1089 } | 1090 } |
| 1090 | 1091 |
| 1091 | 1092 |
| 1092 char* Top::RestoreThread(char* from) { | 1093 char* Top::RestoreThread(char* from) { |
| 1093 memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(thread_local_)); | 1094 memcpy(reinterpret_cast<char*>(&thread_local_), from, sizeof(thread_local_)); |
| 1094 // This might be just paranoia, but it seems to be needed in case a | 1095 // This might be just paranoia, but it seems to be needed in case a |
| 1095 // thread_local_ is restored on a separate OS thread. | 1096 // thread_local_ is restored on a separate OS thread. |
| 1096 #ifdef USE_SIMULATOR | 1097 #ifdef USE_SIMULATOR |
| 1097 #ifdef V8_TARGET_ARCH_ARM | 1098 #ifdef V8_TARGET_ARCH_ARM |
| 1098 thread_local_.simulator_ = assembler::arm::Simulator::current(); | 1099 thread_local_.simulator_ = Simulator::current(); |
| 1099 #elif V8_TARGET_ARCH_MIPS | 1100 #elif V8_TARGET_ARCH_MIPS |
| 1100 thread_local_.simulator_ = assembler::mips::Simulator::current(); | 1101 thread_local_.simulator_ = assembler::mips::Simulator::current(); |
| 1101 #endif | 1102 #endif |
| 1102 #endif | 1103 #endif |
| 1103 return from + sizeof(thread_local_); | 1104 return from + sizeof(thread_local_); |
| 1104 } | 1105 } |
| 1105 | 1106 |
| 1106 } } // namespace v8::internal | 1107 } } // namespace v8::internal |
| OLD | NEW |