diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0fdbe9..dab47bf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # NAN ChangeLog -**Version 1.5.2: current Node unstable: 0.11.15, Node stable: 0.10.35, io.js: 1.0.3** +**Version 1.6.0: current Node unstable: 0.11.15, Node stable: 0.10.35, io.js: 1.0.3** + +### 1.6.0 Jan 23 2015 + - Deprecated `NanNewContextHandle` in favor of `NanNew` 49259af + - Support utility functions moved in newer v8 versions (Node 0.11.15, io.js 1.0) a0aa179 + - Added `NanEncode`, `NanDecodeBytes` and `NanDecodeWrite` 75e6fb9 ### 1.5.2 Jan 23 2015 @@ -14,7 +19,6 @@ - Correctness: Make explicit downcasts of String lengths 00074e6 - Windows: Limit the scope of disabled warning C4530 83d7deb - ### 1.5.1 Jan 15 2015 - Build: version bump diff --git a/README.md b/README.md index f91d08b9..0b025af0 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Native Abstractions for Node.js **A header file filled with macro and utility goodness for making add-on development for Node.js easier across versions 0.8, 0.10 and 0.11, and eventually 0.12.** -***Current version: 1.5.2*** +***Current version: 1.6.0*** *(See [CHANGELOG.md](https://github.com/rvagg/nan/blob/master/CHANGELOG.md) for complete ChangeLog)* @@ -25,6 +25,13 @@ This project also contains some helper utilities that make addon development a b ## News & Updates +### Jan-2015: 1.6.0 release + +* Deprecated `NanNewContextHandle` in favor of `NanNew` +* Added `NanSetCounterFunction`, `NanSetCreateHistogramFunction`, `NanSetAddHistogramSampleFunction` +* Added `NanIdleNotification`, `NanLowMemoryNotification`, `NanContextDisposedNotification` +* Added `NanEncode`, `NanDecodeBytes` and `NanDecodeWrite` + ### Jan-2015: 1.5.0 release * Support [io.js](https://github.com/iojs/io.js) thanks to [Ben Noordhuis](bnoordhuis) @@ -284,7 +291,7 @@ NAN_METHOD(CalculateAsync) { * NanThrowError, NanThrowTypeError, NanThrowRangeError, NanThrowError(Handle), NanThrowError(Handle, int) * NanNewBufferHandle(char *, size_t, FreeCallback, void *), NanNewBufferHandle(char *, uint32_t), NanNewBufferHandle(uint32_t) * NanBufferUse(char *, uint32_t) - * NanNewContextHandle + * NanNewContextHandle * NanGetCurrentContext * NanHasInstance * NanDisposePersistent @@ -294,6 +301,9 @@ NAN_METHOD(CalculateAsync) { * NanSetPrototypeTemplate * NanSetInstanceTemplate * NanMakeCallback + * NanEncode + * NanDecodeBytes + * NanDecodeWrite * NanCompileScript * NanRunScript * NanAdjustExternalMemory @@ -302,6 +312,12 @@ NAN_METHOD(CalculateAsync) { * NanRemoveGCEpilogueCallback * NanRemoveGCPrologueCallback * NanGetHeapStatistics + * NanSetCounterFunction + * NanSetCreateHistogramFunction + * NanSetAddHistogramSampleFunction + * NanIdleNotification + * NanLowMemoryNotification + * NanContextDisposedNotification * NanCallback * NanAsyncWorker * NanAsyncQueueWorker @@ -974,8 +990,11 @@ careless use can lead to "double free or corruption" and other cryptic failures. Can be used to check the type of an object to determine it is of a particular class you have already defined and have a `Persistent` handle for. -### Local<Context> NanNewContextHandle([ExtensionConfiguration*, Handle<ObjectTemplate>, Handle<Value>]) -Creates a new `Local` handle. +### ~~Local<Context> NanNewContextHandle([ExtensionConfiguration*, Handle<ObjectTemplate>, Handle<Value>]) + +Deprecated. Use `NanNew` instead. + +~~Creates a new `Local` handle. ```c++ Local ftmpl = NanNew(); @@ -1058,6 +1077,21 @@ Use to add instance properties on function templates. Use instead of `node::MakeCallback` to call javascript functions. This (or `NanCallback`) is the only proper way of calling functions. You must _*never, ever*_ directly use `Function::Call`, it will lead to run-time failures. + +### NanEncode(const void*, size_t[, enum Nan::Encoding]) + +Replaces `node::Encode`. + + +### NanDecodeBytes(v8::Handle<v8::Value>[, enum Nan::Encoding]) + +Replaces `node::DecodeBytes`. + + +### NanDecodeWrite(char *, size_t, v8::Handle<v8::Value>[, enum Nan::Encoding]) + +Replaces `node::DecodeWrite`. + ### NanCompileScript(Handle s [, const ScriptOrigin& origin]) @@ -1098,6 +1132,36 @@ Simply does `RemoveGCPrologueCallback` Simply does `GetHeapStatistics` + +### NanSetCounterFunction(CounterLookupCallback cb) + +Simply does `SetCounterFunction` + + +### NanSetCreateHistogramFunction(CreateHistogramCallback cb) + +Simply does `SetCreateHistogramFunction` + + +### NanSetAddHistogramSampleFunction(AddHistogramSampleCallback cb) + +Simply does `SetAddHistogramSampleFunction` + + +### NanIdleNotification(int idle_time_in_ms) + +Simply does `IdleNotification` + + +### NanLowMemoryNotification() + +Simply does `LowMemoryNotification` + + +### NanContextDisposedNotification() + +Simply does `ContextDisposedNotification` + ### NanCallback diff --git a/nan.h b/nan.h index 531b3aca..fa15e266 100644 --- a/nan.h +++ b/nan.h @@ -12,7 +12,7 @@ * * MIT License * - * Version 1.5.2: current Node unstable: 0.11.15, Node stable: 0.10.35, io.js: 1.0.3 + * Version 1.6.0: current Node unstable: 0.11.15, Node stable: 0.10.35, io.js: 1.0.3 * * See https://github.com/rvagg/nan for the latest update to this file **********************************************************************************/ @@ -166,6 +166,63 @@ NAN_INLINE v8::Local _NanEnsureLocal(v8::Local val) { return val; } +/* io.js 1.0 */ +#if NODE_MODULE_VERSION >= 42 || NODE_VERSION_AT_LEAST(0, 11, 15) + NAN_INLINE + void NanSetCounterFunction(v8::CounterLookupCallback cb) { + v8::Isolate::GetCurrent()->SetCounterFunction(cb); + } + + NAN_INLINE + void NanSetCreateHistogramFunction(v8::CreateHistogramCallback cb) { + v8::Isolate::GetCurrent()->SetCreateHistogramFunction(cb); + } + + NAN_INLINE + void NanSetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) { + v8::Isolate::GetCurrent()->SetAddHistogramSampleFunction(cb); + } + + NAN_INLINE bool NanIdleNotification(int idle_time_in_ms) { + return v8::Isolate::GetCurrent()->IdleNotification(idle_time_in_ms); + } + + NAN_INLINE void NanLowMemoryNotification() { + v8::Isolate::GetCurrent()->LowMemoryNotification(); + } + + NAN_INLINE void NanContextDisposedNotification() { + v8::Isolate::GetCurrent()->ContextDisposedNotification(); + } +#else + NAN_INLINE + void NanSetCounterFunction(v8::CounterLookupCallback cb) { + v8::V8::SetCounterFunction(cb); + } + + NAN_INLINE + void NanSetCreateHistogramFunction(v8::CreateHistogramCallback cb) { + v8::V8::SetCreateHistogramFunction(cb); + } + + NAN_INLINE + void NanSetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) { + v8::V8::SetAddHistogramSampleFunction(cb); + } + + NAN_INLINE bool NanIdleNotification(int idle_time_in_ms) { + return v8::V8::IdleNotification(idle_time_in_ms); + } + + NAN_INLINE void NanLowMemoryNotification() { + v8::V8::LowMemoryNotification(); + } + + NAN_INLINE void NanContextDisposedNotification() { + v8::V8::ContextDisposedNotification(); + } +#endif + #if (NODE_MODULE_VERSION > 0x000B) // Node 0.11+ (0.11.12 and below won't compile with these) @@ -529,7 +586,7 @@ NAN_INLINE _NanWeakCallbackInfo* NanMakeWeakPersistent( return NanNew(function_template)->HasInstance(value); } - NAN_INLINE v8::Local NanNewContextHandle( + NAN_DEPRECATED NAN_INLINE v8::Local NanNewContextHandle( v8::ExtensionConfiguration* extensions = NULL , v8::Handle tmpl = v8::Handle() , v8::Handle obj = v8::Handle() @@ -1075,7 +1132,7 @@ NAN_INLINE _NanWeakCallbackInfo* NanMakeWeakPersistent( return function_template->HasInstance(value); } - NAN_INLINE v8::Local NanNewContextHandle( + NAN_DEPRECATED NAN_INLINE v8::Local NanNewContextHandle( v8::ExtensionConfiguration* extensions = NULL , v8::Handle tmpl = v8::Handle() , v8::Handle obj = v8::Handle() @@ -1785,6 +1842,68 @@ namespace Nan { enum Encoding {ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER}; } +NAN_INLINE v8::Local NanEncode( + const void *buf, size_t len, enum Nan::Encoding encoding = Nan::BINARY) { +#if (NODE_MODULE_VERSION > 0x000B) + return node::Encode( + v8::Isolate::GetCurrent() + , buf, len + , static_cast(encoding)); +#else +# if (NODE_MODULE_VERSION < 0x000B) + if (encoding == Nan::BUFFER) { + assert(len <= node::Buffer::kMaxLength); + return v8::Local::New(node::Buffer::New( + static_cast(const_cast(buf)), len)->handle_); + } +# endif + return node::Encode(buf, len, static_cast(encoding)); +#endif +} + +NAN_INLINE ssize_t NanDecodeBytes( + v8::Handle val, enum Nan::Encoding encoding = Nan::BINARY) { +#if (NODE_MODULE_VERSION > 0x000B) + return node::DecodeBytes( + v8::Isolate::GetCurrent() + , val + , static_cast(encoding)); +#else +# if (NODE_MODULE_VERSION < 0x000B) + if (encoding == Nan::BUFFER) { + return node::DecodeBytes(val, node::BINARY); + } +# endif + return node::DecodeBytes(val, static_cast(encoding)); +#endif +} + +NAN_INLINE ssize_t NanDecodeWrite( + char *buf + , size_t len + , v8::Handle val + , enum Nan::Encoding encoding = Nan::BINARY) { +#if (NODE_MODULE_VERSION > 0x000B) + return node::DecodeWrite( + v8::Isolate::GetCurrent() + , buf + , len + , val + , static_cast(encoding)); +#else +# if (NODE_MODULE_VERSION < 0x000B) + if (encoding == Nan::BUFFER) { + return node::DecodeWrite(buf, len, val, node::BINARY); + } +# endif + return node::DecodeWrite( + buf + , len + , val + , static_cast(encoding)); +#endif +} + /* NAN_DEPRECATED */ NAN_INLINE void* _NanRawString( v8::Handle from , enum Nan::Encoding encoding diff --git a/nan_implementation_12_inl.h b/nan_implementation_12_inl.h index 5f0bff05..ff63ec0c 100644 --- a/nan_implementation_12_inl.h +++ b/nan_implementation_12_inl.h @@ -48,6 +48,15 @@ Factory::New(bool value) { return v8::BooleanObject::New(value).As(); } +//=== Context ================================================================== + +Factory::return_t +Factory::New( v8::ExtensionConfiguration* extensions + , v8::Handle tmpl + , v8::Handle obj) { + return v8::Context::New(v8::Isolate::GetCurrent(), extensions, tmpl, obj); +} + //=== Date ===================================================================== Factory::return_t diff --git a/nan_implementation_pre_12_inl.h b/nan_implementation_pre_12_inl.h index 4c4ae116..85dd2754 100644 --- a/nan_implementation_pre_12_inl.h +++ b/nan_implementation_pre_12_inl.h @@ -53,6 +53,18 @@ Factory::New(bool value) { return v8::BooleanObject::New(value).As(); } +//=== Context ================================================================== + +Factory::return_t +Factory::New( v8::ExtensionConfiguration* extensions + , v8::Handle tmpl + , v8::Handle obj) { + v8::Persistent ctx = v8::Context::New(extensions, tmpl, obj); + v8::Local lctx = v8::Local::New(ctx); + ctx.Dispose(); + return lctx; +} + //=== Date ===================================================================== Factory::return_t diff --git a/nan_new.h b/nan_new.h index 7058d123..95b6b51e 100644 --- a/nan_new.h +++ b/nan_new.h @@ -57,6 +57,15 @@ struct Factory : FactoryBase { static inline return_t New(bool value); }; +template <> +struct Factory : FactoryBase { + static inline + return_t + New( v8::ExtensionConfiguration* extensions = NULL + , v8::Handle tmpl = v8::Handle() + , v8::Handle obj = v8::Handle()); +}; + template <> struct Factory : FactoryBase { static inline return_t New(double value); diff --git a/test/cpp/nannew.cpp b/test/cpp/nannew.cpp index 854e6bd5..b7b5d39b 100644 --- a/test/cpp/nannew.cpp +++ b/test/cpp/nannew.cpp @@ -99,6 +99,23 @@ NAN_METHOD(testBooleanObject) { } #undef V +NAN_METHOD(testContext) { + NanScope(); + NanTap t(args[0]); + + t.plan(4); + t.ok(_( assertType( NanNew()))); + ExtensionConfiguration extensions(0, NULL); + t.ok(_( assertType( NanNew(&extensions)))); + t.ok(_( assertType( + NanNew(&extensions, Handle())))); + t.ok(_( assertType( + NanNew(&extensions + , Handle(), Handle())))); + + return_NanUndefined(); +} + NAN_METHOD(testDate) { NanScope(); NanTap t(args[0]); @@ -446,6 +463,7 @@ void Init(Handle exports) { NAN_EXPORT(exports, testArray); NAN_EXPORT(exports, testBoolean); NAN_EXPORT(exports, testBooleanObject); + NAN_EXPORT(exports, testContext); NAN_EXPORT(exports, testDate); NAN_EXPORT(exports, testExternal); NAN_EXPORT(exports, testFunction);