From dfb2c79cbb0475c74f13b7ca9d42188957675d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 7 Mar 2015 09:22:47 +0100 Subject: [PATCH] javascript: catch and display exceptions when running scripts/functions --- src/plugins/javascript/weechat-js-v8.cpp | 35 ++++++++++++- src/plugins/javascript/weechat-js.cpp | 66 ++++++++++++++---------- 2 files changed, 73 insertions(+), 28 deletions(-) diff --git a/src/plugins/javascript/weechat-js-v8.cpp b/src/plugins/javascript/weechat-js-v8.cpp index caeaafee8..6966af13e 100644 --- a/src/plugins/javascript/weechat-js-v8.cpp +++ b/src/plugins/javascript/weechat-js-v8.cpp @@ -32,6 +32,14 @@ extern "C" #include "weechat-js.h" #include "weechat-js-v8.h" +#define PRINT_EXCEPTION \ + Local exception = trycatch.Exception(); \ + String::Utf8Value str_exception(exception); \ + weechat_printf (NULL, \ + weechat_gettext ("%s%s: exception: %s"), \ + weechat_prefix ("error"), JS_PLUGIN_NAME, \ + *str_exception); + using namespace v8; @@ -84,11 +92,26 @@ WeechatJsV8::load(const char *source) bool WeechatJsV8::execScript() { + v8::TryCatch trycatch; + this->context = Context::New(NULL, this->global); Context::Scope context_scope(this->context); Handle