Work around issue 131 by checking for empty handles
authorkasperl@chromium.org <kasperl@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 28 Oct 2008 08:29:23 +0000 (08:29 +0000)
committerkasperl@chromium.org <kasperl@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 28 Oct 2008 08:29:23 +0000 (08:29 +0000)
in a few places.
Review URL: http://codereview.chromium.org/8828

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

src/api.cc
src/top.cc

index 2fb5680..86d579b 100644 (file)
@@ -230,7 +230,13 @@ void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
 
 v8::Handle<Value> ThrowException(v8::Handle<v8::Value> value) {
   if (IsDeadCheck("v8::ThrowException()")) return v8::Handle<Value>();
-  i::Top::ScheduleThrow(*Utils::OpenHandle(*value));
+  // If we're passed an empty handle, we throw an undefined exception
+  // to deal more gracefully with out of memory situations.
+  if (value.IsEmpty()) {
+    i::Top::ScheduleThrow(i::Heap::undefined_value());
+  } else {
+    i::Top::ScheduleThrow(*Utils::OpenHandle(*value));
+  }
   return v8::Undefined();
 }
 
index a78ba32..29b7861 100644 (file)
@@ -806,7 +806,7 @@ void Top::DoThrow(Object* exception,
   if (report_exception) {
     if (message != NULL) {
       MessageHandler::ReportMessage(message);
-    } else {
+    } else if (!message_obj.is_null()) {
       MessageHandler::ReportMessage(location, message_obj);
     }
   }