diff --git a/src/module.cc b/src/module.cc index 33a1c40..be11cab 100644 --- a/src/module.cc +++ b/src/module.cc @@ -23,7 +23,7 @@ using namespace v8; -void InitAll(Handle exports, Handle module) { +void InitAll(Local exports, Local module) { Tuntap::Init(module); } diff --git a/src/tuntap.cc b/src/tuntap.cc index 8c108db..6cada03 100644 --- a/src/tuntap.cc +++ b/src/tuntap.cc @@ -41,8 +41,9 @@ Tuntap::~Tuntap() { delete[] this->read_buff; } -void Tuntap::Init(Handle module) { +void Tuntap::Init(Local module) { Isolate* isolate = module->GetIsolate(); + Local context = isolate->GetCurrentContext(); // Prepare constructor template Local tpl = FunctionTemplate::New(isolate, New); @@ -62,14 +63,15 @@ void Tuntap::Init(Handle module) { #undef SETFUNC - constructor.Reset(isolate, tpl->GetFunction()); + constructor.Reset(isolate, tpl->GetFunction(context).ToLocalChecked()); - module->Set(String::NewFromUtf8(isolate, "exports"), tpl->GetFunction()); + module->Set(String::NewFromUtf8(isolate, "exports"), tpl->GetFunction(context).ToLocalChecked()); } void Tuntap::New(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); HandleScope scope(isolate); + Local context = isolate->GetCurrentContext(); bool ret; std::string err_str; Local main_obj; @@ -80,7 +82,7 @@ void Tuntap::New(const FunctionCallbackInfo& args) { obj = new Tuntap(); obj->Wrap(args.This()); if(args[0]->IsObject()) { - main_obj = args[0]->ToObject(); + main_obj = args[0]->ToObject(context).ToLocalChecked(); ret = obj->construct(main_obj, err_str); if(ret == false) { obj->fd = -1; @@ -100,7 +102,7 @@ void Tuntap::New(const FunctionCallbackInfo& args) { } } -bool Tuntap::construct(Handle main_obj, std::string &error) { +bool Tuntap::construct(Local main_obj, std::string &error) { Isolate* isolate = main_obj->GetIsolate(); HandleScope scope(isolate); Local keys_arr; @@ -195,6 +197,7 @@ void Tuntap::writeBuffer(const FunctionCallbackInfo& args) { } void Tuntap::open(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); HandleScope scope(isolate); Local main_obj = Object::New(isolate); std::string err_str; @@ -212,7 +215,7 @@ void Tuntap::open(const FunctionCallbackInfo& args) { return; } - main_obj = args[0]->ToObject(); + main_obj = args[0]->ToObject(context).ToLocalChecked(); } ret = obj->construct(main_obj, err_str); @@ -246,6 +249,7 @@ void Tuntap::close(const FunctionCallbackInfo& args) { void Tuntap::set(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); + Local context = isolate->GetCurrentContext(); HandleScope scope(isolate); Tuntap *obj = ObjectWrap::Unwrap(args.This()); std::vector options; @@ -260,20 +264,20 @@ void Tuntap::set(const FunctionCallbackInfo& args) { return; } - main_obj = args[0]->ToObject(); + main_obj = args[0]->ToObject(context).ToLocalChecked(); - if(main_obj->Has(String::NewFromUtf8(isolate, "type")) || main_obj->Has(String::NewFromUtf8(isolate, "name"))) { + if(main_obj->Has(context, String::NewFromUtf8(isolate, "type")).ToChecked() || main_obj->Has(context, String::NewFromUtf8(isolate, "name")).ToChecked()) { TT_THROW_TYPE("Cannot set name and type from this function!"); return; } obj->objset(main_obj); - keys_arr = main_obj->GetPropertyNames(); + keys_arr = main_obj->GetPropertyNames(context).ToLocalChecked(); for (unsigned int i = 0, limiti = keys_arr->Length(); i < limiti; i++) { key = keys_arr->Get(i); val = main_obj->Get(key); - String::Utf8Value key_str(key->ToString()); + String::Utf8Value key_str(isolate, key); if(strcmp(*key_str, "addr") == 0) { if(obj->fd) @@ -304,7 +308,7 @@ void Tuntap::set(const FunctionCallbackInfo& args) { options.push_back(tuntap_itf_opts_t::OPT_RUNNING); } else if(strcmp(*key_str, "ethtype_comp") == 0) { - String::Utf8Value val_str(val->ToString()); + String::Utf8Value val_str(isolate, val); if(strcmp(*val_str, "none") == 0) obj->itf_opts.ethtype_comp = TUNTAP_ETCOMP_NONE; @@ -341,7 +345,7 @@ void Tuntap::unset(const FunctionCallbackInfo& args) { for (unsigned int i = 0, limiti = keys_arr->Length(); i < limiti; i++) { val = keys_arr->Get(i); - String::Utf8Value val_str(val->ToString()); + String::Utf8Value val_str(isolate, val); if(strcmp(*val_str, "addr") == 0) { obj->itf_opts.addr = ""; @@ -401,17 +405,20 @@ void Tuntap::startRead(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(args.This()); } -void Tuntap::objset(Handle obj) { +void Tuntap::objset(Local obj) { + Isolate* isolate = obj->GetIsolate(); + Local context = isolate->GetCurrentContext(); + Local keys_arr; Local key; Local val; - keys_arr = obj->GetPropertyNames(); + keys_arr = obj->GetPropertyNames(context).ToLocalChecked(); for (unsigned int i = 0, limiti = keys_arr->Length(); i < limiti; i++) { key = keys_arr->Get(i); val = obj->Get(key); - String::Utf8Value key_str(key->ToString()); - String::Utf8Value val_str(val->ToString()); + String::Utf8Value key_str(isolate, key); + String::Utf8Value val_str(isolate, val); if(strcmp(*key_str, "type") == 0) { if(strcmp(*val_str, "tun") == 0) { @@ -434,21 +441,21 @@ void Tuntap::objset(Handle obj) { this->itf_opts.dest = *val_str; } else if(strcmp(*key_str, "mtu") == 0) { - this->itf_opts.mtu = val->ToInteger()->Value(); + this->itf_opts.mtu = val->ToInteger(context).ToLocalChecked()->Value(); if(this->itf_opts.mtu <= 50) this->itf_opts.mtu = 50; } else if(strcmp(*key_str, "persist") == 0) { - this->itf_opts.is_persistant = val->ToBoolean()->Value(); + this->itf_opts.is_persistant = val->ToBoolean(context).ToLocalChecked()->Value(); } else if(strcmp(*key_str, "up") == 0) { - this->itf_opts.is_up = val->ToBoolean()->Value(); + this->itf_opts.is_up = val->ToBoolean(context).ToLocalChecked()->Value(); } else if(strcmp(*key_str, "running") == 0) { - this->itf_opts.is_running = val->ToBoolean()->Value(); + this->itf_opts.is_running = val->ToBoolean(context).ToLocalChecked()->Value(); } else if(strcmp(*key_str, "ethtype_comp") == 0) { - String::Utf8Value val_str(val->ToString()); + String::Utf8Value val_str(isolate, val); if(strcmp(*val_str, "none") == 0) this->itf_opts.ethtype_comp = TUNTAP_ETCOMP_NONE; diff --git a/src/tuntap.hh b/src/tuntap.hh index 9f2e397..69ed5e8 100644 --- a/src/tuntap.hh +++ b/src/tuntap.hh @@ -26,7 +26,7 @@ class Tuntap : public node::ObjectWrap { public: - static void Init(v8::Handle module); + static void Init(v8::Local module); private: Tuntap(); @@ -62,8 +62,8 @@ class Tuntap : public node::ObjectWrap { int size; }; - bool construct(v8::Handle main_obj, std::string &error); - void objset(v8::Handle obj); + bool construct(v8::Local main_obj, std::string &error); + void objset(v8::Local obj); static void writeBuffer(const v8::FunctionCallbackInfo& args); static void open(const v8::FunctionCallbackInfo& args); static void close(const v8::FunctionCallbackInfo& args);