From d16db5a9f39c430907c232a399b61dd34462941a Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Dec 07 2015 11:47:32 +0000 Subject: Patch in support for nan 2.x --- diff --git a/nodejs-node-stringprep-nan2.patch b/nodejs-node-stringprep-nan2.patch new file mode 100644 index 0000000..9d6938d --- /dev/null +++ b/nodejs-node-stringprep-nan2.patch @@ -0,0 +1,261 @@ +commit 43d11bffa629143625266900e5ca8efea47f335d +Author: Tom Hughes +Date: Mon Dec 7 11:38:23 2015 +0000 + + Update to nan 2.x for nodejs 4.x + + Based on https://github.com/node-xmpp/node-stringprep/tree/nan2-astro + +diff --git a/node-stringprep.cc b/node-stringprep.cc +index 4b5b371..83c272c 100644 +--- a/node-stringprep.cc ++++ b/node-stringprep.cc +@@ -13,19 +13,19 @@ class UnknownProfileException : public std::exception { + }; + + // protect constructor from GC +-static Persistent stringprep_constructor; ++static Nan::Persistent stringprep_constructor; + +-class StringPrep : public ObjectWrap { ++class StringPrep : public Nan::ObjectWrap { + public: + static void Initialize(Handle target) + { +- NanScope(); +- Local t = NanNew(New); +- NanAssignPersistent(stringprep_constructor, t); ++ Nan::HandleScope scope; ++ Local t = Nan::New(New); ++ stringprep_constructor.Reset(t); + t->InstanceTemplate()->SetInternalFieldCount(1); +- NODE_SET_PROTOTYPE_METHOD(t, "prepare", Prepare); ++ Nan::SetPrototypeMethod(t, "prepare", Prepare); + +- target->Set(NanNew("StringPrep"), t->GetFunction()); ++ target->Set(Nan::New("StringPrep").ToLocalChecked(), t->GetFunction()); + } + + bool good() const +@@ -43,11 +43,9 @@ protected: + + static NAN_METHOD(New) + { +- NanScope(); +- +- if (args.Length() >= 1 && args[0]->IsString()) ++ if (info.Length() >= 1 && info[0]->IsString()) + { +- String::Utf8Value arg0(args[0]->ToString()); ++ Nan::Utf8String arg0(info[0]->ToString()); + UStringPrepProfileType profileType; + try + { +@@ -55,27 +53,28 @@ protected: + } + catch (UnknownProfileException &) + { +- NanThrowTypeError("Unknown StringPrep profile"); +- NanReturnUndefined(); ++ Nan::ThrowTypeError("Unknown StringPrep profile"); ++ return; + } + + StringPrep *self = new StringPrep(profileType); + if (self->good()) + { +- self->Wrap(args.This()); +- NanReturnValue(args.This()); ++ self->Wrap(info.This()); ++ info.GetReturnValue().Set(info.This()); ++ return; + } + else + { + const char* err = self->errorName(); + delete self; +- NanThrowError(err); +- NanReturnUndefined(); ++ Nan::ThrowError(err); ++ return; + } + } + else { +- NanThrowTypeError("Bad argument."); +- NanReturnUndefined(); ++ Nan::ThrowTypeError("Bad argument."); ++ return; + } + } + +@@ -97,22 +96,22 @@ protected: + + static NAN_METHOD(Prepare) + { +- NanScope(); +- +- if (args.Length() >= 1 && args[0]->IsString()) ++ if (info.Length() >= 1 && info[0]->IsString()) + { +- StringPrep *self = ObjectWrap::Unwrap(args.This()); +- String::Value arg0(args[0]->ToString()); +- NanReturnValue(self->prepare(arg0)); ++ StringPrep *self = Nan::ObjectWrap::Unwrap(info.This()); ++ String::Value arg0(info[0]->ToString()); ++ info.GetReturnValue().Set(self->prepare(arg0)); ++ return; + } + else { +- NanThrowTypeError("Bad argument."); +- NanReturnUndefined(); ++ Nan::ThrowTypeError("Bad argument."); ++ return; + } + } + +- Handle prepare(String::Value &str) ++ Local prepare(String::Value &str) + { ++ Nan::EscapableHandleScope scope; + size_t destLen = str.length() + 1; + UChar *dest = NULL; + while(!dest) +@@ -135,23 +134,23 @@ protected: + { + // other error, just bail out + delete[] dest; +- NanThrowError(errorName()); +- return NanUndefined(); ++ Nan::ThrowError(errorName()); ++ return scope.Escape(Nan::Undefined()); + } + else + destLen = w; + } + +- Local result = NanNew(dest, destLen); ++ Local result = Nan::New(dest, destLen).ToLocalChecked(); + delete[] dest; +- return result; ++ return scope.Escape(result); + } + + private: + UStringPrepProfile *profile; + UErrorCode error; + +- static enum UStringPrepProfileType parseProfileType(String::Utf8Value &profile) ++ static enum UStringPrepProfileType parseProfileType(Nan::Utf8String &profile) + throw(UnknownProfileException) + { + if (strcasecmp(*profile, "nameprep") == 0) +@@ -192,12 +191,10 @@ private: + + NAN_METHOD(ToUnicode) + { +- NanScope(); +- +- if (args.Length() >= 2 && args[0]->IsString() && args[1]->IsInt32()) ++ if (info.Length() >= 2 && info[0]->IsString() && info[1]->IsInt32()) + { +- String::Value str(args[0]->ToString()); +- int32_t options = args[1]->ToInt32()->Value(); ++ String::Value str(info[0]->ToString()); ++ int32_t options = info[1]->ToInt32()->Value(); + + // ASCII encoding (xn--*--*) should be longer than Unicode + size_t destLen = str.length() + 1; +@@ -222,31 +219,30 @@ NAN_METHOD(ToUnicode) + { + // other error, just bail out + delete[] dest; +- NanThrowError(u_errorName(error)); +- NanReturnUndefined(); ++ Nan::ThrowError(u_errorName(error)); ++ return; + } + else + destLen = w; + } + +- Local result = NanNew(dest, destLen); ++ Local result = Nan::New(dest, destLen).ToLocalChecked(); + delete[] dest; +- NanReturnValue(result); ++ info.GetReturnValue().Set(result); ++ return; + } + else { +- NanThrowTypeError("Bad argument."); +- NanReturnUndefined(); ++ Nan::ThrowTypeError("Bad argument."); ++ return; + } + } + + NAN_METHOD(ToASCII) + { +- NanScope(); +- +- if (args.Length() >= 2 && args[0]->IsString() && args[1]->IsInt32()) ++ if (info.Length() >= 2 && info[0]->IsString() && info[1]->IsInt32()) + { +- String::Value str(args[0]->ToString()); +- int32_t options = args[1]->ToInt32()->Value(); ++ String::Value str(info[0]->ToString()); ++ int32_t options = info[1]->ToInt32()->Value(); + + // find out length first + UErrorCode error = U_ZERO_ERROR; +@@ -270,28 +266,28 @@ NAN_METHOD(ToASCII) + { + // other error, just bail out + delete[] dest; +- NanThrowError(u_errorName(error)); +- NanReturnUndefined(); ++ Nan::ThrowError(u_errorName(error)); ++ return; + } + +- Local result = NanNew(dest, destLen); ++ Local result = Nan::New(dest, destLen).ToLocalChecked(); + delete[] dest; +- NanReturnValue(result); ++ info.GetReturnValue().Set(result); ++ return; + } + else { +- NanThrowTypeError("Bad argument."); +- NanReturnUndefined(); ++ Nan::ThrowTypeError("Bad argument."); ++ return; + } + } + + /*** Initialization ***/ + +-extern "C" void init(Handle target) ++NAN_MODULE_INIT(init) + { +- NanScope(); + StringPrep::Initialize(target); +- NODE_SET_METHOD(target, "toUnicode", ToUnicode); +- NODE_SET_METHOD(target, "toASCII", ToASCII); ++ Nan::SetMethod(target, "toUnicode", ToUnicode); ++ Nan::SetMethod(target, "toASCII", ToASCII); + } + + NODE_MODULE(node_stringprep, init) +diff --git a/package.json b/package.json +index bc1ccdf..cc2970a 100644 +--- a/package.json ++++ b/package.json +@@ -14,7 +14,7 @@ + "dependencies": { + "bindings": "~1.2.1", + "debug": "~2.2.0", +- "nan": "~1.8.4" ++ "nan": "^2.1.0" + }, + "devDependencies": { + "grunt": "~0.4.2", diff --git a/nodejs-node-stringprep.spec b/nodejs-node-stringprep.spec index d0f58ef..b52bfd1 100644 --- a/nodejs-node-stringprep.spec +++ b/nodejs-node-stringprep.spec @@ -4,12 +4,14 @@ Name: nodejs-node-stringprep Version: 0.7.3 -Release: 2%{?dist} +Release: 3%{?dist} Summary: ICU StringPrep profiles for Node.js License: MIT Group: System Environment/Libraries URL: https://github.com/node-xmpp/node-stringprep Source0: https://registry.npmjs.org/node-stringprep/-/node-stringprep-%{version}.tgz +# https://github.com/node-xmpp/node-stringprep/pull/79 +Patch0: nodejs-node-stringprep-nan2.patch %if 0%{?fedora} >= 19 ExclusiveArch: %{nodejs_arches} @@ -21,7 +23,7 @@ BuildRequires: libicu-devel BuildRequires: nodejs-packaging BuildRequires: node-gyp BuildRequires: npm(bindings) -BuildRequires: npm(nan) >= 1.8.4, npm(nan) < 2.0.0 +BuildRequires: npm(nan) >= 2.1.0 # The project uses Grunt, but there isn't anything fancy being done so we # can just use mocha directly. @@ -38,7 +40,7 @@ to be fast. %prep -%setup -q -n package +%autosetup -p1 -n package %nodejs_fixdep bindings '~1.1' @@ -75,6 +77,9 @@ install -p -D -m0755 build/Release/node_stringprep.node \ %changelog +* Mon Dec 7 2015 Tom Hughes - 0.7.3-3 +- Patch in support for nan 2.x + * Wed Nov 25 2015 Tom Hughes - 0.7.3-2 - Export LDFLAGS for hardened build support