/* * weechat-js-v8.cpp - v8 javascript functions * * Copyright (C) 2013 Koka El Kiwi * Copyright (C) 2015-2017 Sébastien Helleu * * This file is part of WeeChat, the extensible chat client. * * WeeChat is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * WeeChat is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WeeChat. If not, see . */ #undef _ #include extern "C" { #include "../weechat-plugin.h" #include "../plugin-script.h" } #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; /* * Constructor. */ WeechatJsV8::WeechatJsV8() { this->global = ObjectTemplate::New(); } /* * Destructor. */ WeechatJsV8::~WeechatJsV8() { this->context.Dispose(); } /* * Loads a javascript script. */ bool WeechatJsV8::load(Handle source) { this->source = source; return true; } /* * Loads a javascript script. */ bool WeechatJsV8::load(const char *source) { Handle src = String::New(source); return this->load(src); } /* * Executes a javascript script. */ bool WeechatJsV8::execScript() { v8::TryCatch trycatch; this->context = Context::New(NULL, this->global); Context::Scope context_scope(this->context); Handle