diff --git a/package.json b/package.json index cc6ee44..824acc3 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,6 @@ }, "license": "MIT", "dependencies": { - "nan": "2.12.0" + "nan": "2.13.2" } } diff --git a/src/addon.cc b/src/addon.cc index f0aab0c..e17ef16 100644 --- a/src/addon.cc +++ b/src/addon.cc @@ -7,26 +7,54 @@ using namespace v8; void init(Local exports) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Local context = isolate->GetCurrentContext(); + v8::HandleScope handle_scope(isolate); Nan::Set(exports, Nan::New("version").ToLocalChecked(), Nan::New(VERSION).ToLocalChecked()); - Nan::Set(exports, - Nan::New("verify").ToLocalChecked(), - Nan::New(verify)->GetFunction()); + { + v8::Local method; + Nan::New(verify)->GetFunction(context).ToLocal(&method); + Nan::Set(exports, + Nan::New("verify").ToLocalChecked(), + method + ); + } - Nan::Set(exports, - Nan::New("getAltNames").ToLocalChecked(), - Nan::New(get_altnames)->GetFunction()); - Nan::Set(exports, - Nan::New("getSubject").ToLocalChecked(), - Nan::New(get_subject)->GetFunction()); - Nan::Set(exports, - Nan::New("getIssuer").ToLocalChecked(), - Nan::New(get_issuer)->GetFunction()); - Nan::Set(exports, - Nan::New("parseCert").ToLocalChecked(), - Nan::New(parse_cert)->GetFunction()); + { + v8::Local method; + Nan::New(get_altnames)->GetFunction(context).ToLocal(&method); + Nan::Set(exports, + Nan::New("getAltNames").ToLocalChecked(), + method + ); + } + { + v8::Local method; + Nan::New(get_subject)->GetFunction(context).ToLocal(&method); + Nan::Set(exports, + Nan::New("getSubject").ToLocalChecked(), + method + ); + } + { + v8::Local method; + Nan::New(get_issuer)->GetFunction(context).ToLocal(&method); + Nan::Set(exports, + Nan::New("getIssuer").ToLocalChecked(), + method + ); + } + { + v8::Local method; + Nan::New(parse_cert)->GetFunction(context).ToLocal(&method); + Nan::Set(exports, + Nan::New("parseCert").ToLocalChecked(), + method + ); + } } NODE_MODULE(x509, init) diff --git a/src/x509.cc b/src/x509.cc index 00e02ae..c7141f4 100644 --- a/src/x509.cc +++ b/src/x509.cc @@ -28,6 +28,7 @@ static const char *MISSING[4][2] = { }; std::string parse_args(const Nan::FunctionCallbackInfo& info) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); if (info.Length() == 0) { Nan::ThrowTypeError("Must provide a certificate string."); return std::string(); @@ -38,12 +39,12 @@ std::string parse_args(const Nan::FunctionCallbackInfo& info) { return std::string(); } - if (info[0]->ToString()->Length() == 0) { + if (info[0]->ToString(isolate)->Length() == 0) { Nan::ThrowTypeError("Certificate argument provided, but left blank."); return std::string(); } - return *Nan::Utf8String(info[0]->ToString()); + return *Nan::Utf8String(info[0]->ToString(isolate)); } @@ -51,9 +52,10 @@ std::string parse_args(const Nan::FunctionCallbackInfo& info) { NAN_METHOD(verify) { Nan::HandleScope scope; OpenSSL_add_all_algorithms(); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); - std::string cert_path = *String::Utf8Value(info[0]->ToString()); - std::string ca_bundlestr = *String::Utf8Value(info[1]->ToString()); + std::string cert_path = *String::Utf8Value(isolate, info[0]->ToString(isolate)); + std::string ca_bundlestr = *String::Utf8Value(isolate, info[1]->ToString(isolate)); X509_STORE *store = NULL; X509_STORE_CTX *verify_ctx = NULL; @@ -112,10 +114,11 @@ NAN_METHOD(verify) { NAN_METHOD(get_altnames) { Nan::HandleScope scope; std::string parsed_arg = parse_args(info); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); if(parsed_arg.size() == 0) { info.GetReturnValue().SetUndefined(); } - Local exports(try_parse(parsed_arg)->ToObject()); + Local exports(try_parse(parsed_arg)->ToObject(isolate)); Local key = Nan::New("altNames").ToLocalChecked(); info.GetReturnValue().Set( Nan::Get(exports, key).ToLocalChecked()); @@ -125,10 +128,11 @@ NAN_METHOD(get_altnames) { NAN_METHOD(get_subject) { Nan::HandleScope scope; std::string parsed_arg = parse_args(info); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); if(parsed_arg.size() == 0) { info.GetReturnValue().SetUndefined(); } - Local exports(try_parse(parsed_arg)->ToObject()); + Local exports(try_parse(parsed_arg)->ToObject(isolate)); Local key = Nan::New("subject").ToLocalChecked(); info.GetReturnValue().Set( Nan::Get(exports, key).ToLocalChecked()); @@ -137,11 +141,12 @@ NAN_METHOD(get_subject) { NAN_METHOD(get_issuer) { Nan::HandleScope scope; + v8::Isolate* isolate = v8::Isolate::GetCurrent(); std::string parsed_arg = parse_args(info); if(parsed_arg.size() == 0) { info.GetReturnValue().SetUndefined(); } - Local exports(try_parse(parsed_arg)->ToObject()); + Local exports(try_parse(parsed_arg)->ToObject(isolate)); Local key = Nan::New("issuer").ToLocalChecked(); info.GetReturnValue().Set( Nan::Get(exports, key).ToLocalChecked()); @@ -150,11 +155,12 @@ NAN_METHOD(get_issuer) { NAN_METHOD(parse_cert) { Nan::HandleScope scope; + v8::Isolate* isolate = v8::Isolate::GetCurrent(); std::string parsed_arg = parse_args(info); if(parsed_arg.size() == 0) { info.GetReturnValue().SetUndefined(); } - Local exports(try_parse(parsed_arg)->ToObject()); + Local exports(try_parse(parsed_arg)->ToObject(isolate)); info.GetReturnValue().Set(exports); ERR_clear_error(); } @@ -444,6 +450,7 @@ Local parse_serial(ASN1_INTEGER *serial) { Local parse_date(ASN1_TIME *date) { Nan::EscapableHandleScope scope; + v8::Isolate* isolate = v8::Isolate::GetCurrent(); BIO *bio; BUF_MEM *bm; char formatted[64]; @@ -459,7 +466,7 @@ Local parse_date(ASN1_TIME *date) { Local global = Nan::GetCurrentContext()->Global(); Local DateObject = Nan::Get(global, - Nan::New("Date").ToLocalChecked()).ToLocalChecked()->ToObject(); + Nan::New("Date").ToLocalChecked()).ToLocalChecked()->ToObject(isolate); return scope.Escape(Nan::CallAsConstructor(DateObject, 1, args).ToLocalChecked()); }