Skip to content

Commit 46508a4

Browse files
committed
lib: update to nan 2.x
1 parent 589f59f commit 46508a4

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"url": "https://github.com/LinusU/node-alias.git"
2323
},
2424
"dependencies": {
25-
"nan": "^1.9.0"
25+
"nan": "^2.0.5"
2626
}
2727
}

src/impl-apple-cheetah.cc

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
#include <CoreFoundation/CFURL.h>
44
#include <CoreFoundation/CFString.h>
55

6-
using v8::String;
7-
using v8::Local;
8-
96
const char* OSErrDescription(OSErr err) {
107
switch (err) {
118
case nsvErr: return "Volume not found";
@@ -24,9 +21,7 @@ const char* OSErrDescription(OSErr err) {
2421
}
2522

2623
NAN_METHOD(MethodGetVolumeName) {
27-
NanScope();
28-
29-
NanAsciiString aPath(args[0]);
24+
Nan::Utf8String aPath(info[0]);
3025

3126
CFStringRef volumePath = CFStringCreateWithCString(NULL, *aPath, kCFStringEncodingUTF8);
3227
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, volumePath, kCFURLPOSIXPathStyle, true);
@@ -35,22 +30,18 @@ NAN_METHOD(MethodGetVolumeName) {
3530
FSRef urlFS;
3631
FSCatalogInfo urlInfo;
3732
HFSUniStr255 outString;
38-
Local<String> errorDesc;
3933

4034
if (CFURLGetFSRef(url, &urlFS) == false) {
41-
NanThrowError("Failed to convert URL to file or directory object");
42-
NanReturnUndefined();
35+
return Nan::ThrowError("Failed to convert URL to file or directory object");
4336
}
4437

4538
if ((err = FSGetCatalogInfo(&urlFS, kFSCatInfoVolume, &urlInfo, NULL, NULL, NULL)) != noErr) {
46-
NanThrowError(OSErrDescription(err));
47-
NanReturnUndefined();
39+
return Nan::ThrowError(OSErrDescription(err));
4840
}
4941

5042
if ((err = FSGetVolumeInfo(urlInfo.volume, 0, NULL, kFSVolInfoNone, NULL, &outString, NULL)) != noErr) {
51-
NanThrowError(OSErrDescription(err));
52-
NanReturnUndefined();
43+
return Nan::ThrowError(OSErrDescription(err));
5344
}
5445

55-
NanReturnValue(NanNew(outString.unicode, outString.length));
46+
info.GetReturnValue().Set(Nan::New<v8::String>(outString.unicode, outString.length).ToLocalChecked());
5647
}

src/impl-apple-lion.cc

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,35 @@ using v8::Value;
99

1010
Local<String> MYCFStringGetV8String(CFStringRef aString) {
1111
if (aString == NULL) {
12-
return NanNew("");
12+
return Nan::EmptyString();
1313
}
1414

1515
CFIndex length = CFStringGetLength(aString);
1616
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
1717
char *buffer = (char *) malloc(maxSize);
1818

1919
if (!CFStringGetCString(aString, buffer, maxSize, kCFStringEncodingUTF8)) {
20-
return NanNew("");
20+
return Nan::EmptyString();
2121
}
2222

23-
Local<String> result = NanNew(buffer);
23+
Local<String> result = Nan::New(buffer).ToLocalChecked();
2424
free(buffer);
2525

2626
return result;
2727
}
2828

2929
NAN_METHOD(MethodGetVolumeName) {
30-
NanScope();
31-
32-
NanAsciiString aPath(args[0]);
30+
Nan::Utf8String aPath(info[0]);
3331

3432
CFStringRef out;
3533
CFErrorRef error;
3634

3735
CFStringRef volumePath = CFStringCreateWithCString(NULL, *aPath, kCFStringEncodingUTF8);
3836
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, volumePath, kCFURLPOSIXPathStyle, true);
3937

40-
if(CFURLCopyResourcePropertyForKey(url, kCFURLVolumeNameKey, &out, &error)) {
41-
Local<String> result = MYCFStringGetV8String(out);
42-
NanReturnValue(result);
43-
} else {
44-
NanThrowError(MYCFStringGetV8String(CFErrorCopyDescription(error)));
45-
NanReturnUndefined();
38+
if(!CFURLCopyResourcePropertyForKey(url, kCFURLVolumeNameKey, &out, &error)) {
39+
return Nan::ThrowError(MYCFStringGetV8String(CFErrorCopyDescription(error)));
4640
}
41+
42+
info.GetReturnValue().Set(MYCFStringGetV8String(out));
4743
}

src/volume.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
using v8::FunctionTemplate;
1313

14-
void Initialize(v8::Handle<v8::Object> exports) {
15-
exports->Set(NanNew("getVolumeName"), NanNew<FunctionTemplate>(MethodGetVolumeName)->GetFunction());
14+
NAN_MODULE_INIT(Initialize) {
15+
Nan::Set(target, Nan::New("getVolumeName").ToLocalChecked(),
16+
Nan::GetFunction(Nan::New<FunctionTemplate>(MethodGetVolumeName)).ToLocalChecked());
1617
}
1718

1819
NODE_MODULE(volume, Initialize)

0 commit comments

Comments
 (0)