Skip to content

Commit

Permalink
Merge pull request #237 from rvagg/forgotten_methods
Browse files Browse the repository at this point in the history
Readded missing String constructors.
  • Loading branch information
kkoopa committed Jan 17, 2015
2 parents a628a50 + 18d828f commit 4dafe32
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions nan_implementation_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ Factory<v8::Signature>::New( Factory<v8::Signature>::FTH receiver

//=== String ===================================================================

Factory<v8::String>::return_t
Factory<v8::String>::New() {
return v8::String::Empty(v8::Isolate::GetCurrent());
}

Factory<v8::String>::return_t
Factory<v8::String>::New(const char * value, int length) {
return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), value,
Expand Down
5 changes: 5 additions & 0 deletions nan_implementation_pre_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ Factory<v8::Signature>::New( Factory<v8::Signature>::FTH receiver

//=== String ===================================================================

Factory<v8::String>::return_t
Factory<v8::String>::New() {
return v8::String::Empty();
}

Factory<v8::String>::return_t
Factory<v8::String>::New(const char * value, int length) {
return v8::String::New(value, length);
Expand Down
7 changes: 7 additions & 0 deletions nan_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ struct Factory<v8::Signature> : FactoryBase<v8::Signature> {

template <>
struct Factory<v8::String> : FactoryBase<v8::String> {
static inline return_t New();
static inline return_t New(const char *value, int length = -1);
static inline return_t New(const uint16_t *value, int length = -1);
static inline return_t New(std::string const& value);
Expand Down Expand Up @@ -237,6 +238,12 @@ NanNew(std::string const& value) {
return NanNew<v8::String>(value);
}

inline
NanIntern::Factory<v8::String>::return_t
NanNew(const char * value, int length) {
return NanNew<v8::String>(value, length);
}

inline
NanIntern::Factory<v8::String>::return_t
NanNew(const char * value) {
Expand Down
8 changes: 7 additions & 1 deletion test/cpp/nannew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,16 @@ NAN_METHOD(testString) {
NanScope();
NanTap t(args[0]);

t.plan(10);
t.plan(14);

t.ok(_( stringMatches( NanNew<String>("Hello World"), "Hello World")));
t.ok(_( stringMatches( NanNew<String>("Hello World", 4), "Hell")));
t.ok(_( stringMatches( NanNew<String>(std::string("foo")), "foo")));
t.ok(_( assertType<String>( NanNew<String>("plonk."))));

t.ok(_( stringMatches( NanNew<String>(), "")));
t.ok(_( assertType<String>( NanNew<String>())));

// These should be deprecated
const uint8_t *ustring = reinterpret_cast<const uint8_t *>("unsigned chars");
t.ok(_( stringMatches( NanNew<String>(ustring), "unsigned chars")));
Expand All @@ -249,6 +252,9 @@ NAN_METHOD(testString) {
"using namespace nan; // is poetry")));
t.ok(_( assertType<String>( NanNew("plonk."))));

t.ok(_( stringMatches( NanNew("Hello World", 4), "Hell")));
t.ok(_( assertType<String>( NanNew("plonk.", 4))));

t.ok(_( stringMatches( NanNew(std::string("bar")), "bar")));
t.ok(_( assertType<String>( NanNew(std::string("plonk.")))));

Expand Down

0 comments on commit 4dafe32

Please sign in to comment.