Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

using namespace v8;

void InitAll(Handle<Object> exports, Handle<Object> module) {
void InitAll(Local<Object> exports, Local<Object> module) {
Tuntap::Init(module);
}

Expand Down
49 changes: 28 additions & 21 deletions src/tuntap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ Tuntap::~Tuntap() {
delete[] this->read_buff;
}

void Tuntap::Init(Handle<Object> module) {
void Tuntap::Init(Local<Object> module) {
Isolate* isolate = module->GetIsolate();
Local<Context> context = isolate->GetCurrentContext();

// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
Expand All @@ -62,14 +63,15 @@ void Tuntap::Init(Handle<Object> 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<Value>& args) {
Isolate* isolate = args.GetIsolate();
HandleScope scope(isolate);
Local<Context> context = isolate->GetCurrentContext();
bool ret;
std::string err_str;
Local<Object> main_obj;
Expand All @@ -80,7 +82,7 @@ void Tuntap::New(const FunctionCallbackInfo<Value>& 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;
Expand All @@ -100,7 +102,7 @@ void Tuntap::New(const FunctionCallbackInfo<Value>& args) {
}
}

bool Tuntap::construct(Handle<Object> main_obj, std::string &error) {
bool Tuntap::construct(Local<Object> main_obj, std::string &error) {
Isolate* isolate = main_obj->GetIsolate();
HandleScope scope(isolate);
Local<Array> keys_arr;
Expand Down Expand Up @@ -195,6 +197,7 @@ void Tuntap::writeBuffer(const FunctionCallbackInfo<Value>& args) {
}
void Tuntap::open(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
HandleScope scope(isolate);
Local<Object> main_obj = Object::New(isolate);
std::string err_str;
Expand All @@ -212,7 +215,7 @@ void Tuntap::open(const FunctionCallbackInfo<Value>& args) {
return;
}

main_obj = args[0]->ToObject();
main_obj = args[0]->ToObject(context).ToLocalChecked();
}

ret = obj->construct(main_obj, err_str);
Expand Down Expand Up @@ -246,6 +249,7 @@ void Tuntap::close(const FunctionCallbackInfo<Value>& args) {

void Tuntap::set(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
HandleScope scope(isolate);
Tuntap *obj = ObjectWrap::Unwrap<Tuntap>(args.This());
std::vector<tuntap_itf_opts_t::option_e> options;
Expand All @@ -260,20 +264,20 @@ void Tuntap::set(const FunctionCallbackInfo<Value>& 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)
Expand Down Expand Up @@ -304,7 +308,7 @@ void Tuntap::set(const FunctionCallbackInfo<Value>& 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;
Expand Down Expand Up @@ -341,7 +345,7 @@ void Tuntap::unset(const FunctionCallbackInfo<Value>& 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 = "";
Expand Down Expand Up @@ -401,17 +405,20 @@ void Tuntap::startRead(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(args.This());
}

void Tuntap::objset(Handle<Object> obj) {
void Tuntap::objset(Local<Object> obj) {
Isolate* isolate = obj->GetIsolate();
Local<Context> context = isolate->GetCurrentContext();

Local<Array> keys_arr;
Local<Value> key;
Local<Value> 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) {
Expand All @@ -434,21 +441,21 @@ void Tuntap::objset(Handle<Object> 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;
Expand Down
6 changes: 3 additions & 3 deletions src/tuntap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class Tuntap : public node::ObjectWrap {
public:
static void Init(v8::Handle<v8::Object> module);
static void Init(v8::Local<v8::Object> module);

private:
Tuntap();
Expand Down Expand Up @@ -62,8 +62,8 @@ class Tuntap : public node::ObjectWrap {
int size;
};

bool construct(v8::Handle<v8::Object> main_obj, std::string &error);
void objset(v8::Handle<v8::Object> obj);
bool construct(v8::Local<v8::Object> main_obj, std::string &error);
void objset(v8::Local<v8::Object> obj);
static void writeBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
static void open(const v8::FunctionCallbackInfo<v8::Value>& args);
static void close(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down