Skip to content

Commit

Permalink
Upgrade to use Nan>=2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Lawrence committed Aug 25, 2015
1 parent fa73496 commit c413e35
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -2,5 +2,4 @@ language: node_js
node_js:
- "0.12"
- "0.10"
- "0.8"

5 changes: 2 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "oid",
"version": "1.1.0",
"version": "1.2.0",
"keywords":
["object", "id", "identity", "hash", "hashcode", "objid", "oid"],
"description":
Expand Down Expand Up @@ -30,9 +30,8 @@
"node": ">=0.8.0"
},
"dependencies": {
"nan": "~1.8"
"nan": "^2.0.5"
},

"scripts": {
"install": "node-gyp configure build; mkdir -p bin; mv build/Release/*.node bin",
"test": "node test/test.js"
Expand Down
51 changes: 24 additions & 27 deletions src/oidNative.cc
Expand Up @@ -7,37 +7,34 @@
using namespace v8;

NAN_METHOD(ObjectIdHash) {
NanScope();

Local<Value> val = args[0];
Local<Value> val = info[0];
if (val->IsNull()) {
NanReturnValue(NanNew<Integer>(99961)); // A prime number.
}
info.GetReturnValue().Set(Nan::New<Integer>(99961)); // A prime number.

Local<Object> obj = val->ToObject();
if (obj.IsEmpty()) {
return NanThrowError("Not an object.");
}
} else {
Local<Object> obj = val->ToObject();
if (obj.IsEmpty()) {
return Nan::ThrowError("Not an object.");
}

int hash = obj->GetIdentityHash() & 0x7fffffff;
int hash = obj->GetIdentityHash() & 0x7fffffff;

if (hash == 0) {
// V8 guarantees the original hash is non-zero, but it doesn't
// guarantee that it's not MININT. We want to guarantee a positive
// number (that is non-zero and non-negative), and so we have to
// deal with this case specially.
hash = 1;
}
if (hash == 0) {
// V8 guarantees the original hash is non-zero, but it doesn't
// guarantee that it's not MININT. We want to guarantee a positive
// number (that is non-zero and non-negative), and so we have to
// deal with this case specially.
hash = 1;
}

NanReturnValue(NanNew<Integer>(hash));
info.GetReturnValue().Set(Nan::New<Integer>(hash));
}
}

NAN_METHOD(NumberIdHash) {
NanScope();

Local<Number> num = args[0]->ToNumber();
Local<Number> num = info[0]->ToNumber();
if (num.IsEmpty()) {
return NanThrowError("Not a number.");
return Nan::ThrowError("Not a number.");
}

union {
Expand All @@ -59,14 +56,14 @@ NAN_METHOD(NumberIdHash) {
hash = 1;
}

NanReturnValue(NanNew<Number>((double) hash));
info.GetReturnValue().Set(Nan::New<Number>((double) hash));
}

void init(Handle<Object> target) {
target->Set(NanNew<String>("objectIdHash"),
NanNew<FunctionTemplate>(ObjectIdHash)->GetFunction());
target->Set(NanNew<String>("numberIdHash"),
NanNew<FunctionTemplate>(NumberIdHash)->GetFunction());
target->Set(Nan::New<String>("objectIdHash").ToLocalChecked(),
Nan::New<FunctionTemplate>(ObjectIdHash)->GetFunction());
target->Set(Nan::New<String>("numberIdHash").ToLocalChecked(),
Nan::New<FunctionTemplate>(NumberIdHash)->GetFunction());
}

NODE_MODULE(oidNative, init)

0 comments on commit c413e35

Please sign in to comment.