Add TryCatch block to avoid crashes of renderer
authorWonYoung Choi <wy80.choi@samsung.com>
Tue, 24 May 2016 02:48:39 +0000 (11:48 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Tue, 24 May 2016 02:48:39 +0000 (11:48 +0900)
When uncatched exception is thrown in the callback, TryCatch block
is necessary in calling the callback like below.

v8::TryCatch try_catch(isolate)
func->Call(..)

extensions/renderer/runtime_ipc_client.cc

index aaae627..20da3a8 100644 (file)
@@ -40,9 +40,15 @@ void RuntimeIPCClient::JSCallback::Call(v8::Isolate* isolate,
                                         v8::Handle<v8::Value> args[]) {
   if (!callback_.IsEmpty()) {
     v8::HandleScope handle_scope(isolate);
+    v8::TryCatch try_catch(isolate);
     v8::Handle<v8::Function> func =
         v8::Local<v8::Function>::New(isolate, callback_);
     func->Call(func, 1, args);
+    if (try_catch.HasCaught()) {
+      LOGGER(ERROR) << "Exception when running Javascript callback";
+      v8::String::Utf8Value exception_str(try_catch.Exception());
+      LOGGER(ERROR) << (*exception_str);
+    }
   }
 }