Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update calls to use contexts and convert Maybes into Checked values, … #3

Merged
merged 2 commits into from Aug 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/zlib_sync.cc
Expand Up @@ -65,15 +65,15 @@ class ZlibSyncInflate : public ObjectWrap {

static NAN_METHOD(Push) {
ZlibSyncInflate* self = ObjectWrap::Unwrap<ZlibSyncInflate>(info.This());

Local<Context> context = Nan::GetCurrentContext();
Local<Object> buffer = Local<Object>::Cast(info[0]);
int flush = Z_NO_FLUSH;
if(info[1]->IsBoolean()) {
if(info[1]->BooleanValue()) {
if(info[1]->BooleanValue(context).ToChecked()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we can use the magic of nan, Nan::To<bool>().FromJust() would be preferred. Some of these *Value() calls are deprecated anyway.

flush = Z_FINISH;
}
} else if(info[1]->IsNumber()) {
flush = info[1]->Int32Value();
flush = info[1]->Int32Value(context).ToChecked();
}

z_stream* stream = &self->stream;
Expand Down Expand Up @@ -153,7 +153,7 @@ class ZlibSyncInflate : public ObjectWrap {
if(!info.IsConstructCall()) {
return Nan::ThrowTypeError("Use the new operator to construct a ZlibSyncInflate.");
}

Local<Context> context = Nan::GetCurrentContext();
unsigned int chunkSize = 16 * 1024;
bool toString = false;
int windowBits = 15;
Expand All @@ -162,20 +162,20 @@ class ZlibSyncInflate : public ObjectWrap {

Local<Value> val = Nan::Get(options, Nan::New<String>("chunkSize").ToLocalChecked()).ToLocalChecked();
if(val->IsNumber()) {
chunkSize = val->Int32Value();
chunkSize = val->Int32Value(context).ToChecked();
}

val = Nan::Get(options, Nan::New<String>("to").ToLocalChecked()).ToLocalChecked();
if(val->IsString()) {
std::string to = *String::Utf8Value(val->ToString());
std::string to = *Nan::Utf8String(val->ToString(context).ToLocalChecked());
if(to == "string") {
toString = true;
}
}

val = Nan::Get(options, Nan::New<String>("windowBits").ToLocalChecked()).ToLocalChecked();
if(val->IsNumber()) {
windowBits = val->Int32Value();
windowBits = val->Int32Value(context).ToChecked();
}
}

Expand All @@ -187,7 +187,7 @@ class ZlibSyncInflate : public ObjectWrap {

static NAN_MODULE_INIT(Init) {
Nan::HandleScope scope;

Local<Context> context = Nan::GetCurrentContext();
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New<String>("ZlibSyncInflate").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Expand All @@ -201,7 +201,7 @@ class ZlibSyncInflate : public ObjectWrap {
Nan::SetAccessor(itpl, Nan::New<String>("result").ToLocalChecked(), GetResult);
Nan::SetAccessor(itpl, Nan::New<String>("windowBits").ToLocalChecked(), GetWindowBits);

target->Set(Nan::New<String>("Inflate").ToLocalChecked(), tpl->GetFunction());
target->Set(Nan::New<String>("Inflate").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thing is deprecated too, could add context as first arg and a ToChecked() at the end.

}
};

Expand Down