Revision: 7553
Author: [email protected]
Date: Fri Apr 8 02:39:45 2011
Log: Report stack overflow exceptions to V8 message listeners
Stack overflow exceptions like other JavaScript exceptions should be
reported to listeners added via V8::AddMessageListener
Review URL: http://codereview.chromium.org/6816021
http://code.google.com/p/v8/source/detail?r=7553
Modified:
/branches/bleeding_edge/src/isolate.h
/branches/bleeding_edge/src/messages.cc
/branches/bleeding_edge/src/messages.h
/branches/bleeding_edge/src/top.cc
/branches/bleeding_edge/test/cctest/test-api.cc
=======================================
--- /branches/bleeding_edge/src/isolate.h Thu Apr 7 13:57:07 2011
+++ /branches/bleeding_edge/src/isolate.h Fri Apr 8 02:39:45 2011
@@ -179,7 +179,6 @@
int thread_id_;
MaybeObject* pending_exception_;
bool has_pending_message_;
- const char* pending_message_;
Object* pending_message_obj_;
Script* pending_message_script_;
int pending_message_start_pos_;
@@ -515,7 +514,6 @@
}
void clear_pending_message() {
thread_local_top_.has_pending_message_ = false;
- thread_local_top_.pending_message_ = NULL;
thread_local_top_.pending_message_obj_ = heap_.the_hole_value();
thread_local_top_.pending_message_script_ = NULL;
}
@@ -675,9 +673,7 @@
// Promote a scheduled exception to pending. Asserts
has_scheduled_exception.
Failure* PromoteScheduledException();
- void DoThrow(MaybeObject* exception,
- MessageLocation* location,
- const char* message);
+ void DoThrow(MaybeObject* exception, MessageLocation* location);
// Checks if exception should be reported and finds out if it's
// caught externally.
bool ShouldReportException(bool* can_be_caught_externally,
=======================================
--- /branches/bleeding_edge/src/messages.cc Thu Apr 7 12:52:24 2011
+++ /branches/bleeding_edge/src/messages.cc Fri Apr 8 02:39:45 2011
@@ -54,11 +54,6 @@
loc->start_pos(), *str);
}
}
-
-
-void MessageHandler::ReportMessage(const char* msg) {
- PrintF("%s\n", msg);
-}
Handle<JSMessageObject> MessageHandler::MakeMessageObject(
@@ -113,7 +108,7 @@
// to report a message as they are due to unhandled exceptions thrown in
// message callbacks.
if (isolate->in_exception_reporting()) {
- ReportMessage("uncaught exception thrown while reporting");
+ PrintF("uncaught exception thrown while reporting\n");
return;
}
isolate->set_in_exception_reporting(true);
=======================================
--- /branches/bleeding_edge/src/messages.h Thu Apr 7 12:52:24 2011
+++ /branches/bleeding_edge/src/messages.h Fri Apr 8 02:39:45 2011
@@ -89,9 +89,6 @@
// of message listeners registered in an environment
class MessageHandler {
public:
- // Report a message (w/o JS heap allocation).
- static void ReportMessage(const char* msg);
-
// Returns a message object for the API to use.
static Handle<JSMessageObject> MakeMessageObject(
const char* type,
=======================================
--- /branches/bleeding_edge/src/top.cc Thu Apr 7 12:52:24 2011
+++ /branches/bleeding_edge/src/top.cc Fri Apr 8 02:39:45 2011
@@ -534,19 +534,19 @@
// the message for stack overflow exceptions which is very likely to
// double fault with another stack overflow exception, we use a
// precomputed message.
- DoThrow(*exception, NULL, kStackOverflowMessage);
+ DoThrow(*exception, NULL);
return Failure::Exception();
}
Failure* Isolate::TerminateExecution() {
- DoThrow(heap_.termination_exception(), NULL, NULL);
+ DoThrow(heap_.termination_exception(), NULL);
return Failure::Exception();
}
Failure* Isolate::Throw(Object* exception, MessageLocation* location) {
- DoThrow(exception, location, NULL);
+ DoThrow(exception, location);
return Failure::Exception();
}
@@ -664,9 +664,7 @@
}
-void Isolate::DoThrow(MaybeObject* exception,
- MessageLocation* location,
- const char* message) {
+void Isolate::DoThrow(MaybeObject* exception, MessageLocation* location) {
ASSERT(!has_pending_exception());
HandleScope scope;
@@ -723,7 +721,6 @@
// Save the message for reporting if the the exception remains uncaught.
thread_local_top()->has_pending_message_ = report_exception;
- thread_local_top()->pending_message_ = message;
if (!message_obj.is_null()) {
thread_local_top()->pending_message_obj_ = *message_obj;
if (location != NULL) {
@@ -811,9 +808,7 @@
} else {
if (thread_local_top_.has_pending_message_) {
thread_local_top_.has_pending_message_ = false;
- if (thread_local_top_.pending_message_ != NULL) {
- MessageHandler::ReportMessage(thread_local_top_.pending_message_);
- } else if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
+ if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
HandleScope scope;
Handle<Object> message_obj(thread_local_top_.pending_message_obj_);
if (thread_local_top_.pending_message_script_ != NULL) {
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Thu Apr 7 12:52:24 2011
+++ /branches/bleeding_edge/test/cctest/test-api.cc Fri Apr 8 02:39:45 2011
@@ -2661,6 +2661,21 @@
CHECK(message_received);
v8::V8::RemoveMessageListeners(check_message);
}
+
+
+TEST(APIStackOverflowAndVerboseTryCatch) {
+ message_received = false;
+ v8::HandleScope scope;
+ v8::V8::AddMessageListener(receive_message);
+ LocalContext context;
+ v8::TryCatch try_catch;
+ try_catch.SetVerbose(true);
+ Local<Value> result = CompileRun("function foo() { foo(); } foo();");
+ CHECK(try_catch.HasCaught());
+ CHECK(result.IsEmpty());
+ CHECK(message_received);
+ v8::V8::RemoveMessageListeners(receive_message);
+}
THREADED_TEST(ExternalScriptException) {
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev