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

Added support of nan@2.0.9 #1

Merged
merged 2 commits into from Sep 15, 2015
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -2,7 +2,6 @@ language: node_js
node_js:
- "0.12"
- "0.10"
- "0.8"
install:
- "npm install -g npm"
- "npm install"
Expand Down
28 changes: 14 additions & 14 deletions icuWrapper.cpp
Expand Up @@ -4,9 +4,9 @@
#include <unicode/ucsdet.h>

NAN_METHOD(DetectCharacterEncoding) {
NanScope();
Nan::HandleScope scope;

v8::Local<v8::Object> inputBuffer = args[0]->ToObject();
v8::Local<v8::Object> inputBuffer = info[0]->ToObject();

UCharsetDetector *charsetDetector;
const UCharsetMatch *charsetMatch;
Expand All @@ -15,7 +15,7 @@ NAN_METHOD(DetectCharacterEncoding) {
charsetDetector = ucsdet_open(&errorCode);

if(U_FAILURE(errorCode)) {
NanThrowError("Failed to open ICU charset detector.");
Nan::ThrowError("Failed to open ICU charset detector.");
}

ucsdet_setText(
Expand All @@ -26,37 +26,37 @@ NAN_METHOD(DetectCharacterEncoding) {
);

if(U_FAILURE(errorCode)) {
NanThrowError("Failed to set ICU charset detector’s text.");
Nan::ThrowError("Failed to set ICU charset detector’s text.");
}

charsetMatch = ucsdet_detect(charsetDetector, &errorCode);

if(U_FAILURE(errorCode)) {
NanThrowError("Failed to detect charset.");
Nan::ThrowError("Failed to detect charset.");
}

const char *charsetName = ucsdet_getName(charsetMatch, &errorCode);

if(U_FAILURE(errorCode)) {
NanThrowError("Failed to get name from charset match.");
Nan::ThrowError("Failed to get name from charset match.");
}

int32_t confidence = ucsdet_getConfidence(charsetMatch, &errorCode);

if(U_FAILURE(errorCode)) {
NanThrowError("Failed to get confidence from charset match.");
Nan::ThrowError("Failed to get confidence from charset match.");
}

v8::Local<v8::Object> obj = NanNew<v8::Object>();
obj->Set(NanNew<v8::String>("encoding"), NanNew<v8::String>(charsetName));
obj->Set(NanNew<v8::String>("confidence"), NanNew<v8::Number>(confidence));
v8::Local<v8::Object> obj = Nan::New<v8::Object>();
obj->Set(Nan::New<v8::String>("encoding").ToLocalChecked(), Nan::New<v8::String>(charsetName).ToLocalChecked());
obj->Set(Nan::New<v8::String>("confidence").ToLocalChecked(), Nan::New<v8::Number>(confidence));

NanReturnValue(obj);
info.GetReturnValue().Set(obj);
}

void Init(v8::Handle<v8::Object> exports) {
exports->Set(NanNew<v8::String>("detectCharacterEncoding"),
NanNew<v8::FunctionTemplate>(DetectCharacterEncoding)->GetFunction());
void Init(v8::Local<v8::Object> exports) {
exports->Set(Nan::New<v8::String>("detectCharacterEncoding").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(DetectCharacterEncoding)->GetFunction());
}

NODE_MODULE(icuWrapper, Init);
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"bindings": "^1.2.1",
"nan": "^1.6.1"
"nan": "^2.0.9"
},
"devDependencies": {
"mocha": "^2.1.0"
Expand Down