Added option for TryCatches to not capture the message object on
authorchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 10 Sep 2008 14:54:15 +0000 (14:54 +0000)
committerchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 10 Sep 2008 14:54:15 +0000 (14:54 +0000)
exceptions.

It turned out that the stack overflow fix from before had disabled
message storing in another test.  Previously, stack overflows would
actually cause a message object to start being created but cause
another exception which would not be reported and that's what stopped
the infinite regress.  This change resores that behavior.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@259 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

include/v8.h
src/api.cc
src/execution.cc
src/top.cc
test/cctest/test-api.cc

index 430165a..c2724e8 100644 (file)
@@ -1993,11 +1993,19 @@ class EXPORT TryCatch {
    */
   void SetVerbose(bool value);
 
+  /**
+   * Set whether or not this TryCatch should capture a Message object
+   * which holds source information about where the exception
+   * occurred.  True by default.
+   */
+  void SetCaptureMessage(bool value);
+
  public:
   TryCatch* next_;
   void* exception_;
   void* message_;
   bool is_verbose_;
+  bool capture_message_;
 };
 
 
index 6d4904d..75fcf2b 100644 (file)
@@ -1082,7 +1082,8 @@ v8::TryCatch::TryCatch()
     : next_(i::Top::try_catch_handler()),
       exception_(i::Heap::the_hole_value()),
       message_(i::Smi::FromInt(0)),
-      is_verbose_(false) {
+      is_verbose_(false),
+      capture_message_(true) {
   i::Top::RegisterTryCatchHandler(this);
 }
 
@@ -1129,6 +1130,11 @@ void v8::TryCatch::SetVerbose(bool value) {
 }
 
 
+void v8::TryCatch::SetCaptureMessage(bool value) {
+  capture_message_ = value;
+}
+
+
 // --- M e s s a g e ---
 
 
index f1dae92..ce2259e 100644 (file)
@@ -130,9 +130,12 @@ Handle<Object> Execution::TryCall(Handle<JSFunction> func,
                                   Object*** args,
                                   bool* caught_exception) {
   // Enter a try-block while executing the JavaScript code. To avoid
-  // duplicate error printing it must be non-verbose.
+  // duplicate error printing it must be non-verbose.  Also, to avoid
+  // creating message objects during stack overflow we shouldn't
+  // capture messages.
   v8::TryCatch catcher;
   catcher.SetVerbose(false);
+  catcher.SetCaptureMessage(false);
 
   Handle<Object> result = Invoke(false, func, receiver, argc, args,
                                  caught_exception);
index 8b2d9b7..061b300 100644 (file)
@@ -770,7 +770,9 @@ void Top::DoThrow(Object* exception,
 
   Handle<Object> message_obj;
   MessageLocation potential_computed_location;
-  if (report_exception) {
+  bool try_catch_needs_message =
+    is_caught_externally && thread_local_.try_catch_handler_->capture_message_;
+  if (report_exception || try_catch_needs_message) {
     if (location == NULL) {
       // If no location was specified we use a computed one instead
       ComputeLocation(&potential_computed_location);
index fbf1a40..f5bc4c6 100644 (file)
@@ -4845,6 +4845,21 @@ THREADED_TEST(Regress54) {
 }
 
 
+THREADED_TEST(CatchStackOverflow) {
+  v8::HandleScope scope;
+  LocalContext context;
+  v8::TryCatch try_catch;
+  v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(
+    "function f() {"
+    "  return f();"
+    "}"
+    ""
+    "f();"));
+  v8::Handle<v8::Value> result = script->Run();
+  CHECK(result.IsEmpty());
+}
+
+
 THREADED_TEST(TryCatchSourceInfo) {
   v8::HandleScope scope;
   LocalContext context;