Fix shutting down, other minor cleanups

This commit is contained in:
2016-08-14 17:46:29 +01:00
parent 8ebe6c2c4e
commit da93eda0be
7 changed files with 98 additions and 88 deletions

View File

@ -20,16 +20,11 @@ V8Instance::V8Instance(std::string guild_id, std::map<std::string, DiscordObject
create();
}
V8Instance::~V8Instance() {
clean_up();
}
void V8Instance::create() {
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = ArrayBuffer::Allocator::NewDefaultAllocator();
isolate = Isolate::New(create_params);
isolate->Enter();
Logger::write("[v8] Created isolate", Logger::LogLevel::Debug);
Isolate::Scope isolate_scope(isolate);
@ -661,18 +656,6 @@ void V8Instance::js_shuffle(const v8::FunctionCallbackInfo<v8::Value> &args) {
}
}
void V8Instance::clean_up() {
Logger::write("[v8] Cleaning up", Logger::LogLevel::Debug);
isolate->Exit();
isolate->Dispose();
}
void V8Instance::reload() {
clean_up();
create();
}
void V8Instance::exec_js(std::string js, DiscordObjects::Channel *channel, DiscordObjects::GuildMember *sender, std::string args) {
HandleScope handle_scope(isolate);
Local<Context> context = Local<Context>::New(isolate, context_);

View File

@ -22,12 +22,9 @@ class V8Instance {
public:
V8Instance(std::string guild_id, std::map<std::string, DiscordObjects::Guild> *guilds,
std::map<std::string, DiscordObjects::Channel> *channels, std::map<std::string, DiscordObjects::User> *users, std::map<std::string, DiscordObjects::Role> *roles);
~V8Instance();
void reload();
void exec_js(std::string js, DiscordObjects::Channel *channel, DiscordObjects::GuildMember *sender, std::string args = "");
private:
void clean_up();
void create();
Local<Context> create_context();