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

Side by Side Diff: src/top.h

Issue 6685087: Make exception thrown via v8 public API propagate to v8::TryCatch as JS thrown exceptions do. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 // Access to current thread id. 189 // Access to current thread id.
190 static int thread_id() { return thread_local_.thread_id_; } 190 static int thread_id() { return thread_local_.thread_id_; }
191 static void set_thread_id(int id) { thread_local_.thread_id_ = id; } 191 static void set_thread_id(int id) { thread_local_.thread_id_ = id; }
192 192
193 // Interface to pending exception. 193 // Interface to pending exception.
194 static MaybeObject* pending_exception() { 194 static MaybeObject* pending_exception() {
195 ASSERT(has_pending_exception()); 195 ASSERT(has_pending_exception());
196 return thread_local_.pending_exception_; 196 return thread_local_.pending_exception_;
197 } 197 }
198 static bool external_caught_exception() {
199 return thread_local_.external_caught_exception_;
200 }
201 static void set_pending_exception(MaybeObject* exception) { 198 static void set_pending_exception(MaybeObject* exception) {
202 thread_local_.pending_exception_ = exception; 199 thread_local_.pending_exception_ = exception;
203 } 200 }
204 static void clear_pending_exception() { 201 static void clear_pending_exception() {
205 thread_local_.pending_exception_ = Heap::the_hole_value(); 202 thread_local_.pending_exception_ = Heap::the_hole_value();
206 } 203 }
207
208 static MaybeObject** pending_exception_address() { 204 static MaybeObject** pending_exception_address() {
209 return &thread_local_.pending_exception_; 205 return &thread_local_.pending_exception_;
210 } 206 }
211 static bool has_pending_exception() { 207 static bool has_pending_exception() {
212 return !thread_local_.pending_exception_->IsTheHole(); 208 return !thread_local_.pending_exception_->IsTheHole();
213 } 209 }
210
211 static bool external_caught_exception() {
212 return thread_local_.external_caught_exception_;
213 }
214 static void set_external_caught_exception(bool value) {
215 thread_local_.external_caught_exception_ = value;
216 }
217
214 static void clear_pending_message() { 218 static void clear_pending_message() {
215 thread_local_.has_pending_message_ = false; 219 thread_local_.has_pending_message_ = false;
216 thread_local_.pending_message_ = NULL; 220 thread_local_.pending_message_ = NULL;
217 thread_local_.pending_message_obj_ = Heap::the_hole_value(); 221 thread_local_.pending_message_obj_ = Heap::the_hole_value();
218 thread_local_.pending_message_script_ = NULL; 222 thread_local_.pending_message_script_ = NULL;
219 } 223 }
220 static v8::TryCatch* try_catch_handler() { 224 static v8::TryCatch* try_catch_handler() {
221 return thread_local_.TryCatchHandler(); 225 return thread_local_.TryCatchHandler();
222 } 226 }
223 static Address try_catch_handler_address() { 227 static Address try_catch_handler_address() {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 458
455 static inline ThreadLocalTop* GetCurrentThread() { return &thread_local_; } 459 static inline ThreadLocalTop* GetCurrentThread() { return &thread_local_; }
456 static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); } 460 static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); }
457 static char* ArchiveThread(char* to); 461 static char* ArchiveThread(char* to);
458 static char* RestoreThread(char* from); 462 static char* RestoreThread(char* from);
459 static void FreeThreadResources() { thread_local_.Free(); } 463 static void FreeThreadResources() { thread_local_.Free(); }
460 464
461 static const char* kStackOverflowMessage; 465 static const char* kStackOverflowMessage;
462 466
463 private: 467 private:
468
469 static v8::TryCatch* catcher() {
470 return thread_local_.catcher_;
471 }
472
473 static void set_catcher(v8::TryCatch* catcher) {
474 thread_local_.catcher_ = catcher;
475 }
476
477 // Attempts to propagate the pending exception to the proper v8::TryCatch.
478 static void PropagatePendingExceptionToExternalTryCatch();
479
464 #ifdef ENABLE_VMSTATE_TRACKING 480 #ifdef ENABLE_VMSTATE_TRACKING
465 // Set of states used when communicating with the runtime profiler. 481 // Set of states used when communicating with the runtime profiler.
466 // 482 //
467 // The set of possible transitions is divided between the VM and the 483 // The set of possible transitions is divided between the VM and the
468 // profiler threads. 484 // profiler threads.
469 // 485 //
470 // The VM thread can perform these transitions: 486 // The VM thread can perform these transitions:
471 // o IN_JS -> NOT_IN_JS 487 // o IN_JS -> NOT_IN_JS
472 // o NOT_IN_JS -> IN_JS 488 // o NOT_IN_JS -> IN_JS
473 // o NOT_IN_JS_WAITING_FOR_JS -> IN_JS notifying the profiler thread 489 // o NOT_IN_JS_WAITING_FOR_JS -> IN_JS notifying the profiler thread
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // Debug. 534 // Debug.
519 // Mutex for serializing access to break control structures. 535 // Mutex for serializing access to break control structures.
520 static Mutex* break_access_; 536 static Mutex* break_access_;
521 537
522 friend class SaveContext; 538 friend class SaveContext;
523 friend class AssertNoContextChange; 539 friend class AssertNoContextChange;
524 friend class ExecutionAccess; 540 friend class ExecutionAccess;
525 friend class ThreadLocalTop; 541 friend class ThreadLocalTop;
526 542
527 static void FillCache(); 543 static void FillCache();
544
545 public:
546 class ExceptionScope {
547 public:
548 ExceptionScope() :
549 // Scope currently can only be used for regular exceptions, not
550 // failures like OOM or termination exception.
551 pending_exception_(Top::pending_exception()->ToObjectUnchecked()),
552 catcher_(Top::catcher())
553 { }
554
555 ~ExceptionScope() {
556 Top::set_catcher(catcher_);
557 Top::set_pending_exception(*pending_exception_);
558 }
559
560 private:
561 Handle<Object> pending_exception_;
562 v8::TryCatch* catcher_;
563 };
528 }; 564 };
529 565
530 566
531 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the 567 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the
532 // class as a work around for a bug in the generated code found with these 568 // class as a work around for a bug in the generated code found with these
533 // versions of GCC. See V8 issue 122 for details. 569 // versions of GCC. See V8 issue 122 for details.
534 class SaveContext BASE_EMBEDDED { 570 class SaveContext BASE_EMBEDDED {
535 public: 571 public:
536 SaveContext() 572 SaveContext()
537 : context_(Top::context()), 573 : context_(Top::context()),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 static void Unlock() { Top::break_access_->Unlock(); } 635 static void Unlock() { Top::break_access_->Unlock(); }
600 636
601 static bool TryLock() { 637 static bool TryLock() {
602 return Top::break_access_->TryLock(); 638 return Top::break_access_->TryLock();
603 } 639 }
604 }; 640 };
605 641
606 } } // namespace v8::internal 642 } } // namespace v8::internal
607 643
608 #endif // V8_TOP_H_ 644 #endif // V8_TOP_H_
OLDNEW
« src/messages.cc ('K') | « src/messages.cc ('k') | src/top.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698