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

Side by Side Diff: src/top.h

Issue 6397011: 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: Addressing Vitaly's comments Created 9 years, 10 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 // Access to current thread id. 180 // Access to current thread id.
181 static int thread_id() { return thread_local_.thread_id_; } 181 static int thread_id() { return thread_local_.thread_id_; }
182 static void set_thread_id(int id) { thread_local_.thread_id_ = id; } 182 static void set_thread_id(int id) { thread_local_.thread_id_ = id; }
183 183
184 // Interface to pending exception. 184 // Interface to pending exception.
185 static MaybeObject* pending_exception() { 185 static MaybeObject* pending_exception() {
186 ASSERT(has_pending_exception()); 186 ASSERT(has_pending_exception());
187 return thread_local_.pending_exception_; 187 return thread_local_.pending_exception_;
188 } 188 }
189 static bool external_caught_exception() {
190 return thread_local_.external_caught_exception_;
191 }
192 static void set_pending_exception(MaybeObject* exception) { 189 static void set_pending_exception(MaybeObject* exception) {
193 thread_local_.pending_exception_ = exception; 190 thread_local_.pending_exception_ = exception;
194 } 191 }
195 static void clear_pending_exception() { 192 static void clear_pending_exception() {
196 thread_local_.pending_exception_ = Heap::the_hole_value(); 193 thread_local_.pending_exception_ = Heap::the_hole_value();
197 } 194 }
198
199 static MaybeObject** pending_exception_address() { 195 static MaybeObject** pending_exception_address() {
200 return &thread_local_.pending_exception_; 196 return &thread_local_.pending_exception_;
201 } 197 }
202 static bool has_pending_exception() { 198 static bool has_pending_exception() {
203 return !thread_local_.pending_exception_->IsTheHole(); 199 return !thread_local_.pending_exception_->IsTheHole();
204 } 200 }
201
202 static bool external_caught_exception() {
203 return thread_local_.external_caught_exception_;
204 }
205 static void set_external_caught_exception(bool value) {
206 thread_local_.external_caught_exception_ = value;
207 }
208
205 static void clear_pending_message() { 209 static void clear_pending_message() {
206 thread_local_.has_pending_message_ = false; 210 thread_local_.has_pending_message_ = false;
207 thread_local_.pending_message_ = NULL; 211 thread_local_.pending_message_ = NULL;
208 thread_local_.pending_message_obj_ = Heap::the_hole_value(); 212 thread_local_.pending_message_obj_ = Heap::the_hole_value();
209 thread_local_.pending_message_script_ = NULL; 213 thread_local_.pending_message_script_ = NULL;
210 } 214 }
211 static v8::TryCatch* try_catch_handler() { 215 static v8::TryCatch* try_catch_handler() {
212 return thread_local_.TryCatchHandler(); 216 return thread_local_.TryCatchHandler();
213 } 217 }
214 static Address try_catch_handler_address() { 218 static Address try_catch_handler_address() {
(...skipping 18 matching lines...) Expand all
233 ASSERT(has_scheduled_exception()); 237 ASSERT(has_scheduled_exception());
234 return thread_local_.scheduled_exception_; 238 return thread_local_.scheduled_exception_;
235 } 239 }
236 static bool has_scheduled_exception() { 240 static bool has_scheduled_exception() {
237 return !thread_local_.scheduled_exception_->IsTheHole(); 241 return !thread_local_.scheduled_exception_->IsTheHole();
238 } 242 }
239 static void clear_scheduled_exception() { 243 static void clear_scheduled_exception() {
240 thread_local_.scheduled_exception_ = Heap::the_hole_value(); 244 thread_local_.scheduled_exception_ = Heap::the_hole_value();
241 } 245 }
242 246
243 static void setup_external_caught() {
244 thread_local_.external_caught_exception_ =
245 has_pending_exception() &&
246 (thread_local_.catcher_ != NULL) &&
247 (try_catch_handler() == thread_local_.catcher_);
248 }
249
250 static void SetCaptureStackTraceForUncaughtExceptions( 247 static void SetCaptureStackTraceForUncaughtExceptions(
251 bool capture, 248 bool capture,
252 int frame_limit, 249 int frame_limit,
253 StackTrace::StackTraceOptions options); 250 StackTrace::StackTraceOptions options);
254 251
255 // Tells whether the current context has experienced an out of memory 252 // Tells whether the current context has experienced an out of memory
256 // exception. 253 // exception.
257 static bool is_out_of_memory(); 254 static bool is_out_of_memory();
258 255
259 // JS execution stack (see frames.h). 256 // JS execution stack (see frames.h).
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 442
446 static inline ThreadLocalTop* GetCurrentThread() { return &thread_local_; } 443 static inline ThreadLocalTop* GetCurrentThread() { return &thread_local_; }
447 static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); } 444 static int ArchiveSpacePerThread() { return sizeof(ThreadLocalTop); }
448 static char* ArchiveThread(char* to); 445 static char* ArchiveThread(char* to);
449 static char* RestoreThread(char* from); 446 static char* RestoreThread(char* from);
450 static void FreeThreadResources() { thread_local_.Free(); } 447 static void FreeThreadResources() { thread_local_.Free(); }
451 448
452 static const char* kStackOverflowMessage; 449 static const char* kStackOverflowMessage;
453 450
454 private: 451 private:
452
453 static v8::TryCatch* catcher() {
454 return thread_local_.catcher_;
455 }
456
457 static void set_catcher(v8::TryCatch* catcher) {
458 thread_local_.catcher_ = catcher;
459 }
460
461 static void setup_external_caught() {
462 thread_local_.external_caught_exception_ =
463 has_pending_exception() &&
464 (thread_local_.catcher_ != NULL) &&
465 (try_catch_handler() == thread_local_.catcher_);
466 }
467
468 // Attempts to propagate the pending exception to the proper v8::TryCatch.
469 static void PropagatePendingExceptionToExternalTryCatch();
470
455 #ifdef ENABLE_VMSTATE_TRACKING 471 #ifdef ENABLE_VMSTATE_TRACKING
456 // Set of states used when communicating with the runtime profiler. 472 // Set of states used when communicating with the runtime profiler.
457 // 473 //
458 // The set of possible transitions is divided between the VM and the 474 // The set of possible transitions is divided between the VM and the
459 // profiler threads. 475 // profiler threads.
460 // 476 //
461 // The VM thread can perform these transitions: 477 // The VM thread can perform these transitions:
462 // o IN_JS -> NOT_IN_JS 478 // o IN_JS -> NOT_IN_JS
463 // o NOT_IN_JS -> IN_JS 479 // o NOT_IN_JS -> IN_JS
464 // o NOT_IN_JS_WAITING_FOR_JS -> IN_JS notifying the profiler thread 480 // 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
509 // Debug. 525 // Debug.
510 // Mutex for serializing access to break control structures. 526 // Mutex for serializing access to break control structures.
511 static Mutex* break_access_; 527 static Mutex* break_access_;
512 528
513 friend class SaveContext; 529 friend class SaveContext;
514 friend class AssertNoContextChange; 530 friend class AssertNoContextChange;
515 friend class ExecutionAccess; 531 friend class ExecutionAccess;
516 friend class ThreadLocalTop; 532 friend class ThreadLocalTop;
517 533
518 static void FillCache(); 534 static void FillCache();
535
536 public:
537 class Scope {
538 public:
539 Scope() :
Vitaly Repeshko 2011/02/01 19:07:17 Does it lint?
antonm 2011/02/01 20:14:39 Yes
540 // Scope currently can only be used for regular exceptions, not
541 // failures like OOM or termination exception.
542 pending_exception_(Top::pending_exception()->ToObjectUnchecked()),
543 external_caught_exception_(Top::external_caught_exception()),
544 catcher_(Top::catcher())
545 { }
546
547 ~Scope() {
548 Top::set_catcher(catcher_);
549 Top::set_external_caught_exception(external_caught_exception);
550 Top::set_pending_exception(*pending_exception_);
551 }
552
553 private:
554 Handle<Object> pending_exception_;
555 bool external_caught_exception_;
556 v8::TryCatch* catcher_;
557 };
519 }; 558 };
520 559
521 560
522 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the 561 // If the GCC version is 4.1.x or 4.2.x an additional field is added to the
523 // class as a work around for a bug in the generated code found with these 562 // class as a work around for a bug in the generated code found with these
524 // versions of GCC. See V8 issue 122 for details. 563 // versions of GCC. See V8 issue 122 for details.
525 class SaveContext BASE_EMBEDDED { 564 class SaveContext BASE_EMBEDDED {
526 public: 565 public:
527 SaveContext() 566 SaveContext()
528 : context_(Top::context()), 567 : context_(Top::context()),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 static void Unlock() { Top::break_access_->Unlock(); } 629 static void Unlock() { Top::break_access_->Unlock(); }
591 630
592 static bool TryLock() { 631 static bool TryLock() {
593 return Top::break_access_->TryLock(); 632 return Top::break_access_->TryLock();
594 } 633 }
595 }; 634 };
596 635
597 } } // namespace v8::internal 636 } } // namespace v8::internal
598 637
599 #endif // V8_TOP_H_ 638 #endif // V8_TOP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698