Skip to content

Commit

Permalink
Merge pull request #224 from bnoordhuis/iojs-compat-onepointfive
Browse files Browse the repository at this point in the history
Make compatible with io.js
  • Loading branch information
rvagg committed Jan 13, 2015
2 parents df86aaf + b003843 commit 39f85f4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
13 changes: 12 additions & 1 deletion nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -1727,14 +1727,25 @@ static bool _NanGetExternalParts(
assert(val->IsString());
v8::Local<v8::String> str = NanNew(val.As<v8::String>());

#if NODE_MODULE_VERSION >= 42 // io.js v1.0.0
if (str->IsExternalOneByte()) {
const v8::String::ExternalOneByteStringResource* ext;
ext = str->GetExternalOneByteStringResource();
*data = ext->data();
*len = ext->length();
return true;
}
#else
if (str->IsExternalAscii()) {
const v8::String::ExternalAsciiStringResource* ext;
ext = str->GetExternalAsciiStringResource();
*data = ext->data();
*len = ext->length();
return true;
}
#endif

} else if (str->IsExternal()) {
if (str->IsExternal()) {
const v8::String::ExternalStringResource* ext;
ext = str->GetExternalStringResource();
*data = reinterpret_cast<const char*>(ext->data());
Expand Down
4 changes: 4 additions & 0 deletions nan_implementation_12_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ Factory<v8::String>::New(v8::String::ExternalStringResource * value) {
}

Factory<v8::String>::return_t
#if NODE_MODULE_VERSION >= 42 // io.js v1.0.0
Factory<v8::String>::New(v8::String::ExternalOneByteStringResource * value) {
#else
Factory<v8::String>::New(v8::String::ExternalAsciiStringResource * value) {
#endif
return v8::String::NewExternal(v8::Isolate::GetCurrent(), value);
}

Expand Down
8 changes: 8 additions & 0 deletions nan_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ struct Factory<v8::String> : FactoryBase<v8::String> {
static inline return_t New(std::string const& value);

static inline return_t New(v8::String::ExternalStringResource * value);
#if NODE_MODULE_VERSION >= 42 // io.js v1.0.0
static inline return_t New(v8::String::ExternalOneByteStringResource * value);
#else
static inline return_t New(v8::String::ExternalAsciiStringResource * value);
#endif

// TODO(agnat): Deprecate.
static inline return_t New(const uint8_t * value, int length = -1);
Expand Down Expand Up @@ -259,7 +263,11 @@ NanNew(v8::String::ExternalStringResource * value) {

inline
NanIntern::Factory<v8::String>::return_t
#if NODE_MODULE_VERSION >= 42 // io.js v1.0.0
NanNew(v8::String::ExternalOneByteStringResource * value) {
#else
NanNew(v8::String::ExternalAsciiStringResource * value) {
#endif
return NanNew<v8::String>(value);
}

Expand Down
4 changes: 4 additions & 0 deletions test/cpp/morenews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ class ExtString : public v8::String::ExternalStringResource {
};


#if NODE_MODULE_VERSION >= 42 // io.js v1.0.0
class ExtAsciiString : public v8::String::ExternalOneByteStringResource {
#else
class ExtAsciiString : public v8::String::ExternalAsciiStringResource {
#endif
public:
~ExtAsciiString() { }
const char *data() const { return s; }
Expand Down

0 comments on commit 39f85f4

Please sign in to comment.