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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"readmeFilename": "README.md",
"dependencies": {
"bindings": "1.2.x",
"nan": "^2.4.0"
"nan": "^2.14.1"
}
}
44 changes: 21 additions & 23 deletions src/Int64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ using namespace v8;

Nan::Persistent<Function> Int64::constructor;

void Int64::Init(Handle<Object> exports) {
Nan::HandleScope scope;

NAN_MODULE_INIT(Int64::Init) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Int64").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Expand All @@ -41,21 +39,21 @@ void Int64::Init(Handle<Object> exports) {
Nan::SetPrototypeMethod(tpl, "add", Add);
Nan::SetPrototypeMethod(tpl, "sub", Sub);

constructor.Reset(tpl->GetFunction());
exports->Set(Nan::New("Int64").ToLocalChecked(), tpl->GetFunction());
constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
Nan::Set(target, Nan::New("Int64").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
}

Int64::Int64() {
mValue = 0;
}

Int64::Int64(const Local<Number>& n) {
mValue = static_cast<uint64_t>(n->NumberValue());
mValue = static_cast<uint64_t>(Nan::To<int64_t>(n).ToChecked());
}

Int64::Int64(const Local<Number>& hi, const Local<Number>& lo) {
uint32_t highBits = static_cast<uint32_t>(hi->NumberValue());
uint32_t lowBits = static_cast<uint32_t>(lo->NumberValue());
uint32_t highBits = static_cast<uint32_t>(Nan::To<uint32_t>(hi).ToChecked());
uint32_t lowBits = static_cast<uint32_t>(Nan::To<uint32_t>(lo).ToChecked());
mValue =
(static_cast<uint64_t>(highBits) << 32) |
(static_cast<uint64_t>(lowBits));
Expand Down Expand Up @@ -84,7 +82,7 @@ NAN_METHOD(Int64::New) {
if (info[0]->IsNumber()) {
obj = new Int64(Nan::To<v8::Number>(info[0]).ToLocalChecked());
} else if (info[0]->IsString()) {
obj = new Int64(info[0]->ToString());
obj = new Int64(Nan::To<String>(info[0]).ToLocalChecked());
}
} else if (info.Length() == 2) {
if (info[0]->IsNumber() && info[1]->IsNumber()) {
Expand Down Expand Up @@ -171,7 +169,7 @@ NAN_METHOD(Int64::Equals) {
Nan::ThrowTypeError("Object expected");
}
Int64* obj = ObjectWrap::Unwrap<Int64>(info.Holder());
Int64* otherObj = ObjectWrap::Unwrap<Int64>(info[0]->ToObject());
Int64* otherObj = ObjectWrap::Unwrap<Int64>(Nan::To<Object>(info[0]).ToLocalChecked());
bool isEqual = obj->mValue == otherObj->mValue;
info.GetReturnValue().Set(Nan::New(isEqual));
}
Expand All @@ -184,7 +182,7 @@ NAN_METHOD(Int64::Compare) {
Nan::ThrowTypeError("Object expected");
}
Int64* obj = ObjectWrap::Unwrap<Int64>(info.Holder());
Int64* otherObj = ObjectWrap::Unwrap<Int64>(info[0]->ToObject());
Int64* otherObj = ObjectWrap::Unwrap<Int64>(Nan::To<Object>(info[0]).ToLocalChecked());
int32_t cmp = 0;
if (obj->mValue < otherObj->mValue) {
cmp = -1;
Expand Down Expand Up @@ -215,7 +213,7 @@ NAN_METHOD(Int64::ShiftLeft) {
}
Int64* obj = ObjectWrap::Unwrap<Int64>(info.Holder());
uint64_t shiftBy = static_cast<uint64_t>(
Nan::To<v8::Number>(info[0]).ToLocalChecked()->NumberValue()
Nan::To<int64_t>(info[0]).ToChecked()
);
uint64_t value = obj->mValue << shiftBy;
Local<Value> argv[2] = {
Expand All @@ -238,7 +236,7 @@ NAN_METHOD(Int64::ShiftRight) {
}
Int64* obj = ObjectWrap::Unwrap<Int64>(info.Holder());
uint64_t shiftBy = static_cast<uint64_t>(
Nan::To<v8::Number>(info[0]).ToLocalChecked()->NumberValue()
Nan::To<int64_t>(info[0]).ToChecked()
);
uint64_t value = obj->mValue >> shiftBy;
Local<Value> argv[2] = {
Expand All @@ -258,9 +256,9 @@ NAN_METHOD(Int64::And) {
Int64* obj = ObjectWrap::Unwrap<Int64>(info.Holder());
uint64_t value;
if (info[0]->IsNumber()) {
value = obj->mValue & info[0]->IntegerValue();
value = obj->mValue & Nan::To<int64_t>(info[0]).ToChecked();
} else if (info[0]->IsObject()) {
Int64* otherObj = ObjectWrap::Unwrap<Int64>(info[0]->ToObject());
Int64* otherObj = ObjectWrap::Unwrap<Int64>(Nan::To<Object>(info[0]).ToLocalChecked());
value = obj->mValue & otherObj->mValue;
} else {
Nan::ThrowTypeError("Object or number expected");
Expand All @@ -283,9 +281,9 @@ NAN_METHOD(Int64::Or) {
Int64* obj = ObjectWrap::Unwrap<Int64>(info.Holder());
uint64_t value;
if (info[0]->IsNumber()) {
value = obj->mValue | info[0]->IntegerValue();
value = obj->mValue | Nan::To<int64_t>(info[0]).ToChecked();
} else if (info[0]->IsObject()) {
Int64* otherObj = ObjectWrap::Unwrap<Int64>(info[0]->ToObject());
Int64* otherObj = ObjectWrap::Unwrap<Int64>(Nan::To<Object>(info[0]).ToLocalChecked());
value = obj->mValue | otherObj->mValue;
} else {
Nan::ThrowTypeError("Object or number expected");
Expand All @@ -308,9 +306,9 @@ NAN_METHOD(Int64::Xor) {
Int64* obj = ObjectWrap::Unwrap<Int64>(info.Holder());
uint64_t value;
if (info[0]->IsNumber()) {
value = obj->mValue ^ info[0]->IntegerValue();
value = obj->mValue ^ Nan::To<int64_t>(info[0]).ToChecked();
} else if (info[0]->IsObject()) {
Int64* otherObj = ObjectWrap::Unwrap<Int64>(info[0]->ToObject());
Int64* otherObj = ObjectWrap::Unwrap<Int64>(Nan::To<Object>(info[0]).ToLocalChecked());
value = obj->mValue ^ otherObj->mValue;
} else {
Nan::ThrowTypeError("Object or number expected");
Expand All @@ -333,9 +331,9 @@ NAN_METHOD(Int64::Add) {
Int64* obj = ObjectWrap::Unwrap<Int64>(info.Holder());
uint64_t value;
if (info[0]->IsNumber()) {
value = obj->mValue + info[0]->IntegerValue();
value = obj->mValue + Nan::To<int64_t>(info[0]).ToChecked();
} else if (info[0]->IsObject()) {
Int64* otherObj = ObjectWrap::Unwrap<Int64>(info[0]->ToObject());
Int64* otherObj = ObjectWrap::Unwrap<Int64>(Nan::To<Object>(info[0]).ToLocalChecked());
value = obj->mValue + otherObj->mValue;
} else {
Nan::ThrowTypeError("Object or number expected");
Expand All @@ -358,9 +356,9 @@ NAN_METHOD(Int64::Sub) {
Int64* obj = ObjectWrap::Unwrap<Int64>(info.Holder());
uint64_t value;
if (info[0]->IsNumber()) {
value = obj->mValue - info[0]->IntegerValue();
value = obj->mValue - Nan::To<int64_t>(info[0]).ToChecked();
} else if (info[0]->IsObject()) {
Int64* otherObj = ObjectWrap::Unwrap<Int64>(info[0]->ToObject());
Int64* otherObj = ObjectWrap::Unwrap<Int64>(Nan::To<Object>(info[0]).ToLocalChecked());
value = obj->mValue - otherObj->mValue;
} else {
Nan::ThrowTypeError("Object or number expected");
Expand Down
2 changes: 1 addition & 1 deletion src/Int64.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace v8;

class Int64 : public Nan::ObjectWrap {
public:
static void Init(Handle<Object> exports);
static NAN_MODULE_INIT(Init);

private:
Int64();
Expand Down
4 changes: 2 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using namespace node;
using namespace v8;

void InitAll(Handle<Object> exports) {
Int64::Init(exports);
NAN_MODULE_INIT(InitAll) {
Int64::Init(target);
}

NODE_MODULE(Int64, InitAll)