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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 save_context_ = NULL; | 84 save_context_ = NULL; |
85 catcher_ = NULL; | 85 catcher_ = NULL; |
86 promise_on_stack_ = NULL; | 86 promise_on_stack_ = NULL; |
87 | 87 |
88 // These members are re-initialized later after deserialization | 88 // These members are re-initialized later after deserialization |
89 // is complete. | 89 // is complete. |
90 pending_exception_ = NULL; | 90 pending_exception_ = NULL; |
91 has_pending_message_ = false; | 91 has_pending_message_ = false; |
92 rethrowing_message_ = false; | 92 rethrowing_message_ = false; |
93 pending_message_obj_ = NULL; | 93 pending_message_obj_ = NULL; |
94 pending_message_script_ = NULL; | |
95 scheduled_exception_ = NULL; | 94 scheduled_exception_ = NULL; |
96 } | 95 } |
97 | 96 |
98 | 97 |
99 void ThreadLocalTop::Initialize() { | 98 void ThreadLocalTop::Initialize() { |
100 InitializeInternal(); | 99 InitializeInternal(); |
101 #ifdef USE_SIMULATOR | 100 #ifdef USE_SIMULATOR |
102 simulator_ = Simulator::current(isolate_); | 101 simulator_ = Simulator::current(isolate_); |
103 #endif | 102 #endif |
104 thread_id_ = ThreadId::Current(); | 103 thread_id_ = ThreadId::Current(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 void Isolate::IterateThread(ThreadVisitor* v, char* t) { | 182 void Isolate::IterateThread(ThreadVisitor* v, char* t) { |
184 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(t); | 183 ThreadLocalTop* thread = reinterpret_cast<ThreadLocalTop*>(t); |
185 v->VisitThread(this, thread); | 184 v->VisitThread(this, thread); |
186 } | 185 } |
187 | 186 |
188 | 187 |
189 void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { | 188 void Isolate::Iterate(ObjectVisitor* v, ThreadLocalTop* thread) { |
190 // Visit the roots from the top for a given thread. | 189 // Visit the roots from the top for a given thread. |
191 v->VisitPointer(&thread->pending_exception_); | 190 v->VisitPointer(&thread->pending_exception_); |
192 v->VisitPointer(&(thread->pending_message_obj_)); | 191 v->VisitPointer(&(thread->pending_message_obj_)); |
193 v->VisitPointer(bit_cast<Object**>(&(thread->pending_message_script_))); | |
194 v->VisitPointer(bit_cast<Object**>(&(thread->context_))); | 192 v->VisitPointer(bit_cast<Object**>(&(thread->context_))); |
195 v->VisitPointer(&thread->scheduled_exception_); | 193 v->VisitPointer(&thread->scheduled_exception_); |
196 | 194 |
197 for (v8::TryCatch* block = thread->try_catch_handler(); | 195 for (v8::TryCatch* block = thread->try_catch_handler(); |
198 block != NULL; | 196 block != NULL; |
199 block = block->next_) { | 197 block = block->next_) { |
200 v->VisitPointer(bit_cast<Object**>(&(block->exception_))); | 198 v->VisitPointer(bit_cast<Object**>(&(block->exception_))); |
201 v->VisitPointer(bit_cast<Object**>(&(block->message_obj_))); | 199 v->VisitPointer(bit_cast<Object**>(&(block->message_obj_))); |
202 v->VisitPointer(bit_cast<Object**>(&(block->message_script_))); | |
203 } | 200 } |
204 | 201 |
205 // Iterate over pointers on native execution stack. | 202 // Iterate over pointers on native execution stack. |
206 for (StackFrameIterator it(this, thread); !it.done(); it.Advance()) { | 203 for (StackFrameIterator it(this, thread); !it.done(); it.Advance()) { |
207 it.frame()->Iterate(v); | 204 it.frame()->Iterate(v); |
208 } | 205 } |
209 } | 206 } |
210 | 207 |
211 | 208 |
212 void Isolate::Iterate(ObjectVisitor* v) { | 209 void Isolate::Iterate(ObjectVisitor* v) { |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 | 979 |
983 if (bootstrapper()->IsActive()) { | 980 if (bootstrapper()->IsActive()) { |
984 // It's not safe to try to make message objects or collect stack traces | 981 // It's not safe to try to make message objects or collect stack traces |
985 // while the bootstrapper is active since the infrastructure may not have | 982 // while the bootstrapper is active since the infrastructure may not have |
986 // been properly initialized. | 983 // been properly initialized. |
987 ReportBootstrappingException(exception_handle, location); | 984 ReportBootstrappingException(exception_handle, location); |
988 } else { | 985 } else { |
989 Handle<Object> message_obj = CreateMessage(exception_handle, location); | 986 Handle<Object> message_obj = CreateMessage(exception_handle, location); |
990 | 987 |
991 thread_local_top()->pending_message_obj_ = *message_obj; | 988 thread_local_top()->pending_message_obj_ = *message_obj; |
992 thread_local_top()->pending_message_script_ = *location->script(); | |
993 | 989 |
994 // If the abort-on-uncaught-exception flag is specified, abort on any | 990 // If the abort-on-uncaught-exception flag is specified, abort on any |
995 // exception not caught by JavaScript, even when an external handler is | 991 // exception not caught by JavaScript, even when an external handler is |
996 // present. This flag is intended for use by JavaScript developers, so | 992 // present. This flag is intended for use by JavaScript developers, so |
997 // print a user-friendly stack trace (not an internal one). | 993 // print a user-friendly stack trace (not an internal one). |
998 if (fatal_exception_depth == 0 && FLAG_abort_on_uncaught_exception && | 994 if (fatal_exception_depth == 0 && FLAG_abort_on_uncaught_exception && |
999 (report_exception || can_be_caught_externally)) { | 995 (report_exception || can_be_caught_externally)) { |
1000 fatal_exception_depth++; | 996 fatal_exception_depth++; |
1001 PrintF(stderr, "%s\n\nFROM\n", | 997 PrintF(stderr, "%s\n\nFROM\n", |
1002 MessageHandler::GetLocalizedMessage(this, message_obj).get()); | 998 MessageHandler::GetLocalizedMessage(this, message_obj).get()); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 } | 1150 } |
1155 } | 1151 } |
1156 | 1152 |
1157 | 1153 |
1158 void Isolate::RestorePendingMessageFromTryCatch(v8::TryCatch* handler) { | 1154 void Isolate::RestorePendingMessageFromTryCatch(v8::TryCatch* handler) { |
1159 DCHECK(handler == try_catch_handler()); | 1155 DCHECK(handler == try_catch_handler()); |
1160 DCHECK(handler->HasCaught()); | 1156 DCHECK(handler->HasCaught()); |
1161 DCHECK(handler->rethrow_); | 1157 DCHECK(handler->rethrow_); |
1162 DCHECK(handler->capture_message_); | 1158 DCHECK(handler->capture_message_); |
1163 Object* message = reinterpret_cast<Object*>(handler->message_obj_); | 1159 Object* message = reinterpret_cast<Object*>(handler->message_obj_); |
1164 Object* script = reinterpret_cast<Object*>(handler->message_script_); | |
1165 DCHECK(message->IsJSMessageObject() || message->IsTheHole()); | 1160 DCHECK(message->IsJSMessageObject() || message->IsTheHole()); |
1166 DCHECK(script->IsScript() || script->IsTheHole()); | |
1167 thread_local_top()->pending_message_obj_ = message; | 1161 thread_local_top()->pending_message_obj_ = message; |
1168 thread_local_top()->pending_message_script_ = script; | |
1169 } | 1162 } |
1170 | 1163 |
1171 | 1164 |
1172 void Isolate::CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler) { | 1165 void Isolate::CancelScheduledExceptionFromTryCatch(v8::TryCatch* handler) { |
1173 DCHECK(has_scheduled_exception()); | 1166 DCHECK(has_scheduled_exception()); |
1174 if (scheduled_exception() == handler->exception_) { | 1167 if (scheduled_exception() == handler->exception_) { |
1175 DCHECK(scheduled_exception() != heap()->termination_exception()); | 1168 DCHECK(scheduled_exception() != heap()->termination_exception()); |
1176 clear_scheduled_exception(); | 1169 clear_scheduled_exception(); |
1177 } | 1170 } |
1178 } | 1171 } |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 if (thread_local_top_.pending_exception_ == heap()->termination_exception()) { | 1432 if (thread_local_top_.pending_exception_ == heap()->termination_exception()) { |
1440 // Do nothing: if needed, the exception has been already propagated to | 1433 // Do nothing: if needed, the exception has been already propagated to |
1441 // v8::TryCatch. | 1434 // v8::TryCatch. |
1442 } else { | 1435 } else { |
1443 if (thread_local_top_.has_pending_message_) { | 1436 if (thread_local_top_.has_pending_message_) { |
1444 thread_local_top_.has_pending_message_ = false; | 1437 thread_local_top_.has_pending_message_ = false; |
1445 if (!thread_local_top_.pending_message_obj_->IsTheHole()) { | 1438 if (!thread_local_top_.pending_message_obj_->IsTheHole()) { |
1446 HandleScope scope(this); | 1439 HandleScope scope(this); |
1447 Handle<JSMessageObject> message_obj( | 1440 Handle<JSMessageObject> message_obj( |
1448 JSMessageObject::cast(thread_local_top_.pending_message_obj_)); | 1441 JSMessageObject::cast(thread_local_top_.pending_message_obj_)); |
1449 if (!thread_local_top_.pending_message_script_->IsTheHole()) { | 1442 Handle<JSValue> script_wrapper(JSValue::cast(message_obj->script())); |
1450 Handle<Script> script( | 1443 Handle<Script> script(Script::cast(script_wrapper->value())); |
1451 Script::cast(thread_local_top_.pending_message_script_)); | 1444 int start_pos = message_obj->start_position(); |
1452 int start_pos = message_obj->start_position(); | 1445 int end_pos = message_obj->end_position(); |
1453 int end_pos = message_obj->end_position(); | 1446 MessageLocation location(script, start_pos, end_pos); |
1454 MessageLocation location(script, start_pos, end_pos); | 1447 MessageHandler::ReportMessage(this, &location, message_obj); |
1455 MessageHandler::ReportMessage(this, &location, message_obj); | |
1456 } else { | |
1457 MessageHandler::ReportMessage(this, NULL, message_obj); | |
1458 } | |
1459 } | 1448 } |
1460 } | 1449 } |
1461 } | 1450 } |
1462 if (can_clear_message) clear_pending_message(); | 1451 if (can_clear_message) clear_pending_message(); |
1463 } | 1452 } |
1464 | 1453 |
1465 | 1454 |
1466 MessageLocation Isolate::GetMessageLocation() { | 1455 MessageLocation Isolate::GetMessageLocation() { |
1467 DCHECK(has_pending_exception()); | 1456 DCHECK(has_pending_exception()); |
1468 | 1457 |
1469 if (thread_local_top_.pending_exception_ != heap()->termination_exception() && | 1458 if (thread_local_top_.pending_exception_ != heap()->termination_exception() && |
1470 thread_local_top_.has_pending_message_ && | 1459 thread_local_top_.has_pending_message_ && |
1471 !thread_local_top_.pending_message_obj_->IsTheHole()) { | 1460 !thread_local_top_.pending_message_obj_->IsTheHole()) { |
1472 Handle<JSMessageObject> message_obj( | 1461 Handle<JSMessageObject> message_obj( |
1473 JSMessageObject::cast(thread_local_top_.pending_message_obj_)); | 1462 JSMessageObject::cast(thread_local_top_.pending_message_obj_)); |
1474 Handle<Script> script( | 1463 Handle<JSValue> script_wrapper(JSValue::cast(message_obj->script())); |
1475 Script::cast(thread_local_top_.pending_message_script_)); | 1464 Handle<Script> script(Script::cast(script_wrapper->value())); |
1476 int start_pos = message_obj->start_position(); | 1465 int start_pos = message_obj->start_position(); |
1477 int end_pos = message_obj->end_position(); | 1466 int end_pos = message_obj->end_position(); |
1478 return MessageLocation(script, start_pos, end_pos); | 1467 return MessageLocation(script, start_pos, end_pos); |
1479 } | 1468 } |
1480 | 1469 |
1481 return MessageLocation(); | 1470 return MessageLocation(); |
1482 } | 1471 } |
1483 | 1472 |
1484 | 1473 |
1485 bool Isolate::OptionalRescheduleException(bool is_bottom_call) { | 1474 bool Isolate::OptionalRescheduleException(bool is_bottom_call) { |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1981 | 1970 |
1982 thread_local_top_.external_caught_exception_ = true; | 1971 thread_local_top_.external_caught_exception_ = true; |
1983 if (thread_local_top_.pending_exception_ == heap()->termination_exception()) { | 1972 if (thread_local_top_.pending_exception_ == heap()->termination_exception()) { |
1984 try_catch_handler()->can_continue_ = false; | 1973 try_catch_handler()->can_continue_ = false; |
1985 try_catch_handler()->has_terminated_ = true; | 1974 try_catch_handler()->has_terminated_ = true; |
1986 try_catch_handler()->exception_ = heap()->null_value(); | 1975 try_catch_handler()->exception_ = heap()->null_value(); |
1987 } else { | 1976 } else { |
1988 v8::TryCatch* handler = try_catch_handler(); | 1977 v8::TryCatch* handler = try_catch_handler(); |
1989 DCHECK(thread_local_top_.pending_message_obj_->IsJSMessageObject() || | 1978 DCHECK(thread_local_top_.pending_message_obj_->IsJSMessageObject() || |
1990 thread_local_top_.pending_message_obj_->IsTheHole()); | 1979 thread_local_top_.pending_message_obj_->IsTheHole()); |
1991 DCHECK(thread_local_top_.pending_message_script_->IsScript() || | |
1992 thread_local_top_.pending_message_script_->IsTheHole()); | |
1993 handler->can_continue_ = true; | 1980 handler->can_continue_ = true; |
1994 handler->has_terminated_ = false; | 1981 handler->has_terminated_ = false; |
1995 handler->exception_ = pending_exception(); | 1982 handler->exception_ = pending_exception(); |
1996 // Propagate to the external try-catch only if we got an actual message. | 1983 // Propagate to the external try-catch only if we got an actual message. |
1997 if (thread_local_top_.pending_message_obj_->IsTheHole()) return true; | 1984 if (thread_local_top_.pending_message_obj_->IsTheHole()) return true; |
1998 | 1985 |
1999 handler->message_obj_ = thread_local_top_.pending_message_obj_; | 1986 handler->message_obj_ = thread_local_top_.pending_message_obj_; |
2000 handler->message_script_ = thread_local_top_.pending_message_script_; | |
2001 } | 1987 } |
2002 return true; | 1988 return true; |
2003 } | 1989 } |
2004 | 1990 |
2005 | 1991 |
2006 void Isolate::InitializeLoggingAndCounters() { | 1992 void Isolate::InitializeLoggingAndCounters() { |
2007 if (logger_ == NULL) { | 1993 if (logger_ == NULL) { |
2008 logger_ = new Logger(this); | 1994 logger_ = new Logger(this); |
2009 } | 1995 } |
2010 if (counters_ == NULL) { | 1996 if (counters_ == NULL) { |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2650 if (prev_ && prev_->Intercept(flag)) return true; | 2636 if (prev_ && prev_->Intercept(flag)) return true; |
2651 // Then check whether this scope intercepts. | 2637 // Then check whether this scope intercepts. |
2652 if ((flag & intercept_mask_)) { | 2638 if ((flag & intercept_mask_)) { |
2653 intercepted_flags_ |= flag; | 2639 intercepted_flags_ |= flag; |
2654 return true; | 2640 return true; |
2655 } | 2641 } |
2656 return false; | 2642 return false; |
2657 } | 2643 } |
2658 | 2644 |
2659 } } // namespace v8::internal | 2645 } } // namespace v8::internal |
OLD | NEW |