diff --git a/nan.h b/nan.h index e29acb97..87a16fd6 100644 --- a/nan.h +++ b/nan.h @@ -110,6 +110,19 @@ NAN_INLINE uint32_t NanUInt32OptionValue( : def; } +template +v8::Local NanNew(v8::Handle); + +template +NAN_INLINE v8::Local _NanEnsureLocal(v8::Handle val) { + return NanNew(val); +} + +template +NAN_INLINE v8::Local _NanEnsureLocal(v8::Local val) { + return val; +} + #if (NODE_MODULE_VERSION > 0x000B) // Node 0.11+ (0.11.3 and below won't compile with these) @@ -498,17 +511,7 @@ NAN_INLINE uint32_t NanUInt32OptionValue( # define NanEscapableScope() \ v8::EscapableHandleScope scope(v8::Isolate::GetCurrent()) - template - NAN_INLINE v8::Local _NanEscapeScopeHelper(v8::Handle val) { - return NanNew(val); - } - - template - NAN_INLINE v8::Local _NanEscapeScopeHelper(v8::Local val) { - return val; - } - -# define NanEscapeScope(val) scope.Escape(_NanEscapeScopeHelper(val)) +# define NanEscapeScope(val) scope.Escape(_NanEnsureLocal(val)) # define NanLocker() v8::Locker locker(v8::Isolate::GetCurrent()) # define NanUnlocker() v8::Unlocker unlocker(v8::Isolate::GetCurrent()) # define NanReturnValue(value) return args.GetReturnValue().Set(value) @@ -1077,12 +1080,12 @@ NAN_INLINE _NanWeakCallbackInfo* NanMakeWeakPersistent( template NAN_INLINE v8::Local NanNew(P arg) { - return T::New(arg); + return _NanEnsureLocal(T::New(arg)); } template NAN_INLINE v8::Local NanNew(P arg, int length) { - return T::New(arg, length); + return _NanEnsureLocal(T::New(arg, length)); } template @@ -1129,11 +1132,6 @@ NAN_INLINE _NanWeakCallbackInfo* NanMakeWeakPersistent( return v8::Date::New(time).As(); } - template<> - NAN_INLINE v8::Local NanNew(bool value) { - return v8::Local::New(v8::Boolean::New(value)); - } - typedef v8::Script NanUnboundScript; typedef v8::Script NanBoundScript; diff --git a/test/cpp/news.cpp b/test/cpp/news.cpp index ccb83797..bb09d31b 100644 --- a/test/cpp/news.cpp +++ b/test/cpp/news.cpp @@ -154,6 +154,12 @@ NAN_METHOD(NewBoolean) { NanReturnValue(NanNew(true)); } +// #212 +NAN_METHOD(NewBoolean2) { + NanScope(); + NanReturnValue(NanNew(1)); +} + void Init(v8::Handle target) { target->Set( NanNew("newNumber") @@ -255,6 +261,10 @@ void Init(v8::Handle target) { NanNew("newBoolean") , NanNew(NewBoolean)->GetFunction() ); + target->Set( + NanNew("newBoolean2") + , NanNew(NewBoolean2)->GetFunction() + ); } NODE_MODULE(news, Init) diff --git a/test/js/news-test.js b/test/js/news-test.js index 1a8dca4b..fe2ef5d6 100644 --- a/test/js/news-test.js +++ b/test/js/news-test.js @@ -11,7 +11,7 @@ const test = require('tap').test , bindings = require('bindings')({ module_root: testRoot, bindings: 'news' }); test('news', function (t) { - t.plan(50); + t.plan(52); t.type(bindings.newNumber, 'function'); t.type(bindings.newPositiveInteger, 'function'); t.type(bindings.newNegativeInteger, 'function'); @@ -37,6 +37,7 @@ test('news', function (t) { t.type(bindings.newDate, 'function'); t.type(bindings.newArray, 'function'); t.type(bindings.newBoolean, 'function'); + t.type(bindings.newBoolean2, 'function'); t.equal(bindings.newNumber(), 0.5); t.equal(bindings.newPositiveInteger(), 1); @@ -63,4 +64,5 @@ test('news', function (t) { t.deepEquals(bindings.newDate(), new Date(1337)); t.deepEquals(bindings.newArray(), []); t.equal(bindings.newBoolean(), true); + t.equal(bindings.newBoolean2(), true); });