33#include < CoreFoundation/CFURL.h>
44#include < CoreFoundation/CFString.h>
55
6- using namespace v8 ;
6+ using v8::String;
7+ using v8::Local;
78
8- Local<String> OSErrDescription (OSErr err) {
9+ const char * OSErrDescription (OSErr err) {
910
1011 switch (err) {
11- case nsvErr: return String::New ( " Volume not found" ) ;
12- case ioErr: return String::New ( " I/O error." ) ;
13- case bdNamErr: return String::New ( " Bad filename or volume name." ) ;
14- case mFulErr : return String::New ( " Memory full (open) or file won't fit (load)" ) ;
15- case tmfoErr: return String::New ( " Too many files open." ) ;
16- case fnfErr: return String::New ( " File or directory not found; incomplete pathname." ) ;
17- case volOffLinErr: return String::New ( " Volume is offline." ) ;
18- case nsDrvErr: return String::New ( " No such drive." ) ;
19- case dirNFErr: return String::New ( " Directory not found or incomplete pathname." ) ;
20- case tmwdoErr: return String::New ( " Too many working directories open." ) ;
12+ case nsvErr: return " Volume not found" ;
13+ case ioErr: return " I/O error." ;
14+ case bdNamErr: return " Bad filename or volume name." ;
15+ case mFulErr : return " Memory full (open) or file won't fit (load)" ;
16+ case tmfoErr: return " Too many files open." ;
17+ case fnfErr: return " File or directory not found; incomplete pathname." ;
18+ case volOffLinErr: return " Volume is offline." ;
19+ case nsDrvErr: return " No such drive." ;
20+ case dirNFErr: return " Directory not found or incomplete pathname." ;
21+ case tmwdoErr: return " Too many working directories open." ;
2122 }
2223
23- return String::New ( " Could not get volume name" ) ;
24+ return " Could not get volume name" ;
2425}
2526
26- v8::Handle<Value> MethodGetVolumeName ( const Arguments& args ) {
27- HandleScope scope ;
27+ NAN_METHOD (MethodGetVolumeName ) {
28+ NanScope () ;
2829
29- String::AsciiValue aPath (args[0 ]);
30+ NanAsciiString aPath (args[0 ]);
3031
3132 CFStringRef volumePath = CFStringCreateWithCString (NULL , *aPath, kCFStringEncodingUTF8 );
3233 CFURLRef url = CFURLCreateWithFileSystemPath (NULL , volumePath, kCFURLPOSIXPathStyle , true );
@@ -38,19 +39,19 @@ v8::Handle<Value> MethodGetVolumeName(const Arguments& args) {
3839 Local<String> errorDesc;
3940
4041 if (CFURLGetFSRef (url, &urlFS) == false ) {
41- ThrowException ( Exception::Error ( String::New ( " Failed to convert URL to file or directory object" ))-> ToObject () );
42- return scope. Close ( Undefined () );
42+ NanThrowError ( " Failed to convert URL to file or directory object" );
43+ NanReturnUndefined ( );
4344 }
4445
4546 if ((err = FSGetCatalogInfo (&urlFS, kFSCatInfoVolume , &urlInfo, NULL , NULL , NULL )) != noErr) {
46- ThrowException ( Exception::Error ( OSErrDescription (err))-> ToObject ( ));
47- return scope. Close ( Undefined () );
47+ NanThrowError ( OSErrDescription (err));
48+ NanReturnUndefined ( );
4849 }
4950
5051 if ((err = FSGetVolumeInfo (urlInfo.volume , 0 , NULL , kFSVolInfoNone , NULL , &outString, NULL )) != noErr) {
51- ThrowException ( Exception::Error ( OSErrDescription (err))-> ToObject ( ));
52- return scope. Close ( Undefined () );
52+ NanThrowError ( OSErrDescription (err));
53+ NanReturnUndefined ( );
5354 }
5455
55- return scope. Close ( String::New (outString.unicode , outString.length ));
56+ NanReturnValue ( NanNew (outString.unicode , outString.length ));
5657}
0 commit comments