| 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 <fstream> // NOLINT(readability/streams) | 7 #include <fstream> // NOLINT(readability/streams) |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "src/v8.h" | 10 #include "src/v8.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 #endif | 75 #endif |
| 76 js_entry_sp_ = NULL; | 76 js_entry_sp_ = NULL; |
| 77 external_callback_scope_ = NULL; | 77 external_callback_scope_ = NULL; |
| 78 current_vm_state_ = EXTERNAL; | 78 current_vm_state_ = EXTERNAL; |
| 79 try_catch_handler_ = NULL; | 79 try_catch_handler_ = NULL; |
| 80 context_ = NULL; | 80 context_ = NULL; |
| 81 thread_id_ = ThreadId::Invalid(); | 81 thread_id_ = ThreadId::Invalid(); |
| 82 external_caught_exception_ = false; | 82 external_caught_exception_ = false; |
| 83 failed_access_check_callback_ = NULL; | 83 failed_access_check_callback_ = NULL; |
| 84 save_context_ = NULL; | 84 save_context_ = NULL; |
| 85 catcher_ = NULL; | |
| 86 promise_on_stack_ = NULL; | 85 promise_on_stack_ = NULL; |
| 87 | 86 |
| 88 // These members are re-initialized later after deserialization | 87 // These members are re-initialized later after deserialization |
| 89 // is complete. | 88 // is complete. |
| 90 pending_exception_ = NULL; | 89 pending_exception_ = NULL; |
| 91 has_pending_message_ = false; | 90 has_pending_message_ = false; |
| 92 rethrowing_message_ = false; | 91 rethrowing_message_ = false; |
| 93 pending_message_obj_ = NULL; | 92 pending_message_obj_ = NULL; |
| 94 scheduled_exception_ = NULL; | 93 scheduled_exception_ = NULL; |
| 95 } | 94 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 244 |
| 246 | 245 |
| 247 void Isolate::RegisterTryCatchHandler(v8::TryCatch* that) { | 246 void Isolate::RegisterTryCatchHandler(v8::TryCatch* that) { |
| 248 thread_local_top()->set_try_catch_handler(that); | 247 thread_local_top()->set_try_catch_handler(that); |
| 249 } | 248 } |
| 250 | 249 |
| 251 | 250 |
| 252 void Isolate::UnregisterTryCatchHandler(v8::TryCatch* that) { | 251 void Isolate::UnregisterTryCatchHandler(v8::TryCatch* that) { |
| 253 DCHECK(thread_local_top()->try_catch_handler() == that); | 252 DCHECK(thread_local_top()->try_catch_handler() == that); |
| 254 thread_local_top()->set_try_catch_handler(that->next_); | 253 thread_local_top()->set_try_catch_handler(that->next_); |
| 255 thread_local_top()->catcher_ = NULL; | |
| 256 } | 254 } |
| 257 | 255 |
| 258 | 256 |
| 259 Handle<String> Isolate::StackTraceString() { | 257 Handle<String> Isolate::StackTraceString() { |
| 260 if (stack_trace_nesting_level_ == 0) { | 258 if (stack_trace_nesting_level_ == 0) { |
| 261 stack_trace_nesting_level_++; | 259 stack_trace_nesting_level_++; |
| 262 HeapStringAllocator allocator; | 260 HeapStringAllocator allocator; |
| 263 StringStream::ClearMentionedObjectCache(this); | 261 StringStream::ClearMentionedObjectCache(this); |
| 264 StringStream accumulator(&allocator); | 262 StringStream accumulator(&allocator); |
| 265 incomplete_message_ = &accumulator; | 263 incomplete_message_ = &accumulator; |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 MessageHandler::GetLocalizedMessage(this, message_obj).get()); | 996 MessageHandler::GetLocalizedMessage(this, message_obj).get()); |
| 999 PrintCurrentStackTrace(stderr); | 997 PrintCurrentStackTrace(stderr); |
| 1000 base::OS::Abort(); | 998 base::OS::Abort(); |
| 1001 } | 999 } |
| 1002 } | 1000 } |
| 1003 } | 1001 } |
| 1004 | 1002 |
| 1005 // Save the message for reporting if the the exception remains uncaught. | 1003 // Save the message for reporting if the the exception remains uncaught. |
| 1006 thread_local_top()->has_pending_message_ = report_exception; | 1004 thread_local_top()->has_pending_message_ = report_exception; |
| 1007 | 1005 |
| 1008 // Do not forget to clean catcher_ if currently thrown exception cannot | |
| 1009 // be caught. If necessary, ReThrow will update the catcher. | |
| 1010 thread_local_top()->catcher_ = | |
| 1011 can_be_caught_externally ? try_catch_handler() : NULL; | |
| 1012 | |
| 1013 // Set the exception being thrown. | 1006 // Set the exception being thrown. |
| 1014 set_pending_exception(*exception_handle); | 1007 set_pending_exception(*exception_handle); |
| 1015 return heap()->exception(); | 1008 return heap()->exception(); |
| 1016 } | 1009 } |
| 1017 | 1010 |
| 1018 | 1011 |
| 1019 Object* Isolate::ReThrow(Object* exception) { | 1012 Object* Isolate::ReThrow(Object* exception) { |
| 1020 bool can_be_caught_externally = false; | 1013 DCHECK(!has_pending_exception()); |
| 1021 bool catchable_by_javascript = is_catchable_by_javascript(exception); | |
| 1022 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); | |
| 1023 | |
| 1024 thread_local_top()->catcher_ = can_be_caught_externally ? | |
| 1025 try_catch_handler() : NULL; | |
| 1026 | 1014 |
| 1027 // Set the exception being re-thrown. | 1015 // Set the exception being re-thrown. |
| 1028 set_pending_exception(exception); | 1016 set_pending_exception(exception); |
| 1029 return heap()->exception(); | 1017 return heap()->exception(); |
| 1030 } | 1018 } |
| 1031 | 1019 |
| 1032 | 1020 |
| 1033 // TODO(turbofan): Make sure table is sorted and use binary search. | 1021 // TODO(turbofan): Make sure table is sorted and use binary search. |
| 1034 static int LookupInHandlerTable(Code* code, int pc_offset) { | 1022 static int LookupInHandlerTable(Code* code, int pc_offset) { |
| 1035 FixedArray* handler_table = code->handler_table(); | 1023 FixedArray* handler_table = code->handler_table(); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 exception = | 1368 exception = |
| 1381 factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("exception")); | 1369 factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("exception")); |
| 1382 } | 1370 } |
| 1383 } | 1371 } |
| 1384 return MessageHandler::MakeMessageObject(this, "uncaught_exception", location, | 1372 return MessageHandler::MakeMessageObject(this, "uncaught_exception", location, |
| 1385 HandleVector<Object>(&exception, 1), | 1373 HandleVector<Object>(&exception, 1), |
| 1386 stack_trace_object); | 1374 stack_trace_object); |
| 1387 } | 1375 } |
| 1388 | 1376 |
| 1389 | 1377 |
| 1390 bool Isolate::HasExternalTryCatch() { | |
| 1391 DCHECK(has_pending_exception()); | |
| 1392 | |
| 1393 return (thread_local_top()->catcher_ != NULL) && | |
| 1394 (try_catch_handler() == thread_local_top()->catcher_); | |
| 1395 } | |
| 1396 | |
| 1397 | |
| 1398 bool Isolate::IsFinallyOnTop() { | 1378 bool Isolate::IsFinallyOnTop() { |
| 1399 // Get the address of the external handler so we can compare the address to | 1379 // Get the address of the external handler so we can compare the address to |
| 1400 // determine which one is closer to the top of the stack. | 1380 // determine which one is closer to the top of the stack. |
| 1401 Address external_handler_address = | 1381 Address external_handler_address = |
| 1402 thread_local_top()->try_catch_handler_address(); | 1382 thread_local_top()->try_catch_handler_address(); |
| 1403 DCHECK(external_handler_address != NULL); | 1383 DCHECK(external_handler_address != NULL); |
| 1404 | 1384 |
| 1405 // The exception has been externally caught if and only if there is | 1385 // The exception has been externally caught if and only if there is |
| 1406 // an external handler which is on top of the top-most try-finally | 1386 // an external handler which is on top of the top-most try-finally |
| 1407 // handler. | 1387 // handler. |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1947 } | 1927 } |
| 1948 | 1928 |
| 1949 | 1929 |
| 1950 void Isolate::InitializeThreadLocal() { | 1930 void Isolate::InitializeThreadLocal() { |
| 1951 thread_local_top_.isolate_ = this; | 1931 thread_local_top_.isolate_ = this; |
| 1952 thread_local_top_.Initialize(); | 1932 thread_local_top_.Initialize(); |
| 1953 } | 1933 } |
| 1954 | 1934 |
| 1955 | 1935 |
| 1956 bool Isolate::PropagatePendingExceptionToExternalTryCatch() { | 1936 bool Isolate::PropagatePendingExceptionToExternalTryCatch() { |
| 1957 DCHECK(has_pending_exception()); | 1937 Object* exception = pending_exception(); |
| 1958 | 1938 |
| 1959 bool has_external_try_catch = HasExternalTryCatch(); | 1939 bool can_be_caught_externally = false; |
| 1960 if (!has_external_try_catch) { | 1940 bool catchable_by_javascript = is_catchable_by_javascript(exception); |
| 1941 ShouldReportException(&can_be_caught_externally, catchable_by_javascript); |
| 1942 if (!can_be_caught_externally) { |
| 1961 thread_local_top_.external_caught_exception_ = false; | 1943 thread_local_top_.external_caught_exception_ = false; |
| 1962 return true; | 1944 return true; |
| 1963 } | 1945 } |
| 1964 | 1946 |
| 1965 bool catchable_by_js = is_catchable_by_javascript(pending_exception()); | 1947 if (catchable_by_javascript && IsFinallyOnTop()) { |
| 1966 if (catchable_by_js && IsFinallyOnTop()) { | |
| 1967 thread_local_top_.external_caught_exception_ = false; | 1948 thread_local_top_.external_caught_exception_ = false; |
| 1968 return false; | 1949 return false; |
| 1969 } | 1950 } |
| 1970 | 1951 |
| 1971 thread_local_top_.external_caught_exception_ = true; | 1952 thread_local_top_.external_caught_exception_ = true; |
| 1972 if (thread_local_top_.pending_exception_ == heap()->termination_exception()) { | 1953 if (!catchable_by_javascript) { |
| 1973 try_catch_handler()->can_continue_ = false; | 1954 try_catch_handler()->can_continue_ = false; |
| 1974 try_catch_handler()->has_terminated_ = true; | 1955 try_catch_handler()->has_terminated_ = true; |
| 1975 try_catch_handler()->exception_ = heap()->null_value(); | 1956 try_catch_handler()->exception_ = heap()->null_value(); |
| 1976 } else { | 1957 } else { |
| 1977 v8::TryCatch* handler = try_catch_handler(); | 1958 v8::TryCatch* handler = try_catch_handler(); |
| 1978 DCHECK(thread_local_top_.pending_message_obj_->IsJSMessageObject() || | 1959 DCHECK(thread_local_top_.pending_message_obj_->IsJSMessageObject() || |
| 1979 thread_local_top_.pending_message_obj_->IsTheHole()); | 1960 thread_local_top_.pending_message_obj_->IsTheHole()); |
| 1980 handler->can_continue_ = true; | 1961 handler->can_continue_ = true; |
| 1981 handler->has_terminated_ = false; | 1962 handler->has_terminated_ = false; |
| 1982 handler->exception_ = pending_exception(); | 1963 handler->exception_ = pending_exception(); |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2636 if (prev_ && prev_->Intercept(flag)) return true; | 2617 if (prev_ && prev_->Intercept(flag)) return true; |
| 2637 // Then check whether this scope intercepts. | 2618 // Then check whether this scope intercepts. |
| 2638 if ((flag & intercept_mask_)) { | 2619 if ((flag & intercept_mask_)) { |
| 2639 intercepted_flags_ |= flag; | 2620 intercepted_flags_ |= flag; |
| 2640 return true; | 2621 return true; |
| 2641 } | 2622 } |
| 2642 return false; | 2623 return false; |
| 2643 } | 2624 } |
| 2644 | 2625 |
| 2645 } } // namespace v8::internal | 2626 } } // namespace v8::internal |
| OLD | NEW |