-
Notifications
You must be signed in to change notification settings - Fork 24
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
Nan2 #72
Closed
Nan2 #72
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
sudo: false | ||
|
||
language: node_js | ||
|
||
env: | ||
- CXX="g++-4.8" | ||
|
||
node_js: | ||
- "0.8" | ||
- "0.10" | ||
- "0.11" | ||
- iojs | ||
# - '0.8' | ||
# - '0.10' | ||
# - '0.12' | ||
- '4.0' | ||
# - '4.1' | ||
|
||
addons: | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
packages: | ||
- g++-4.8 | ||
- gcc-4.8 | ||
|
||
before_install: | ||
- "sudo apt-get install libicu-dev" | ||
# Workaround for a permissions issue with Travis virtual machine images | ||
# that breaks Python's multiprocessing: | ||
# https://github.com/travis-ci/travis-cookbooks/issues/155 | ||
- sudo rm -rf /dev/shm | ||
- sudo ln -s /run/shm /dev/shm | ||
- npm i -g npm@1.X | ||
# npm shipped with Node.js 0.8 doesn't support carret so let's update it | ||
- 'if [ "$TRAVIS_NODE_VERSION" == "0.8" ]; then npm i -g npm; fi' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,19 +13,19 @@ class UnknownProfileException : public std::exception { | |
}; | ||
|
||
// protect constructor from GC | ||
static Persistent<FunctionTemplate> stringprep_constructor; | ||
static Nan::Persistent<FunctionTemplate> stringprep_constructor; | ||
|
||
class StringPrep : public ObjectWrap { | ||
class StringPrep : public Nan::ObjectWrap { | ||
public: | ||
static void Initialize(Handle<Object> target) | ||
static void Initialize(Local<Object> target) | ||
{ | ||
NanScope(); | ||
Local<FunctionTemplate> t = NanNew<FunctionTemplate>(New); | ||
NanAssignPersistent(stringprep_constructor, t); | ||
Nan::HandleScope scope; | ||
Local<FunctionTemplate> t = Nan::New<FunctionTemplate>(New); | ||
stringprep_constructor.Reset(t); | ||
t->InstanceTemplate()->SetInternalFieldCount(1); | ||
NODE_SET_PROTOTYPE_METHOD(t, "prepare", Prepare); | ||
Nan::SetPrototypeMethod(t, "prepare", Prepare); | ||
|
||
target->Set(NanNew<String>("StringPrep"), t->GetFunction()); | ||
Nan::Set(target, Nan::New<String>("StringPrep").ToLocalChecked(), t->GetFunction()); | ||
} | ||
|
||
bool good() const | ||
|
@@ -43,39 +43,38 @@ class StringPrep : public ObjectWrap { | |
|
||
static NAN_METHOD(New) | ||
{ | ||
NanScope(); | ||
|
||
if (args.Length() >= 1 && args[0]->IsString()) | ||
if (info.Length() >= 1 && info[0]->IsString()) | ||
{ | ||
String::Utf8Value arg0(args[0]->ToString()); | ||
Nan::Utf8String arg0(info[0]->ToString()); | ||
UStringPrepProfileType profileType; | ||
try | ||
{ | ||
profileType = parseProfileType(arg0); | ||
} | ||
catch (UnknownProfileException &) | ||
{ | ||
NanThrowTypeError("Unknown StringPrep profile"); | ||
NanReturnUndefined(); | ||
Nan::ThrowTypeError("Unknown StringPrep profile"); | ||
return; | ||
} | ||
|
||
StringPrep *self = new StringPrep(profileType); | ||
if (self->good()) | ||
{ | ||
self->Wrap(args.This()); | ||
NanReturnValue(args.This()); | ||
self->Wrap(info.This()); | ||
info.GetReturnValue().Set(info.This()); | ||
return; | ||
} | ||
else | ||
{ | ||
const char* err = self->errorName(); | ||
delete self; | ||
NanThrowError(err); | ||
NanReturnUndefined(); | ||
Nan::ThrowError(err); | ||
return; | ||
} | ||
} | ||
else { | ||
NanThrowTypeError("Bad argument."); | ||
NanReturnUndefined(); | ||
Nan::ThrowTypeError("Bad argument."); | ||
return; | ||
} | ||
} | ||
|
||
|
@@ -97,27 +96,27 @@ class StringPrep : public ObjectWrap { | |
|
||
static NAN_METHOD(Prepare) | ||
{ | ||
NanScope(); | ||
|
||
if (args.Length() >= 1 && args[0]->IsString()) | ||
if (info.Length() >= 1 && info[0]->IsString()) | ||
{ | ||
StringPrep *self = ObjectWrap::Unwrap<StringPrep>(args.This()); | ||
String::Value arg0(args[0]->ToString()); | ||
NanReturnValue(self->prepare(arg0)); | ||
StringPrep *self = Nan::ObjectWrap::Unwrap<StringPrep>(info.This()); | ||
String::Value arg0(info[0]->ToString()); | ||
info.GetReturnValue().Set(self->prepare(arg0)); | ||
return; | ||
} | ||
else { | ||
NanThrowTypeError("Bad argument."); | ||
NanReturnUndefined(); | ||
Nan::ThrowTypeError("Bad argument."); | ||
return; | ||
} | ||
} | ||
|
||
Handle<Value> prepare(String::Value &str) | ||
Local<Value> prepare(String::Value &str) | ||
{ | ||
Nan::EscapableHandleScope scope; | ||
size_t destLen = str.length() + 1; | ||
UChar *dest = NULL; | ||
while(!dest) | ||
{ | ||
error = U_ZERO_ERROR; | ||
UErrorCode error = U_ZERO_ERROR; | ||
dest = new UChar[destLen]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
size_t w = usprep_prepare(profile, | ||
*str, str.length(), | ||
|
@@ -131,27 +130,26 @@ class StringPrep : public ObjectWrap { | |
delete[] dest; | ||
dest = NULL; | ||
} | ||
else if (!good()) | ||
else if (!U_SUCCESS(error)) | ||
{ | ||
// other error, just bail out | ||
delete[] dest; | ||
NanThrowError(errorName()); | ||
return NanUndefined(); | ||
Nan::ThrowTypeError(u_errorName(error)); | ||
return scope.Escape(Nan::Undefined()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
else | ||
destLen = w; | ||
} | ||
|
||
Local<String> result = NanNew<String>(dest, destLen); | ||
delete[] dest; | ||
return result; | ||
return scope.Escape(Nan::New<String>(dest, destLen).ToLocalChecked()); | ||
} | ||
|
||
private: | ||
UStringPrepProfile *profile; | ||
UErrorCode error; | ||
|
||
static enum UStringPrepProfileType parseProfileType(String::Utf8Value &profile) | ||
static enum UStringPrepProfileType parseProfileType(Nan::Utf8String &profile) | ||
throw(UnknownProfileException) | ||
{ | ||
if (strcasecmp(*profile, "nameprep") == 0) | ||
|
@@ -192,12 +190,10 @@ class StringPrep : public ObjectWrap { | |
|
||
NAN_METHOD(ToUnicode) | ||
{ | ||
NanScope(); | ||
|
||
if (args.Length() >= 2 && args[0]->IsString() && args[1]->IsInt32()) | ||
if (info.Length() >= 2 && info[0]->IsString() && info[1]->IsInt32()) | ||
{ | ||
String::Value str(args[0]->ToString()); | ||
int32_t options = args[1]->ToInt32()->Value(); | ||
String::Value str(info[0]->ToString()); | ||
int32_t options = info[1]->ToInt32()->Value(); | ||
|
||
// ASCII encoding (xn--*--*) should be longer than Unicode | ||
size_t destLen = str.length() + 1; | ||
|
@@ -210,7 +206,7 @@ NAN_METHOD(ToUnicode) | |
dest, destLen, | ||
options, | ||
NULL, &error); | ||
|
||
if (error == U_BUFFER_OVERFLOW_ERROR) | ||
{ | ||
// retry with a dest buffer twice as large | ||
|
@@ -222,31 +218,30 @@ NAN_METHOD(ToUnicode) | |
{ | ||
// other error, just bail out | ||
delete[] dest; | ||
NanThrowError(u_errorName(error)); | ||
NanReturnUndefined(); | ||
Nan::ThrowError(u_errorName(error)); | ||
return; | ||
} | ||
else | ||
destLen = w; | ||
} | ||
|
||
Local<String> result = NanNew<String>(dest, destLen); | ||
Local result = Nan::New(dest, destLen).ToLocalChecked(); | ||
delete[] dest; | ||
NanReturnValue(result); | ||
info.GetReturnValue().Set(result); | ||
return; | ||
} | ||
else { | ||
NanThrowTypeError("Bad argument."); | ||
NanReturnUndefined(); | ||
Nan::ThrowTypeError("Bad argument."); | ||
return; | ||
} | ||
} | ||
|
||
NAN_METHOD(ToASCII) | ||
{ | ||
NanScope(); | ||
|
||
if (args.Length() >= 2 && args[0]->IsString() && args[1]->IsInt32()) | ||
if (info.Length() >= 2 && info[0]->IsString() && info[1]->IsInt32()) | ||
{ | ||
String::Value str(args[0]->ToString()); | ||
int32_t options = args[1]->ToInt32()->Value(); | ||
String::Value str(info[0]->ToString()); | ||
int32_t options = info[1]->ToInt32()->Value(); | ||
|
||
// find out length first | ||
UErrorCode error = U_ZERO_ERROR; | ||
|
@@ -270,28 +265,28 @@ NAN_METHOD(ToASCII) | |
{ | ||
// other error, just bail out | ||
delete[] dest; | ||
NanThrowError(u_errorName(error)); | ||
NanReturnUndefined(); | ||
Nan::ThrowError(u_errorName(error)); | ||
return; | ||
} | ||
|
||
Local<String> result = NanNew<String>(dest, destLen); | ||
Local result = Nan::New(dest, destLen).ToLocalChecked(); | ||
delete[] dest; | ||
NanReturnValue(result); | ||
info.GetReturnValue().Set(result); | ||
return; | ||
} | ||
else { | ||
NanThrowTypeError("Bad argument."); | ||
NanReturnUndefined(); | ||
Nan::ThrowTypeError("Bad argument."); | ||
return; | ||
} | ||
} | ||
|
||
/*** Initialization ***/ | ||
|
||
extern "C" void init(Handle<Object> target) | ||
NAN_MODULE_INIT(init) | ||
{ | ||
NanScope(); | ||
StringPrep::Initialize(target); | ||
NODE_SET_METHOD(target, "toUnicode", ToUnicode); | ||
NODE_SET_METHOD(target, "toASCII", ToASCII); | ||
Nan::SetMethod(target, "toUnicode", ToUnicode); | ||
Nan::SetMethod(target, "toASCII", ToASCII); | ||
} | ||
|
||
NODE_MODULE(node_stringprep, init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.