diff --git a/nan.h b/nan.h index 6bb36674..fee71a55 100644 --- a/nan.h +++ b/nan.h @@ -1727,14 +1727,25 @@ static bool _NanGetExternalParts( assert(val->IsString()); v8::Local str = NanNew(val.As()); +#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(ext->data()); diff --git a/nan_implementation_12_inl.h b/nan_implementation_12_inl.h index aae8746e..324b0b6c 100644 --- a/nan_implementation_12_inl.h +++ b/nan_implementation_12_inl.h @@ -179,7 +179,11 @@ Factory::New(v8::String::ExternalStringResource * value) { } Factory::return_t +#if NODE_MODULE_VERSION >= 42 // io.js v1.0.0 +Factory::New(v8::String::ExternalOneByteStringResource * value) { +#else Factory::New(v8::String::ExternalAsciiStringResource * value) { +#endif return v8::String::NewExternal(v8::Isolate::GetCurrent(), value); } diff --git a/nan_new.h b/nan_new.h index 5ff0ec22..c087e394 100644 --- a/nan_new.h +++ b/nan_new.h @@ -132,7 +132,11 @@ struct Factory : FactoryBase { 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); @@ -259,7 +263,11 @@ NanNew(v8::String::ExternalStringResource * value) { inline NanIntern::Factory::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(value); } diff --git a/test/cpp/morenews.cpp b/test/cpp/morenews.cpp index d31536c3..9b5e645a 100644 --- a/test/cpp/morenews.cpp +++ b/test/cpp/morenews.cpp @@ -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; }