[V8] Run-time exception in onmessage handler is not forwarded to the
authorjianli@chromium.org <jianli@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Sep 2009 00:07:49 +0000 (00:07 +0000)
committerjianli@chromium.org <jianli@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Sep 2009 00:07:49 +0000 (00:07 +0000)
worker object.
https://bugs.webkit.org/show_bug.cgi?id=28980

Reviewed by David Levin.

The previous fix was partially reverted due to a reliability build break
in chromium. The break happens when an exception is thrown without
setting a message. We need to check for this scenario and handle it.

Tested by worker-close.html.

* bindings/v8/V8AbstractEventListener.cpp:
(WebCore::V8AbstractEventListener::invokeEventHandler):
* bindings/v8/V8Utilities.cpp:
(WebCore::reportException):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@48610 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bindings/v8/V8AbstractEventListener.cpp
WebCore/bindings/v8/V8Utilities.cpp

index 8773a8d..3fdd939 100644 (file)
@@ -1,3 +1,22 @@
+2009-09-21  Jian Li  <jianli@chromium.org>
+
+        Reviewed by David Levin.
+
+        [V8] Run-time exception in onmessage handler is not forwarded to the
+        worker object.
+        https://bugs.webkit.org/show_bug.cgi?id=28980
+
+        The previous fix was partially reverted due to a reliability build break
+        in chromium. The break happens when an exception is thrown without
+        setting a message. We need to check for this scenario and handle it.
+
+        Tested by worker-close.html.
+
+        * bindings/v8/V8AbstractEventListener.cpp:
+        (WebCore::V8AbstractEventListener::invokeEventHandler):
+        * bindings/v8/V8Utilities.cpp:
+        (WebCore::reportException):
+
 2009-09-21  Greg Bolsinga  <bolsinga@apple.com>
 
         Reviewed by Simon Fraser & Sam Weinig.
index 588ea6c..c0efea5 100644 (file)
@@ -82,10 +82,17 @@ void V8AbstractEventListener::invokeEventHandler(v8::Handle<v8::Context> v8Conte
         tryCatch.Reset();
 
         // Call the event handler.
+        tryCatch.SetVerbose(false); // We do not want to report the exception to the inspector console.
         returnValue = callListenerFunction(jsEvent, event, isWindowEvent);
-        tryCatch.Reset();
+
+        // If an error occurs while handling the event, it should be reported.
+        if (tryCatch.HasCaught()) {
+            reportException(0, tryCatch);
+            tryCatch.Reset();
+        }
 
         // Restore the old event. This must be done for all exit paths through this method.
+        tryCatch.SetVerbose(true);
         if (savedEvent.IsEmpty())
             v8Context->Global()->SetHiddenValue(eventSymbol, v8::Undefined());
         else
index a8aa924..f8f7d7c 100644 (file)
@@ -129,8 +129,21 @@ ScriptExecutionContext* getScriptExecutionContext(ScriptState* scriptState)
 
 void reportException(ScriptState* scriptState, v8::TryCatch& exceptionCatcher)
 {
+    String errorMessage;
+    int lineNumber = 0;
+    String sourceURL;
+
+    // There can be a situation that an exception is thrown without setting a message.
     v8::Local<v8::Message> message = exceptionCatcher.Message();
-    getScriptExecutionContext(scriptState)->reportException(toWebCoreString(message->Get()), message->GetLineNumber(), toWebCoreString(message->GetScriptResourceName()));
+    if (message.IsEmpty())
+        errorMessage = toWebCoreString(exceptionCatcher.Exception()->ToString());
+    else {
+        errorMessage = toWebCoreString(message->Get());
+        lineNumber = message->GetLineNumber();
+        sourceURL = toWebCoreString(message->GetScriptResourceName());
+    }
+
+    getScriptExecutionContext(scriptState)->reportException(errorMessage, lineNumber, sourceURL);
     exceptionCatcher.Reset();
 }