From f1385872101680fda27f5e4443b368bd600ba022 Mon Sep 17 00:00:00 2001 From: Benjamin Byholm Date: Sat, 23 May 2015 15:14:51 +0300 Subject: [PATCH] Update for V8 v4.3 --- Makefile | 14 ++ examples/async_pi_estimate/addon.cc | 4 +- nan.h | 160 +++++++++++---- nan_converters.h | 65 +++++++ nan_converters_43_inl.h | 42 ++++ nan_converters_pre_43_inl.h | 42 ++++ nan_implementation_12_inl.h | 159 +++++++++++++-- nan_implementation_pre_12_inl.h | 28 +-- nan_maybe_43_inl.h | 228 ++++++++++++++++++++++ nan_maybe_pre_43_inl.h | 291 ++++++++++++++++++++++++++++ nan_new.h | 30 ++- nan_string_bytes.h | 16 +- test/binding.gyp | 8 + test/cpp/accessors.cpp | 23 ++- test/cpp/accessors2.cpp | 161 +++++++++++++++ test/cpp/asyncprogressworker.cpp | 9 +- test/cpp/asyncworker.cpp | 8 +- test/cpp/asyncworkererror.cpp | 4 +- test/cpp/bufferworkerpersistent.cpp | 15 +- test/cpp/converters.cpp | 128 ++++++++++++ test/cpp/error.cpp | 9 +- test/cpp/gc.cpp | 8 +- test/cpp/indexedinterceptors.cpp | 10 +- test/cpp/isolatedata.cpp | 4 +- test/cpp/makecallback.cpp | 60 +++--- test/cpp/morenews.cpp | 42 ++-- test/cpp/multifile1.cpp | 4 +- test/cpp/multifile2.cpp | 3 +- test/cpp/namedinterceptors.cpp | 10 +- test/cpp/nancallback.cpp | 12 +- test/cpp/nannew.cpp | 97 ++++++---- test/cpp/news.cpp | 153 ++++++++------- test/cpp/objectwraphandle.cpp | 4 +- test/cpp/persistent.cpp | 24 +-- test/cpp/returnemptystring.cpp | 4 +- test/cpp/returnnull.cpp | 4 +- test/cpp/returnundefined.cpp | 4 +- test/cpp/returnvalue.cpp | 14 +- test/cpp/settemplate.cpp | 89 ++++++--- test/cpp/strings.cpp | 8 +- test/cpp/symbols.cpp | 5 +- test/cpp/threadlocal.cpp | 11 +- test/cpp/trycatch.cpp | 10 +- test/cpp/weak.cpp | 6 +- test/cpp/weak2.cpp | 6 +- test/js/accessors2-test.js | 27 +++ test/js/converters-test.js | 45 +++++ 47 files changed, 1726 insertions(+), 382 deletions(-) create mode 100644 nan_converters.h create mode 100644 nan_converters_43_inl.h create mode 100644 nan_converters_pre_43_inl.h create mode 100644 nan_maybe_43_inl.h create mode 100644 nan_maybe_pre_43_inl.h create mode 100644 test/cpp/accessors2.cpp create mode 100644 test/cpp/converters.cpp create mode 100644 test/js/accessors2-test.js create mode 100644 test/js/converters-test.js diff --git a/Makefile b/Makefile index 22022f87..99f2cdbd 100644 --- a/Makefile +++ b/Makefile @@ -18,14 +18,20 @@ LINT_SOURCES = \ nan_callbacks.h \ nan_callbacks_12_inl.h \ nan_callbacks_pre_12_inl.h \ + nan_converters.h \ + nan_converters_43_inl.h \ + nan_converters_pre_43_inl.h \ nan_implementation_12_inl.h \ nan_implementation_pre_12_inl.h \ + nan_maybe_43_inl.h \ + nan_maybe_pre_43_inl.h \ nan_new.h \ nan_persistent_12_inl.h \ nan_persistent_pre_12_inl.h \ nan_string_bytes.h \ nan_weak.h \ test/cpp/accessors.cpp \ + test/cpp/accessors2.cpp \ test/cpp/asyncworker.cpp \ test/cpp/asyncprogressworker.cpp \ test/cpp/asyncworkererror.cpp \ @@ -34,6 +40,10 @@ LINT_SOURCES = \ test/cpp/gc.cpp \ test/cpp/indexedinterceptors.cpp \ test/cpp/morenews.cpp \ + test/cpp/converters.cpp \ + test/cpp/isolatedata.cpp \ + test/cpp/makecallback.cpp \ + test/cpp/morenews.cpp \ test/cpp/multifile1.cpp \ test/cpp/multifile2.cpp \ test/cpp/multifile2.h \ @@ -47,8 +57,10 @@ LINT_SOURCES = \ test/cpp/returnnull.cpp \ test/cpp/returnundefined.cpp \ test/cpp/returnvalue.cpp \ + test/cpp/settemplate.cpp \ test/cpp/strings.cpp \ test/cpp/symbols.cpp \ + test/cpp/threadlocal.cpp \ test/cpp/trycatch.cpp \ test/cpp/weak.cpp \ test/cpp/weak2.cpp \ @@ -70,6 +82,8 @@ forcetest: $(ADDONS): nan.h nan_new.h nan_implementation_pre_12_inl.h nan_implementation_12_inl.h \ nan_callbacks.h nan_callbacks_12_inl.h nan_callbacks_pre_12_inl.h \ + nan_converters.h nan_converters_43_inl.h nan_converters_pre_43_inl.h \ + nan_maybe_43_inl.h nan_maybe_pre_43_inl.h \ nan_persistent_12_inl.h nan_persistent_pre_12_inl.h nan_weak.h \ nan_string_bytes.h test/binding.gyp $(SOURCES) cd test/ && ../node_modules/.bin/node-gyp rebuild diff --git a/examples/async_pi_estimate/addon.cc b/examples/async_pi_estimate/addon.cc index e8956938..b0e72da3 100644 --- a/examples/async_pi_estimate/addon.cc +++ b/examples/async_pi_estimate/addon.cc @@ -18,10 +18,10 @@ using v8::String; // Expose synchronous and asynchronous access to our // Estimate() function void InitAll(Handle exports) { - exports->Set(NanNew("calculateSync"), + exports->Set(NanNew("calculateSync").ToLocalChecked(), NanNew(CalculateSync)->GetFunction()); - exports->Set(NanNew("calculateAsync"), + exports->Set(NanNew("calculateAsync").ToLocalChecked(), NanNew(CalculateAsync)->GetFunction()); } diff --git a/nan.h b/nan.h index 9f956ccd..6c28c5d3 100644 --- a/nan.h +++ b/nan.h @@ -118,7 +118,7 @@ typedef v8::String::ExternalOneByteStringResource NanExternalOneByteStringResource; #endif -#if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) template class NanNonCopyablePersistentTraits : public v8::NonCopyablePersistentTraits {}; @@ -138,8 +138,17 @@ template class NanPersistentBase; template class NanWeakCallbackData; template > class NanPersistent; +#endif // NODE_MODULE_VERSION + + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +# include "nan_maybe_43_inl.h" // NOLINT(build/include) +#else +# include "nan_maybe_pre_43_inl.h" // NOLINT(build/include) #endif +#include "nan_converters.h" // NOLINT(build/include) #include "nan_new.h" // NOLINT(build/include) // uv helpers @@ -276,6 +285,19 @@ template class NanWeakCallbackInfo; #endif namespace Nan { namespace imp { + template + NAN_INLINE + v8::Local + NanUnwrap(NanMaybeLocal maybe) { + return maybe.ToLocalChecked(); + } + + template + NAN_INLINE + v8::Local NanUnwrap(v8::Local val) { + return val; + } + template NAN_INLINE v8::Persistent &NanEnsureHandleOrPersistent( v8::Persistent &val) { // NOLINT(runtime/references) @@ -294,8 +316,10 @@ namespace Nan { namespace imp { } template - NAN_INLINE v8::Local NanEnsureHandleOrPersistent(const T &val) { - return NanNew(val); + NAN_INLINE + v8::Local + NanEnsureHandleOrPersistent(T val) { + return NanUnwrap(NanNew(val)); } template @@ -314,8 +338,9 @@ namespace Nan { namespace imp { } template - NAN_INLINE v8::Local NanEnsureLocal(const T &val) { - return NanNew(val); + NAN_INLINE + v8::Local NanEnsureLocal(T val) { + return NanUnwrap(NanNew(val)); } } // end of namespace imp } // end of namespace Nan @@ -402,9 +427,17 @@ class NanEscapableScope { v8::Isolate::GetCurrent()->SetAddHistogramSampleFunction(cb); } +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + NAN_INLINE bool NanIdleNotification(int idle_time_in_ms) { + return v8::Isolate::GetCurrent()->IdleNotificationDeadline( + idle_time_in_ms * 0.001); + } +# else NAN_INLINE bool NanIdleNotification(int idle_time_in_ms) { return v8::Isolate::GetCurrent()->IdleNotification(idle_time_in_ms); } +#endif NAN_INLINE void NanLowMemoryNotification() { v8::Isolate::GetCurrent()->LowMemoryNotification(); @@ -463,6 +496,10 @@ class NanEscapableScope { return scope.Escape(NanNew(v8::False(v8::Isolate::GetCurrent()))); } + NAN_INLINE v8::Local NanEmptyString() { + return v8::String::Empty(v8::Isolate::GetCurrent()); + } + NAN_INLINE int NanAdjustExternalMemory(int bc) { return static_cast( v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(bc)); @@ -531,26 +568,26 @@ class NanEscapableScope { } # define X(NAME) \ - NAN_INLINE v8::Local Nan ## NAME(const char *errmsg) { \ + NAN_INLINE v8::Local Nan ## NAME(const char *msg) { \ NanEscapableScope scope; \ - return scope.Escape(v8::Exception::NAME(NanNew(errmsg))); \ + return scope.Escape(v8::Exception::NAME(NanNew(msg).ToLocalChecked())); \ } \ \ NAN_INLINE \ - v8::Local Nan ## NAME(v8::Handle errmsg) { \ - return v8::Exception::NAME(errmsg); \ + v8::Local Nan ## NAME(v8::Handle msg) { \ + return v8::Exception::NAME(msg); \ } \ \ - NAN_INLINE void NanThrow ## NAME(const char *errmsg) { \ + NAN_INLINE void NanThrow ## NAME(const char *msg) { \ NanScope scope; \ v8::Isolate::GetCurrent()->ThrowException( \ - v8::Exception::NAME(NanNew(errmsg))); \ + v8::Exception::NAME(NanNew(msg).ToLocalChecked())); \ } \ \ - NAN_INLINE void NanThrow ## NAME(v8::Handle errmsg) { \ + NAN_INLINE void NanThrow ## NAME(v8::Handle msg) { \ NanScope scope; \ v8::Isolate::GetCurrent()->ThrowException( \ - v8::Exception::NAME(NanNew(errmsg))); \ + v8::Exception::NAME(NanNew(msg))); \ } X(Error) @@ -600,33 +637,65 @@ class NanEscapableScope { return NanNew(function_template)->HasInstance(value); } - NAN_INLINE v8::Local NanCompileScript( +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + NAN_INLINE NanMaybeLocal NanCompileScript( v8::Local s , const v8::ScriptOrigin& origin ) { v8::ScriptCompiler::Source source(s, origin); - return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &source); + return v8::ScriptCompiler::Compile(NanGetCurrentContext(), &source); } - NAN_INLINE v8::Local NanCompileScript( + NAN_INLINE NanMaybeLocal NanCompileScript( v8::Local s ) { v8::ScriptCompiler::Source source(s); - return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &source); + return v8::ScriptCompiler::Compile(NanGetCurrentContext(), &source); } - NAN_INLINE v8::Local NanRunScript( + NAN_INLINE NanMaybeLocal NanRunScript( v8::Handle script ) { - return script->BindToCurrentContext()->Run(); + return script->BindToCurrentContext()->Run(NanGetCurrentContext()); } - NAN_INLINE v8::Local NanRunScript( + NAN_INLINE NanMaybeLocal NanRunScript( v8::Handle script ) { - return script->Run(); + return script->Run(NanGetCurrentContext()); + } +#else + NAN_INLINE NanMaybeLocal NanCompileScript( + v8::Local s + , const v8::ScriptOrigin& origin + ) { + v8::ScriptCompiler::Source source(s, origin); + return NanMaybeLocal( + v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &source)); + } + + NAN_INLINE NanMaybeLocal NanCompileScript( + v8::Local s + ) { + v8::ScriptCompiler::Source source(s); + return NanMaybeLocal( + v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &source)); } + NAN_INLINE NanMaybeLocal NanRunScript( + v8::Handle script + ) { + return NanMaybeLocal(script->BindToCurrentContext()->Run()); + } + + NAN_INLINE NanMaybeLocal NanRunScript( + v8::Handle script + ) { + return NanMaybeLocal(script->Run()); + } +#endif + NAN_INLINE v8::Local NanMakeCallback( v8::Handle target , v8::Handle func @@ -694,6 +763,10 @@ class NanEscapableScope { return scope.Escape(NanNew(v8::False())); } + NAN_INLINE v8::Local NanEmptyString() { + return v8::String::Empty(); + } + NAN_INLINE int NanAdjustExternalMemory(int bc) { return static_cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(bc)); } @@ -757,19 +830,19 @@ class NanEscapableScope { } # define X(NAME) \ - NAN_INLINE v8::Local Nan ## NAME(const char *errmsg) { \ + NAN_INLINE v8::Local Nan ## NAME(const char *msg) { \ NanEscapableScope scope; \ - return scope.Escape(v8::Exception::NAME(NanNew(errmsg))); \ + return scope.Escape(v8::Exception::NAME(NanNew(msg).ToLocalChecked())); \ } \ \ NAN_INLINE \ - v8::Local Nan ## NAME(v8::Handle errmsg) { \ - return v8::Exception::NAME(errmsg); \ + v8::Local Nan ## NAME(v8::Handle msg) { \ + return v8::Exception::NAME(msg); \ } \ \ - NAN_INLINE void NanThrow ## NAME(const char *errmsg) { \ + NAN_INLINE void NanThrow ## NAME(const char *msg) { \ NanScope scope; \ - v8::ThrowException(v8::Exception::NAME(NanNew(errmsg))); \ + v8::ThrowException(v8::Exception::NAME(NanNew(msg).ToLocalChecked())); \ } \ \ NAN_INLINE \ @@ -835,21 +908,23 @@ class NanEscapableScope { return function_template->HasInstance(value); } - NAN_INLINE v8::Local NanCompileScript( + NAN_INLINE NanMaybeLocal NanCompileScript( v8::Local s , const v8::ScriptOrigin& origin ) { - return v8::Script::Compile(s, const_cast(&origin)); + return NanMaybeLocal( + v8::Script::Compile(s, const_cast(&origin))); } - NAN_INLINE v8::Local NanCompileScript( + NAN_INLINE NanMaybeLocal NanCompileScript( v8::Local s ) { - return v8::Script::Compile(s); + return NanMaybeLocal(v8::Script::Compile(s)); } - NAN_INLINE v8::Local NanRunScript(v8::Handle script) { - return script->Run(); + NAN_INLINE + NanMaybeLocal NanRunScript(v8::Handle script) { + return NanMaybeLocal(script->Run()); } NAN_INLINE v8::Local NanMakeCallback( @@ -1029,7 +1104,7 @@ class NanCallback { NAN_INLINE void SetFunction(const v8::Handle &fn) { NanScope scope; - NanNew(handle)->Set(kCallbackIndex, fn); + NanSet(NanNew(handle), kCallbackIndex, fn); } NAN_INLINE v8::Local GetFunction() const { @@ -1141,7 +1216,7 @@ class NanCallback { NAN_INLINE void SaveToPersistent( const char *key, const v8::Local &value) { NanScope scope; - NanNew(persistentHandle)->Set(NanNew(key), value); + NanNew(persistentHandle)->Set(NanNew(key).ToLocalChecked(), value); } NAN_INLINE void SaveToPersistent( @@ -1158,7 +1233,8 @@ class NanCallback { NAN_INLINE v8::Local GetFromPersistent(const char *key) const { NanEscapableScope scope; - return scope.Escape(NanNew(persistentHandle)->Get(NanNew(key))); + return scope.Escape( + NanNew(persistentHandle)->Get(NanNew(key).ToLocalChecked())); } NAN_INLINE v8::Local @@ -1192,7 +1268,7 @@ class NanCallback { NanScope scope; v8::Local argv[] = { - v8::Exception::Error(NanNew(ErrorMessage())) + v8::Exception::Error(NanNew(ErrorMessage()).ToLocalChecked()) }; callback->Call(1, argv); } @@ -1498,7 +1574,7 @@ NAN_INLINE void NanSetPrototypeMethod( callback , v8::Handle() , NanNew(recv))->GetFunction(); - v8::Local fn_name = NanNew(name); + v8::Local fn_name = NanNew(name).ToLocalChecked(); recv->PrototypeTemplate()->Set(fn_name, fn); fn->SetName(fn_name); } @@ -1788,7 +1864,7 @@ inline void NanExport(v8::Handle target, const char *name, NanFunctionCallback f) { - target->Set(NanNew(name), + NanSet(target, NanNew(name).ToLocalChecked(), NanNew(f)->GetFunction()); } @@ -1796,7 +1872,7 @@ NanExport(v8::Handle target, const char *name, struct NanTap { explicit NanTap(v8::Handle t) : t_() { - t_.Reset(t->ToObject()); + t_.Reset(NanTo(t).ToLocalChecked()); } ~NanTap() { t_.Reset(); } // not sure if neccessary @@ -1809,13 +1885,13 @@ struct NanTap { inline void ok(bool isOk, const char *msg = NULL) { v8::Handle args[2]; args[0] = NanNew(isOk); - if (msg) args[1] = NanNew(msg); + if (msg) args[1] = NanNew(msg).ToLocalChecked(); NanMakeCallback(NanNew(t_), "ok", msg ? 2 : 1, args); } inline void pass(const char * msg = NULL) { v8::Handle hmsg; - if (msg) hmsg = NanNew(msg); + if (msg) hmsg = NanNew(msg).ToLocalChecked(); NanMakeCallback(NanNew(t_), "pass", msg ? 1 : 0, &hmsg); } diff --git a/nan_converters.h b/nan_converters.h new file mode 100644 index 00000000..776e6d8e --- /dev/null +++ b/nan_converters.h @@ -0,0 +1,65 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2015 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_CONVERTERS_H_ +#define NAN_CONVERTERS_H_ + +namespace Nan { namespace imp { +template struct ToFactoryBase { + typedef NanMaybeLocal return_t; +}; +template struct ValueFactoryBase { typedef NanMaybe return_t; }; + +template struct ToFactory; + +#define X(TYPE) \ + template<> \ + struct ToFactory : ToFactoryBase { \ + static inline return_t convert(v8::Handle val); \ + }; + +X(Boolean) +X(Number) +X(String) +X(Object) +X(Integer) +X(Uint32) +X(Int32) + +#undef X + +#define X(TYPE) \ + template<> \ + struct ToFactory : ValueFactoryBase { \ + static inline return_t convert(v8::Handle val); \ + }; + +X(bool) +X(double) +X(int64_t) +X(uint32_t) +X(int32_t) + +#undef X +} // end of namespace imp +} // end of namespace Nan + +template +NAN_INLINE +typename Nan::imp::ToFactory::return_t NanTo(v8::Handle val) { + return Nan::imp::ToFactory::convert(val); +} + +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +# include "nan_converters_43_inl.h" +#else +# include "nan_converters_pre_43_inl.h" +#endif + +#endif // NAN_CONVERTERS_H_ diff --git a/nan_converters_43_inl.h b/nan_converters_43_inl.h new file mode 100644 index 00000000..ba5fe776 --- /dev/null +++ b/nan_converters_43_inl.h @@ -0,0 +1,42 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2015 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_CONVERTERS_43_INL_H_ +#define NAN_CONVERTERS_43_INL_H_ + +#define X(TYPE) \ +Nan::imp::ToFactory::return_t \ +Nan::imp::ToFactory::convert(v8::Handle val) { \ + return val->To ## TYPE(NanGetCurrentContext()); \ +} + +X(Boolean) +X(Number) +X(String) +X(Object) +X(Integer) +X(Uint32) +X(Int32) + +#undef X + +#define X(TYPE, NAME) \ +Nan::imp::ToFactory::return_t \ +Nan::imp::ToFactory::convert(v8::Handle val) { \ + return val->NAME ##Value(NanGetCurrentContext()); \ +} + +X(bool, Boolean) +X(double, Number) +X(int64_t, Integer) +X(uint32_t, Uint32) +X(int32_t, Int32) + +#undef X + +#endif // NAN_CONVERTERS_43_INL_H_ diff --git a/nan_converters_pre_43_inl.h b/nan_converters_pre_43_inl.h new file mode 100644 index 00000000..f3772da7 --- /dev/null +++ b/nan_converters_pre_43_inl.h @@ -0,0 +1,42 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2015 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_CONVERTERS_PRE_43_INL_H_ +#define NAN_CONVERTERS_PRE_43_INL_H_ + +#define X(TYPE) \ +Nan::imp::ToFactory::return_t \ +Nan::imp::ToFactory::convert(v8::Handle val) { \ + return NanMaybeLocal(val->To ## TYPE()); \ +} + +X(Boolean) +X(Number) +X(String) +X(Object) +X(Integer) +X(Uint32) +X(Int32) + +#undef X + +#define X(TYPE, NAME) \ +Nan::imp::ToFactory::return_t \ +Nan::imp::ToFactory::convert(v8::Handle val) { \ + return NanJust(val->NAME ##Value()); \ +} + +X(bool, Boolean) +X(double, Number) +X(int64_t, Integer) +X(uint32_t, Uint32) +X(int32_t, Int32) + +#undef X + +#endif // NAN_CONVERTERS_PRE_43_INL_H_ diff --git a/nan_implementation_12_inl.h b/nan_implementation_12_inl.h index 8b5d206b..f9af72ce 100644 --- a/nan_implementation_12_inl.h +++ b/nan_implementation_12_inl.h @@ -62,10 +62,25 @@ Factory::New( v8::ExtensionConfiguration* extensions //=== Date ===================================================================== +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) Factory::return_t Factory::New(double value) { - return v8::Date::New(v8::Isolate::GetCurrent(), value).As(); + v8::Local ret; + if (v8::Date::New(NanGetCurrentContext(), value). + ToLocal(reinterpret_cast*>(&ret))) { + return v8::MaybeLocal(ret); + } else { + return v8::MaybeLocal(ret); + } +} +#else +Factory::return_t +Factory::New(double value) { + return Factory::return_t( + v8::Date::New(v8::Isolate::GetCurrent(), value).As()); } +#endif //=== External ================================================================= @@ -84,7 +99,13 @@ Factory::New( NanFunctionCallback callback static std::map cbmap; v8::Local tpl = v8::ObjectTemplate::New(isolate); tpl->SetInternalFieldCount(Nan::imp::kFunctionFieldCount); +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + v8::Local obj = + tpl->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); +#else v8::Local obj = tpl->NewInstance(); +#endif obj->SetAlignedPointerInInternalField( Nan::imp::kFunctionIndex @@ -112,7 +133,13 @@ Factory::New( NanFunctionCallback callback static std::map cbmap; v8::Local tpl = v8::ObjectTemplate::New(isolate); tpl->SetInternalFieldCount(Nan::imp::kFunctionFieldCount); +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) + v8::Local obj = + tpl->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); +#else v8::Local obj = tpl->NewInstance(); +#endif obj->SetAlignedPointerInInternalField( Nan::imp::kFunctionIndex @@ -187,28 +214,56 @@ Factory::New() { //=== RegExp =================================================================== +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +Factory::return_t +Factory::New( + v8::Handle pattern + , v8::RegExp::Flags flags) { + return v8::RegExp::New(NanGetCurrentContext(), pattern, flags); +} +#else Factory::return_t Factory::New( v8::Handle pattern , v8::RegExp::Flags flags) { - return v8::RegExp::New(pattern, flags); + return Factory::return_t(v8::RegExp::New(pattern, flags)); } +#endif //=== Script =================================================================== +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) Factory::return_t Factory::New( v8::Local source) { v8::ScriptCompiler::Source src(source); - return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src); + return v8::ScriptCompiler::Compile(NanGetCurrentContext(), &src); } Factory::return_t Factory::New( v8::Local source , v8::ScriptOrigin const& origin) { v8::ScriptCompiler::Source src(source, origin); - return v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src); + return v8::ScriptCompiler::Compile(NanGetCurrentContext(), &src); +} +#else +Factory::return_t +Factory::New( v8::Local source) { + v8::ScriptCompiler::Source src(source); + return Factory::return_t( + v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src)); } +Factory::return_t +Factory::New( v8::Local source + , v8::ScriptOrigin const& origin) { + v8::ScriptCompiler::Source src(source, origin); + return Factory::return_t( + v8::ScriptCompiler::Compile(v8::Isolate::GetCurrent(), &src)); +} +#endif + //=== Signature ================================================================ Factory::return_t @@ -220,44 +275,100 @@ Factory::New(Factory::FTH receiver) { Factory::return_t Factory::New() { - return v8::String::Empty(v8::Isolate::GetCurrent()); + return Factory::return_t( + v8::String::Empty(v8::Isolate::GetCurrent())); } +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) Factory::return_t Factory::New(const char * value, int length) { - return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), value, - v8::String::kNormalString, length); + return v8::String::NewFromUtf8( + v8::Isolate::GetCurrent(), value, v8::NewStringType::kNormal, length); } Factory::return_t Factory::New(std::string const& value) { assert(value.size() <= INT_MAX && "string too long"); return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), - value.data(), v8::String::kNormalString, static_cast(value.size())); + value.data(), v8::NewStringType::kNormal, static_cast(value.size())); } Factory::return_t Factory::New(const uint8_t * value, int length) { return v8::String::NewFromOneByte(v8::Isolate::GetCurrent(), value, - v8::String::kNormalString, length); + v8::NewStringType::kNormal, length); } Factory::return_t Factory::New(const uint16_t * value, int length) { return v8::String::NewFromTwoByte(v8::Isolate::GetCurrent(), value, - v8::String::kNormalString, length); + v8::NewStringType::kNormal, length); } Factory::return_t Factory::New(v8::String::ExternalStringResource * value) { - return v8::String::NewExternal(v8::Isolate::GetCurrent(), value); + return v8::String::NewExternalTwoByte(v8::Isolate::GetCurrent(), value); } Factory::return_t Factory::New(NanExternalOneByteStringResource * value) { - return v8::String::NewExternal(v8::Isolate::GetCurrent(), value); + return v8::String::NewExternalOneByte(v8::Isolate::GetCurrent(), value); +} +#else +Factory::return_t +Factory::New(const char * value, int length) { + return Factory::return_t( + v8::String::NewFromUtf8( + v8::Isolate::GetCurrent() + , value + , v8::String::kNormalString + , length)); } +Factory::return_t +Factory::New(std::string const& value) { + assert(value.size() <= INT_MAX && "string too long"); + return Factory::return_t( + v8::String::NewFromUtf8( + v8::Isolate::GetCurrent() + , value.data() + , v8::String::kNormalString + , static_cast(value.size()))); +} + +Factory::return_t +Factory::New(const uint8_t * value, int length) { + return Factory::return_t( + v8::String::NewFromOneByte( + v8::Isolate::GetCurrent() + , value + , v8::String::kNormalString, length)); +} + +Factory::return_t +Factory::New(const uint16_t * value, int length) { + return Factory::return_t( + v8::String::NewFromTwoByte( + v8::Isolate::GetCurrent() + , value + , v8::String::kNormalString + , length)); +} + +Factory::return_t +Factory::New(v8::String::ExternalStringResource * value) { + return Factory::return_t( + v8::String::NewExternal(v8::Isolate::GetCurrent(), value)); +} + +Factory::return_t +Factory::New(NanExternalOneByteStringResource * value) { + return Factory::return_t( + v8::String::NewExternal(v8::Isolate::GetCurrent(), value)); +} +#endif + //=== String Object ============================================================ Factory::return_t @@ -267,18 +378,38 @@ Factory::New(v8::Handle value) { //=== Unbound Script =========================================================== +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) +Factory::return_t +Factory::New(v8::Local source) { + v8::ScriptCompiler::Source src(source); + return v8::ScriptCompiler::CompileUnboundScript( + v8::Isolate::GetCurrent(), &src); +} + +Factory::return_t +Factory::New( v8::Local source + , v8::ScriptOrigin const& origin) { + v8::ScriptCompiler::Source src(source, origin); + return v8::ScriptCompiler::CompileUnboundScript( + v8::Isolate::GetCurrent(), &src); +} +#else Factory::return_t Factory::New(v8::Local source) { v8::ScriptCompiler::Source src(source); - return v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src); + return Factory::return_t( + v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src)); } Factory::return_t Factory::New( v8::Local source , v8::ScriptOrigin const& origin) { v8::ScriptCompiler::Source src(source, origin); - return v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src); + return Factory::return_t( + v8::ScriptCompiler::CompileUnbound(v8::Isolate::GetCurrent(), &src)); } +#endif } // end of namespace imp } // end of namespace Nan diff --git a/nan_implementation_pre_12_inl.h b/nan_implementation_pre_12_inl.h index 9473b0b8..6b222b8c 100644 --- a/nan_implementation_pre_12_inl.h +++ b/nan_implementation_pre_12_inl.h @@ -72,7 +72,7 @@ Factory::New( v8::ExtensionConfiguration* extensions Factory::return_t Factory::New(double value) { - return v8::Date::New(value).As(); + return Factory::return_t(v8::Date::New(value).As()); } //=== External ================================================================= @@ -184,19 +184,20 @@ Factory::return_t Factory::New( v8::Handle pattern , v8::RegExp::Flags flags) { - return v8::RegExp::New(pattern, flags); + return Factory::return_t(v8::RegExp::New(pattern, flags)); } //=== Script =================================================================== Factory::return_t Factory::New( v8::Local source) { - return v8::Script::New(source); + return Factory::return_t(v8::Script::New(source)); } Factory::return_t Factory::New( v8::Local source , v8::ScriptOrigin const& origin) { - return v8::Script::New(source, const_cast(&origin)); + return Factory::return_t( + v8::Script::New(source, const_cast(&origin))); } //=== Signature ================================================================ @@ -210,18 +211,19 @@ Factory::New(Factory::FTH receiver) { Factory::return_t Factory::New() { - return v8::String::Empty(); + return Factory::return_t(v8::String::Empty()); } Factory::return_t Factory::New(const char * value, int length) { - return v8::String::New(value, length); + return Factory::return_t(v8::String::New(value, length)); } Factory::return_t Factory::New(std::string const& value) { assert(value.size() <= INT_MAX && "string too long"); - return v8::String::New( value.data(), static_cast(value.size())); + return Factory::return_t( + v8::String::New( value.data(), static_cast(value.size()))); } inline @@ -238,7 +240,7 @@ widenString(std::vector *ws, const uint8_t *s, int l = -1) { Factory::return_t Factory::New(const uint16_t * value, int length) { - return v8::String::New(value, length); + return Factory::return_t(v8::String::New(value, length)); } Factory::return_t @@ -246,21 +248,21 @@ Factory::New(const uint8_t * value, int length) { std::vector wideString; widenString(&wideString, value, length); if (wideString.size() == 0) { - return v8::String::Empty(); + return Factory::return_t(v8::String::Empty()); } else { - return v8::String::New(&wideString.front() - , static_cast(wideString.size())); + return Factory::return_t(v8::String::New(&wideString.front() + , static_cast(wideString.size()))); } } Factory::return_t Factory::New(v8::String::ExternalStringResource * value) { - return v8::String::NewExternal(value); + return Factory::return_t(v8::String::NewExternal(value)); } Factory::return_t Factory::New(v8::String::ExternalAsciiStringResource * value) { - return v8::String::NewExternal(value); + return Factory::return_t(v8::String::NewExternal(value)); } //=== String Object ============================================================ diff --git a/nan_maybe_43_inl.h b/nan_maybe_43_inl.h new file mode 100644 index 00000000..0af39976 --- /dev/null +++ b/nan_maybe_43_inl.h @@ -0,0 +1,228 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2015 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_MAYBE_43_INL_H_ +#define NAN_MAYBE_43_INL_H_ + +template +class NanMaybeLocal : public v8::MaybeLocal { + public: + NanMaybeLocal(const v8::MaybeLocal &that) : // NOLINT(runtime/explicit) + v8::MaybeLocal(that) {} +}; + +template +class NanMaybe : public v8::Maybe { + public: + NanMaybe(const v8::Maybe &that) : // NOLINT(runtime/explicit) + v8::Maybe(that) {} +}; + +template +inline NanMaybe NanNothing() { + return v8::Nothing(); +} + +template +inline NanMaybe NanJust(const T& t) { + return v8::Just(t); +} + +v8::Local NanGetCurrentContext(); + + +NAN_INLINE +NanMaybeLocal NanToDetailString(v8::Handle val) { + return val->ToDetailString(NanGetCurrentContext()); +} + +NAN_INLINE +NanMaybeLocal NanToArrayIndex(v8::Handle val) { + return val->ToArrayIndex(NanGetCurrentContext()); +} + +NAN_INLINE +NanMaybe NanEquals(v8::Handle a, v8::Handle(b)) { + return a->Equals(NanGetCurrentContext(), b); +} + +NAN_INLINE +NanMaybeLocal NanNewInstance(v8::Handle h) { + return NanMaybeLocal(h->NewInstance(NanGetCurrentContext())); +} + +NAN_INLINE +NanMaybeLocal NanNewInstance(v8::Handle h) { + return NanMaybeLocal(h->NewInstance(NanGetCurrentContext())); +} + + +NAN_INLINE NanMaybeLocal NanGetFunction( + v8::Handle t) { + return t->GetFunction(NanGetCurrentContext()); +} + +NAN_INLINE NanMaybe NanSet( + v8::Handle obj + , v8::Handle key + , v8::Handle value) { + return obj->Set(NanGetCurrentContext(), key, value); +} + +NAN_INLINE NanMaybe NanSet( + v8::Handle obj + , uint32_t index + , v8::Handle value) { + return obj->Set(NanGetCurrentContext(), index, value); +} + +NAN_INLINE NanMaybe NanForceSet( + v8::Handle obj + , v8::Handle key + , v8::Handle value + , v8::PropertyAttribute attribs = v8::None) { + return obj->ForceSet(NanGetCurrentContext(), key, value, attribs); +} + +NAN_INLINE NanMaybeLocal NanGet( + v8::Handle obj + , v8::Handle key) { + return obj->Get(NanGetCurrentContext(), key); +} + +NAN_INLINE +NanMaybeLocal NanGet(v8::Handle obj, uint32_t index) { + return obj->Get(NanGetCurrentContext(), index); +} + +NAN_INLINE v8::PropertyAttribute NanGetPropertyAttributes( + v8::Handle obj + , v8::Handle key) { + return obj->GetPropertyAttributes(NanGetCurrentContext(), key).FromJust(); +} + +NAN_INLINE NanMaybe NanHas( + v8::Handle obj + , v8::Handle key) { + return obj->Has(NanGetCurrentContext(), key); +} + +NAN_INLINE NanMaybe NanHas(v8::Handle obj, uint32_t index) { + return obj->Has(NanGetCurrentContext(), index); +} + +NAN_INLINE NanMaybe NanDelete( + v8::Handle obj + , v8::Handle key) { + return obj->Delete(NanGetCurrentContext(), key); +} + +NAN_INLINE +NanMaybe NanDelete(v8::Handle obj, uint32_t index) { + return obj->Delete(NanGetCurrentContext(), index); +} + +NAN_INLINE +NanMaybeLocal NanGetPropertyNames(v8::Handle obj) { + return obj->GetPropertyNames(NanGetCurrentContext()); +} + +NAN_INLINE +NanMaybeLocal NanGetOwnPropertyNames(v8::Handle obj) { + return obj->GetOwnPropertyNames(NanGetCurrentContext()); +} + +NAN_INLINE NanMaybe NanSetPrototype( + v8::Handle obj + , v8::Handle prototype) { + return obj->SetPrototype(NanGetCurrentContext(), prototype); +} + +NAN_INLINE NanMaybeLocal NanObjectProtoToString( + v8::Handle obj) { + return obj->ObjectProtoToString(NanGetCurrentContext()); +} + +NAN_INLINE NanMaybe NanHasOwnProperty( + v8::Handle obj + , v8::Handle key) { + return obj->HasOwnProperty(NanGetCurrentContext(), key); +} + +NAN_INLINE NanMaybe NanHasRealNamedProperty( + v8::Handle obj + , v8::Handle key) { + return obj->HasRealNamedProperty(NanGetCurrentContext(), key); +} + +NAN_INLINE NanMaybe NanHasRealIndexedProperty( + v8::Handle obj + , uint32_t index) { + return obj->HasRealIndexedProperty(NanGetCurrentContext(), index); +} + +NAN_INLINE NanMaybe NanHasRealNamedCallbackProperty( + v8::Handle obj + , v8::Handle key) { + return obj->HasRealNamedCallbackProperty(NanGetCurrentContext(), key); +} + +NAN_INLINE NanMaybeLocal NanGetRealNamedPropertyInPrototypeChain( + v8::Handle obj + , v8::Handle key) { + return obj->GetRealNamedPropertyInPrototypeChain(NanGetCurrentContext(), key); +} + +NAN_INLINE NanMaybeLocal NanGetRealNamedProperty( + v8::Handle obj + , v8::Handle key) { + return obj->GetRealNamedProperty(NanGetCurrentContext(), key); +} + +NAN_INLINE NanMaybeLocal NanCallAsFunction( + v8::Handle obj + , v8::Handle recv + , int argc + , v8::Handle argv[]) { + return obj->CallAsFunction(NanGetCurrentContext(), recv, argc, argv); +} + +NAN_INLINE NanMaybeLocal NanCallAsConstructor( + v8::Handle obj + , int argc, v8::Local argv[]) { + return obj->CallAsConstructor(NanGetCurrentContext(), argc, argv); +} + +NAN_INLINE +NanMaybeLocal NanGetSourceLine(v8::Handle msg) { + return msg->GetSourceLine(NanGetCurrentContext()); +} + +NAN_INLINE NanMaybe NanGetLineNumber(v8::Handle msg) { + return msg->GetLineNumber(NanGetCurrentContext()); +} + +NAN_INLINE NanMaybe NanGetStartColumn(v8::Handle msg) { + return msg->GetStartColumn(NanGetCurrentContext()); +} + +NAN_INLINE NanMaybe NanGetEndColumn(v8::Handle msg) { + return msg->GetEndColumn(NanGetCurrentContext()); +} + +NAN_INLINE NanMaybeLocal NanCloneElementAt( + v8::Handle array + , uint32_t index) { + return array->CloneElementAt(NanGetCurrentContext(), index); +} + +NAN_INLINE NanMaybeLocal NanStackTrace(v8::TryCatch trycatch) { + return trycatch.StackTrace(NanGetCurrentContext()); +} + +#endif // NAN_MAYBE_43_INL_H_ diff --git a/nan_maybe_pre_43_inl.h b/nan_maybe_pre_43_inl.h new file mode 100644 index 00000000..a7f721d4 --- /dev/null +++ b/nan_maybe_pre_43_inl.h @@ -0,0 +1,291 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2015 NAN contributors + * + * MIT License + ********************************************************************/ + +#ifndef NAN_MAYBE_PRE_43_INL_H_ +#define NAN_MAYBE_PRE_43_INL_H_ + +template +class NanMaybeLocal { + public: + NAN_INLINE NanMaybeLocal() : val_(v8::Local()) {} + + template +# if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION + NAN_INLINE NanMaybeLocal(v8::Local that) : val_(that) {} +# else + NAN_INLINE NanMaybeLocal(v8::Local that) : + val_(*reinterpret_cast*>(&that)) {} +# endif + + NAN_INLINE bool IsEmpty() { return val_->IsEmpty(); } + + template + NAN_INLINE bool ToLocal(v8::Local *out) { + *out = val_; + return !IsEmpty(); + } + + NAN_INLINE v8::Local ToLocalChecked() { +#if defined(V8_ENABLE_CHECKS) + assert(!IsEmpty() && "ToLocalChecked is Empty"); +#endif // V8_ENABLE_CHECKS + return val_; + } + + template + NAN_INLINE v8::Local FromMaybe(v8::Local default_value) const { + return IsEmpty() ? default_value : val_; + } + + private: + v8::Local val_; +}; + +template +class NanMaybe { + public: + NAN_INLINE bool IsNothing() const { return !has_value_; } + NAN_INLINE bool IsJust() const { return has_value_; } + + NAN_INLINE T FromJust() const { +#if defined(V8_ENABLE_CHECKS) + assert(IsJust() && "FromJust is Nothing"); +#endif // V8_ENABLE_CHECKS + return value_; + } + + NAN_INLINE T FromMaybe(const T& default_value) const { + return has_value_ ? value_ : default_value; + } + + NAN_INLINE bool operator==(const NanMaybe &other) const { + return (IsJust() == other.IsJust()) && + (!IsJust() || FromJust() == other.FromJust()); + } + + NAN_INLINE bool operator!=(const NanMaybe &other) const { + return !operator==(other); + } + + private: + NanMaybe() : has_value_(false) {} + explicit NanMaybe(const T& t) : has_value_(true), value_(t) {} + bool has_value_; + T value_; + + template + friend NanMaybe NanNothing(); + template + friend NanMaybe NanJust(const U& u); +}; + +template +inline NanMaybe NanNothing() { + return NanMaybe(); +} + +template +inline NanMaybe NanJust(const T& t) { + return NanMaybe(t); +} + +NAN_INLINE +NanMaybeLocal NanToDetailString(v8::Handle val) { + return NanMaybeLocal(val->ToDetailString()); +} + +NAN_INLINE +NanMaybeLocal NanToArrayIndex(v8::Handle val) { + return NanMaybeLocal(val->ToArrayIndex()); +} + +NAN_INLINE +NanMaybe NanEquals(v8::Handle a, v8::Handle(b)) { + return NanJust(a->Equals(b)); +} + +NAN_INLINE +NanMaybeLocal NanNewInstance(v8::Handle h) { + return NanMaybeLocal(h->NewInstance()); +} + +NAN_INLINE +NanMaybeLocal NanNewInstance(v8::Handle h) { + return NanMaybeLocal(h->NewInstance()); +} + +NAN_INLINE +NanMaybeLocal NanGetFunction(v8::Handle t) { + return NanMaybeLocal(t->GetFunction()); +} + +NAN_INLINE NanMaybe NanSet( + v8::Handle obj + , v8::Handle key + , v8::Handle value) { + return NanJust(obj->Set(key, value)); +} + +NAN_INLINE NanMaybe NanSet( + v8::Handle obj + , uint32_t index + , v8::Handle value) { + return NanJust(obj->Set(index, value)); +} + +NAN_INLINE NanMaybe NanForceSet( + v8::Handle obj + , v8::Handle key + , v8::Handle value + , v8::PropertyAttribute attribs = v8::None) { + return NanJust(obj->ForceSet(key, value, attribs)); +} + +NAN_INLINE NanMaybeLocal NanGet( + v8::Handle obj + , v8::Handle key) { + return NanMaybeLocal(obj->Get(key)); +} + +NAN_INLINE NanMaybeLocal NanGet( + v8::Handle obj + , uint32_t index) { + return NanMaybeLocal(obj->Get(index)); +} + +NAN_INLINE NanMaybe NanGetPropertyAttributes( + v8::Handle obj + , v8::Handle key) { + return NanJust(obj->GetPropertyAttributes(key)); +} + +NAN_INLINE NanMaybe NanHas( + v8::Handle obj + , v8::Handle key) { + return NanJust(obj->Has(key)); +} + +NAN_INLINE NanMaybe NanHas( + v8::Handle obj + , uint32_t index) { + return NanJust(obj->Has(index)); +} + +NAN_INLINE NanMaybe NanDelete( + v8::Handle obj + , v8::Handle key) { + return NanJust(obj->Delete(key)); +} + +NAN_INLINE NanMaybe NanDelete( + v8::Handle obj + , uint32_t index) { + return NanJust(obj->Delete(index)); +} + +NAN_INLINE +NanMaybeLocal NanGetPropertyNames(v8::Handle obj) { + return NanMaybeLocal(obj->GetPropertyNames()); +} + +NAN_INLINE +NanMaybeLocal NanGetOwnPropertyNames(v8::Handle obj) { + return NanMaybeLocal(obj->GetOwnPropertyNames()); +} + +NAN_INLINE NanMaybe NanSetPrototype( + v8::Handle obj + , v8::Handle prototype) { + return NanJust(obj->SetPrototype(prototype)); +} + +NAN_INLINE NanMaybeLocal NanObjectProtoToString( + v8::Handle obj) { + return NanMaybeLocal(obj->ObjectProtoToString()); +} + +NAN_INLINE NanMaybe NanHasOwnProperty( + v8::Handle obj + , v8::Handle key) { + return NanJust(obj->HasOwnProperty(key)); +} + +NAN_INLINE NanMaybe NanHasRealNamedProperty( + v8::Handle obj + , v8::Handle key) { + return NanJust(obj->HasRealNamedProperty(key)); +} + +NAN_INLINE NanMaybe NanHasRealIndexedProperty( + v8::Handle obj + , uint32_t index) { + return NanJust(obj->HasRealIndexedProperty(index)); +} + +NAN_INLINE NanMaybe NanHasRealNamedCallbackProperty( + v8::Handle obj + , v8::Handle key) { + return NanJust(obj->HasRealNamedCallbackProperty(key)); +} + +NAN_INLINE NanMaybeLocal NanGetRealNamedPropertyInPrototypeChain( + v8::Handle obj + , v8::Handle key) { + return NanMaybeLocal( + obj->GetRealNamedPropertyInPrototypeChain(key)); +} + +NAN_INLINE NanMaybeLocal NanGetRealNamedProperty( + v8::Handle obj + , v8::Handle key) { + return NanMaybeLocal(obj->GetRealNamedProperty(key)); +} + +NAN_INLINE NanMaybeLocal NanCallAsFunction( + v8::Handle obj + , v8::Handle recv + , int argc + , v8::Handle argv[]) { + return NanMaybeLocal(obj->CallAsFunction(recv, argc, argv)); +} + +NAN_INLINE NanMaybeLocal NanCallAsConstructor( + v8::Handle obj + , int argc + , v8::Local argv[]) { + return NanMaybeLocal(obj->CallAsConstructor(argc, argv)); +} + +NAN_INLINE +NanMaybeLocal NanGetSourceLine(v8::Handle msg) { + return NanMaybeLocal(msg->GetSourceLine()); +} + +NAN_INLINE NanMaybe NanGetLineNumber(v8::Handle msg) { + return NanJust(msg->GetLineNumber()); +} + +NAN_INLINE NanMaybe NanGetStartColumn(v8::Handle msg) { + return NanJust(msg->GetStartColumn()); +} + +NAN_INLINE NanMaybe NanGetEndColumn(v8::Handle msg) { + return NanJust(msg->GetEndColumn()); +} + +NAN_INLINE NanMaybeLocal NanCloneElementAt( + v8::Handle array + , uint32_t index) { + return NanMaybeLocal(array->CloneElementAt(index)); +} + +NAN_INLINE NanMaybeLocal NanStackTrace(v8::TryCatch trycatch) { + return NanMaybeLocal(trycatch.StackTrace()); +} + +#endif // NAN_MAYBE_PRE_43_INL_H_ diff --git a/nan_new.h b/nan_new.h index 67429f5d..3d5bcf71 100644 --- a/nan_new.h +++ b/nan_new.h @@ -26,19 +26,31 @@ template v8::Local To(v8::Handle i); template <> inline v8::Local -To(v8::Handle i) { return i->ToInteger(); } +To(v8::Handle i) { + return NanTo(i).ToLocalChecked(); +} template <> inline v8::Local -To(v8::Handle i) { return i->ToInt32(); } +To(v8::Handle i) { + return NanTo(i).ToLocalChecked(); +} template <> inline v8::Local -To(v8::Handle i) { return i->ToUint32(); } +To(v8::Handle i) { + return NanTo(i).ToLocalChecked(); +} -template struct FactoryBase { typedef v8::Local return_t; }; +template struct FactoryBase { + typedef v8::Local return_t; +}; + +template struct MaybeFactoryBase { + typedef NanMaybeLocal return_t; +}; template struct Factory; @@ -68,7 +80,7 @@ struct Factory : FactoryBase { }; template <> -struct Factory : FactoryBase { +struct Factory : MaybeFactoryBase { static inline return_t New(double value); }; @@ -134,13 +146,13 @@ struct Factory : FactoryBase { }; template <> -struct Factory : FactoryBase { +struct Factory : MaybeFactoryBase { static inline return_t New( v8::Handle pattern, v8::RegExp::Flags flags); }; template <> -struct Factory : FactoryBase { +struct Factory : MaybeFactoryBase { static inline return_t New( v8::Local source); static inline return_t New( v8::Local source , v8::ScriptOrigin const& origin); @@ -153,7 +165,7 @@ struct Factory : FactoryBase { }; template <> -struct Factory : FactoryBase { +struct Factory : MaybeFactoryBase { 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); @@ -179,7 +191,7 @@ struct Factory : FactoryBase { namespace Nan { namespace imp { template <> -struct Factory : FactoryBase { +struct Factory : MaybeFactoryBase { static inline return_t New( v8::Local source); static inline return_t New( v8::Local source , v8::ScriptOrigin const& origin); diff --git a/nan_string_bytes.h b/nan_string_bytes.h index 44122f07..f5040a5e 100644 --- a/nan_string_bytes.h +++ b/nan_string_bytes.h @@ -233,7 +233,7 @@ static Local Encode(const char* buf, enum Nan::Encoding encoding) { assert(buflen <= node::Buffer::kMaxLength); if (!buflen && encoding != Nan::BUFFER) - return NanNew(""); + return NanNew("").ToLocalChecked(); Local val; switch (encoding) { @@ -244,15 +244,15 @@ static Local Encode(const char* buf, if (contains_non_ascii(buf, buflen)) { char* out = new char[buflen]; force_ascii(buf, out, buflen); - val = NanNew(out, buflen); + val = NanNew(out, buflen).ToLocalChecked(); delete[] out; } else { - val = NanNew(buf, buflen); + val = NanNew(buf, buflen).ToLocalChecked(); } break; case Nan::UTF8: - val = NanNew(buf, buflen); + val = NanNew(buf, buflen).ToLocalChecked(); break; case Nan::BINARY: { @@ -263,7 +263,7 @@ static Local Encode(const char* buf, // XXX is the following line platform independent? twobytebuf[i] = cbuf[i]; } - val = NanNew(twobytebuf, buflen); + val = NanNew(twobytebuf, buflen).ToLocalChecked(); delete[] twobytebuf; break; } @@ -275,14 +275,14 @@ static Local Encode(const char* buf, size_t written = base64_encode(buf, buflen, dst, dlen); assert(written == dlen); - val = NanNew(dst, dlen); + val = NanNew(dst, dlen).ToLocalChecked(); delete[] dst; break; } case Nan::UCS2: { const uint16_t* data = reinterpret_cast(buf); - val = NanNew(data, buflen / 2); + val = NanNew(data, buflen / 2).ToLocalChecked(); break; } @@ -292,7 +292,7 @@ static Local Encode(const char* buf, size_t written = hex_encode(buf, buflen, dst, dlen); assert(written == dlen); - val = NanNew(dst, dlen); + val = NanNew(dst, dlen).ToLocalChecked(); delete[] dst; break; } diff --git a/test/binding.gyp b/test/binding.gyp index 9ed98a0d..e6efaee8 100644 --- a/test/binding.gyp +++ b/test/binding.gyp @@ -49,6 +49,10 @@ "target_name" : "accessors" , "sources" : [ "cpp/accessors.cpp" ] } + , { + "target_name" : "accessors2" + , "sources" : [ "cpp/accessors2.cpp" ] + } , { "target_name" : "persistent" , "sources" : [ "cpp/persistent.cpp" ] @@ -120,4 +124,8 @@ "target_name" : "indexedinterceptors" , "sources" : [ "cpp/indexedinterceptors.cpp" ] } + , { + "target_name" : "converters" + , "sources" : [ "cpp/converters.cpp" ] + } ]} diff --git a/test/cpp/accessors.cpp b/test/cpp/accessors.cpp index fa6e455a..5ebb0303 100644 --- a/test/cpp/accessors.cpp +++ b/test/cpp/accessors.cpp @@ -43,21 +43,24 @@ void SetterGetter::Init(v8::Handle target) { v8::Local tpl = NanNew(SetterGetter::New); settergetter_constructor.Reset(tpl); - tpl->SetClassName(NanNew("SetterGetter")); + tpl->SetClassName(NanNew("SetterGetter").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); NanSetPrototypeMethod(tpl, "log", SetterGetter::Log); v8::Local proto = tpl->PrototypeTemplate(); - NanSetAccessor(proto, NanNew("prop1"), SetterGetter::GetProp1); NanSetAccessor( - proto - , NanNew("prop2") - , SetterGetter::GetProp2 - , SetterGetter::SetProp2 + proto + , NanNew("prop1").ToLocalChecked() + , SetterGetter::GetProp1); + NanSetAccessor( + proto + , NanNew("prop2").ToLocalChecked() + , SetterGetter::GetProp2 + , SetterGetter::SetProp2 ); v8::Local createnew = NanNew(CreateNew)->GetFunction(); - target->Set(NanNew("create"), createnew); + NanSet(target, NanNew("create").ToLocalChecked(), createnew); } v8::Handle SetterGetter::NewInstance () { @@ -100,7 +103,7 @@ NAN_GETTER(SetterGetter::GetProp1) { , ")\n" , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - info.GetReturnValue().Set(NanNew(settergetter->prop1)); + info.GetReturnValue().Set(NanNew(settergetter->prop1).ToLocalChecked()); } NAN_GETTER(SetterGetter::GetProp2) { @@ -122,7 +125,7 @@ NAN_GETTER(SetterGetter::GetProp2) { , ")\n" , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); - info.GetReturnValue().Set(NanNew(settergetter->prop2)); + info.GetReturnValue().Set(NanNew(settergetter->prop2).ToLocalChecked()); } NAN_SETTER(SetterGetter::SetProp2) { @@ -154,7 +157,7 @@ NAN_METHOD(SetterGetter::Log) { SetterGetter* settergetter = NanObjectWrap::Unwrap(info.This()); - info.GetReturnValue().Set(NanNew(settergetter->log)); + info.GetReturnValue().Set(NanNew(settergetter->log).ToLocalChecked()); } NODE_MODULE(accessors, SetterGetter::Init) diff --git a/test/cpp/accessors2.cpp b/test/cpp/accessors2.cpp new file mode 100644 index 00000000..f50c5cce --- /dev/null +++ b/test/cpp/accessors2.cpp @@ -0,0 +1,161 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2015 NAN contributors + * + * MIT License + ********************************************************************/ + +#include +#include + +class SetterGetter : public NanObjectWrap { + public: + static void Init (v8::Handle target); + static v8::Handle NewInstance (); + static NAN_METHOD(New); + static NAN_METHOD(Log); + static NAN_GETTER(GetProp1); + static NAN_GETTER(GetProp2); + static NAN_SETTER(SetProp2); + + SetterGetter(); + + char log[1024]; + char prop1[256]; + char prop2[256]; +}; + +static NanPersistent settergetter_constructor; + +NAN_METHOD(CreateNew) { + info.GetReturnValue().Set(SetterGetter::NewInstance()); +} + +SetterGetter::SetterGetter() { + log[0] = '\0'; + strncpy(prop1, "this is property 1", sizeof (prop1) - 1); + prop1[sizeof (prop1) - 1] = '\0'; + prop2[0] = '\0'; +} + +void SetterGetter::Init(v8::Handle target) { + v8::Local tpl = + NanNew(SetterGetter::New); + settergetter_constructor.Reset(tpl); + tpl->SetClassName(NanNew("SetterGetter").ToLocalChecked()); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + NanSetPrototypeMethod(tpl, "log", SetterGetter::Log); + v8::Local createnew = + NanNew(CreateNew)->GetFunction(); + NanSet(target, NanNew("create").ToLocalChecked(), createnew); +} + +v8::Handle SetterGetter::NewInstance () { + NanEscapableScope scope; + v8::Local constructorHandle = + NanNew(settergetter_constructor); + v8::Local instance = + constructorHandle->GetFunction()->NewInstance(0, NULL); + NanSetAccessor( + instance + , NanNew("prop1").ToLocalChecked() + , SetterGetter::GetProp1); + NanSetAccessor( + instance + , NanNew("prop2").ToLocalChecked() + , SetterGetter::GetProp2 + , SetterGetter::SetProp2 + ); + return scope.Escape(instance); +} + +NAN_METHOD(SetterGetter::New) { + SetterGetter* settergetter = new SetterGetter(); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , "New()\n" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + settergetter->Wrap(info.This()); + + info.GetReturnValue().Set(info.This()); +} + +NAN_GETTER(SetterGetter::GetProp1) { + SetterGetter* settergetter = + NanObjectWrap::Unwrap(info.This()); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , "Prop1:GETTER(" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , settergetter->prop1 + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , ")\n" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + + info.GetReturnValue().Set(NanNew(settergetter->prop1).ToLocalChecked()); +} + +NAN_GETTER(SetterGetter::GetProp2) { + SetterGetter* settergetter = + NanObjectWrap::Unwrap(info.This()); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , "Prop2:GETTER(" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , settergetter->prop2 + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , ")\n" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + + info.GetReturnValue().Set(NanNew(settergetter->prop2).ToLocalChecked()); +} + +NAN_SETTER(SetterGetter::SetProp2) { + SetterGetter* settergetter = + NanObjectWrap::Unwrap(info.This()); + strncpy( + settergetter->prop2 + , *v8::String::Utf8Value(value) + , sizeof (settergetter->prop2)); + settergetter->prop2[sizeof (settergetter->prop2) - 1] = '\0'; + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , "Prop2:SETTER(" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , settergetter->prop2 + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); + assert(strlen(settergetter->log) < sizeof (settergetter->log)); + strncat( + settergetter->log + , ")\n" + , sizeof (settergetter->log) - 1 - strlen(settergetter->log)); +} + +NAN_METHOD(SetterGetter::Log) { + SetterGetter* settergetter = + NanObjectWrap::Unwrap(info.This()); + + info.GetReturnValue().Set(NanNew(settergetter->log).ToLocalChecked()); +} + +NODE_MODULE(accessors2, SetterGetter::Init) diff --git a/test/cpp/asyncprogressworker.cpp b/test/cpp/asyncprogressworker.cpp index 1024755f..46bf2f06 100644 --- a/test/cpp/asyncprogressworker.cpp +++ b/test/cpp/asyncprogressworker.cpp @@ -51,14 +51,13 @@ NAN_METHOD(DoProgress) { NanAsyncQueueWorker(new ProgressWorker( callback , progress - , info[0]->Uint32Value() - , info[1]->Uint32Value())); - info.GetReturnValue().SetUndefined(); + , NanTo(info[0]).FromJust() + , NanTo(info[1]).FromJust())); } void Init(v8::Handle exports) { - exports->Set( - NanNew("a") + NanSet(exports + , NanNew("a").ToLocalChecked() , NanNew(DoProgress)->GetFunction()); } diff --git a/test/cpp/asyncworker.cpp b/test/cpp/asyncworker.cpp index a66a00b2..f7ddb326 100644 --- a/test/cpp/asyncworker.cpp +++ b/test/cpp/asyncworker.cpp @@ -28,13 +28,13 @@ class SleepWorker : public NanAsyncWorker { NAN_METHOD(DoSleep) { NanCallback *callback = new NanCallback(info[1].As()); - NanAsyncQueueWorker(new SleepWorker(callback, info[0]->Uint32Value())); - info.GetReturnValue().SetUndefined(); + NanAsyncQueueWorker( + new SleepWorker(callback, NanTo(info[0]).FromJust())); } void Init(v8::Handle exports) { - exports->Set( - NanNew("a") + NanSet(exports + , NanNew("a").ToLocalChecked() , NanNew(DoSleep)->GetFunction()); } diff --git a/test/cpp/asyncworkererror.cpp b/test/cpp/asyncworkererror.cpp index c30935b3..244368ae 100644 --- a/test/cpp/asyncworkererror.cpp +++ b/test/cpp/asyncworkererror.cpp @@ -25,7 +25,9 @@ NAN_METHOD(Work) { } void Init (v8::Handle exports) { - exports->Set(NanNew("a"), NanNew(Work)->GetFunction()); + NanSet(exports + , NanNew("a").ToLocalChecked() + , NanNew(Work)->GetFunction()); } NODE_MODULE(asyncworkererror, Init) diff --git a/test/cpp/bufferworkerpersistent.cpp b/test/cpp/bufferworkerpersistent.cpp index fb89ff97..31606b7b 100644 --- a/test/cpp/bufferworkerpersistent.cpp +++ b/test/cpp/bufferworkerpersistent.cpp @@ -21,7 +21,7 @@ class BufferWorker : public NanAsyncWorker { ) : NanAsyncWorker(callback), milliseconds(milliseconds) { SaveToPersistent("buffer", bufferHandle); - SaveToPersistent(NanNew("puffer"), bufferHandle); + SaveToPersistent(NanNew("puffer").ToLocalChecked(), bufferHandle); SaveToPersistent(0u, bufferHandle); } @@ -37,7 +37,7 @@ class BufferWorker : public NanAsyncWorker { v8::Local handle = GetFromPersistent("buffer"); callback->Call(1, &handle); - handle = GetFromPersistent(NanNew("puffer")); + handle = GetFromPersistent(NanNew("puffer").ToLocalChecked()); callback->Call(1, &handle); handle = GetFromPersistent(0u); @@ -52,14 +52,15 @@ NAN_METHOD(DoSleep) { v8::Local bufferHandle = info[1].As(); NanCallback *callback = new NanCallback(info[2].As()); assert(!callback->IsEmpty() && "Callback shoud not be empty"); - NanAsyncQueueWorker( - new BufferWorker(callback, info[0]->Uint32Value(), bufferHandle)); - info.GetReturnValue().SetUndefined(); + NanAsyncQueueWorker(new BufferWorker( + callback + , NanTo(info[0]).FromJust() + , bufferHandle)); } void Init(v8::Handle exports) { - exports->Set( - NanNew("a") + NanSet(exports + , NanNew("a").ToLocalChecked() , NanNew(DoSleep)->GetFunction()); } diff --git a/test/cpp/converters.cpp b/test/cpp/converters.cpp new file mode 100644 index 00000000..1418d2bd --- /dev/null +++ b/test/cpp/converters.cpp @@ -0,0 +1,128 @@ +/********************************************************************* + * NAN - Native Abstractions for Node.js + * + * Copyright (c) 2015 NAN contributors + * + * MIT License + ********************************************************************/ + +#include + +NAN_METHOD(ToBoolean) { + info.GetReturnValue().Set(NanTo(info[0]).ToLocalChecked()); +} + +NAN_METHOD(ToNumber) { + info.GetReturnValue().Set(NanTo(info[0]).ToLocalChecked()); +} + +NAN_METHOD(ToString) { + info.GetReturnValue().Set(NanTo(info[0]).ToLocalChecked()); +} + +NAN_METHOD(ToDetailString) { + info.GetReturnValue().Set(NanToDetailString(info[0]).ToLocalChecked()); +} + +NAN_METHOD(ToObject) { + info.GetReturnValue().Set(NanTo(info[0]).ToLocalChecked()); +} + +NAN_METHOD(ToInteger) { + info.GetReturnValue().Set(NanTo(info[0]).ToLocalChecked()); +} + +NAN_METHOD(ToUint32) { + info.GetReturnValue().Set(NanTo(info[0]).ToLocalChecked()); +} + +NAN_METHOD(ToInt32) { + info.GetReturnValue().Set(NanTo(info[0]).ToLocalChecked()); +} + +NAN_METHOD(ToArrayIndex) { + NanScope(); + info.GetReturnValue().Set(NanToArrayIndex(info[0]).ToLocalChecked()); +} + +NAN_METHOD(BooleanValue) { + info.GetReturnValue().Set(NanNew(NanTo(info[0]).FromJust())); +} + +NAN_METHOD(NumberValue) { + info.GetReturnValue().Set(NanNew(NanTo(info[0]).FromJust())); +} + +NAN_METHOD(IntegerValue) { + info.GetReturnValue().Set(NanNew(static_cast( + NanTo(info[0]).FromJust()))); +} + +NAN_METHOD(Uint32Value) { + info.GetReturnValue().Set(NanNew(NanTo(info[0]).FromJust())); +} + +NAN_METHOD(Int32Value) { + info.GetReturnValue().Set(NanNew(NanTo(info[0]).FromJust())); +} + +void Init (v8::Handle target) { + NanSet(target + , NanNew("toBoolean").ToLocalChecked() + , NanNew(ToBoolean)->GetFunction() + ); + NanSet(target + , NanNew("toNumber").ToLocalChecked() + , NanNew(ToNumber)->GetFunction() + ); + NanSet(target + , NanNew("toString").ToLocalChecked() + , NanNew(ToString)->GetFunction() + ); + NanSet(target + , NanNew("toDetailString").ToLocalChecked() + , NanNew(ToDetailString)->GetFunction() + ); + NanSet(target + , NanNew("toObject").ToLocalChecked() + , NanNew(ToObject)->GetFunction() + ); + NanSet(target + , NanNew("toInteger").ToLocalChecked() + , NanNew(ToInteger)->GetFunction() + ); + NanSet(target + , NanNew("toUint32").ToLocalChecked() + , NanNew(ToUint32)->GetFunction() + ); + NanSet(target + , NanNew("toInt32").ToLocalChecked() + , NanNew(ToInt32)->GetFunction() + ); + NanSet(target + , NanNew("toArrayIndex").ToLocalChecked() + , NanNew(ToArrayIndex)->GetFunction() + ); + NanSet(target + , NanNew("booleanValue").ToLocalChecked() + , NanNew(BooleanValue)->GetFunction() + ); + NanSet(target + , NanNew("numberValue").ToLocalChecked() + , NanNew(NumberValue)->GetFunction() + ); + NanSet(target + , NanNew("integerValue").ToLocalChecked() + , NanNew(IntegerValue)->GetFunction() + ); + NanSet(target + , NanNew("uint32Value").ToLocalChecked() + , NanNew(Uint32Value)->GetFunction() + ); + NanSet(target + , NanNew("int32Value").ToLocalChecked() + , NanNew(Int32Value)->GetFunction() + ); +} + +NODE_MODULE(converters, Init) diff --git a/test/cpp/error.cpp b/test/cpp/error.cpp index 608a04f1..57f43d3a 100644 --- a/test/cpp/error.cpp +++ b/test/cpp/error.cpp @@ -14,7 +14,7 @@ } \ \ NAN_METHOD(Throw ## NAME ## 2) { \ - return NanThrow ## NAME(NanNew("errmsg")); \ + return NanThrow ## NAME(NanNew("errmsg").ToLocalChecked()); \ } \ \ NAN_METHOD(Throw ## NAME ## 3) { \ @@ -22,7 +22,7 @@ } \ \ NAN_METHOD(Throw ## NAME ## 4) { \ - return NanThrowError(Nan ## NAME(NanNew("errmsg"))); \ + return NanThrowError(Nan ## NAME(NanNew("errmsg").ToLocalChecked())); \ } X(Error) @@ -40,7 +40,10 @@ X(TypeError) X(Throw ## NAME ## 4) #define X(NAME) \ - target->Set(NanNew(#NAME), NanNew(NAME)->GetFunction()); + NanSet( \ + target \ + , NanNew(#NAME).ToLocalChecked() \ + , NanNew(NAME)->GetFunction()); void Init (v8::Handle target) { diff --git a/test/cpp/gc.cpp b/test/cpp/gc.cpp index b788255a..ef89744c 100644 --- a/test/cpp/gc.cpp +++ b/test/cpp/gc.cpp @@ -32,12 +32,12 @@ NAN_METHOD(Check) { } void Init (v8::Handle target) { - target->Set( - NanNew("hook") + NanSet(target + , NanNew("hook").ToLocalChecked() , NanNew(Hook)->GetFunction() ); - target->Set( - NanNew("check") + NanSet(target + , NanNew("check").ToLocalChecked() , NanNew(Check)->GetFunction() ); } diff --git a/test/cpp/indexedinterceptors.cpp b/test/cpp/indexedinterceptors.cpp index 65d56aa7..729b1f14 100644 --- a/test/cpp/indexedinterceptors.cpp +++ b/test/cpp/indexedinterceptors.cpp @@ -35,7 +35,7 @@ void IndexedInterceptor::Init(v8::Handle target) { v8::Local tpl = NanNew(IndexedInterceptor::New); indexedinterceptors_constructor.Reset(tpl); - tpl->SetClassName(NanNew("IndexedInterceptor")); + tpl->SetClassName(NanNew("IndexedInterceptor").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); v8::Local inst = tpl->InstanceTemplate(); @@ -49,7 +49,7 @@ void IndexedInterceptor::Init(v8::Handle target) { v8::Local createnew = NanNew(CreateNew)->GetFunction(); - target->Set(NanNew("create"), createnew); + NanSet(target, NanNew("create").ToLocalChecked(), createnew); } v8::Handle IndexedInterceptor::NewInstance () { @@ -72,9 +72,9 @@ NAN_INDEX_GETTER(IndexedInterceptor::PropertyGetter) { IndexedInterceptor* interceptor = NanObjectWrap::Unwrap(info.This()); if (index == 0) { - info.GetReturnValue().Set(NanNew(interceptor->buf)); + info.GetReturnValue().Set(NanNew(interceptor->buf).ToLocalChecked()); } else { - info.GetReturnValue().Set(NanNew("bar")); + info.GetReturnValue().Set(NanNew("bar").ToLocalChecked()); } } @@ -94,7 +94,7 @@ NAN_INDEX_SETTER(IndexedInterceptor::PropertySetter) { NAN_INDEX_ENUMERATOR(IndexedInterceptor::PropertyEnumerator) { v8::Local arr = NanNew(); - arr->Set(0, NanNew("whee")); + NanSet(arr, 0, NanNew("whee").ToLocalChecked()); info.GetReturnValue().Set(arr); } diff --git a/test/cpp/isolatedata.cpp b/test/cpp/isolatedata.cpp index c47ce7d7..87607725 100644 --- a/test/cpp/isolatedata.cpp +++ b/test/cpp/isolatedata.cpp @@ -27,8 +27,8 @@ NAN_METHOD(SetAndGet) { } void Init (v8::Handle target) { - target->Set( - NanNew("setAndGet") + NanSet(target + , NanNew("setAndGet").ToLocalChecked() , NanNew(SetAndGet)->GetFunction() ); } diff --git a/test/cpp/makecallback.cpp b/test/cpp/makecallback.cpp index 2733b3e8..2aea0cfe 100644 --- a/test/cpp/makecallback.cpp +++ b/test/cpp/makecallback.cpp @@ -9,16 +9,16 @@ #include class MyObject : public node::ObjectWrap { -public: - static void Init(v8::Handle exports); + public: + static void Init(v8::Handle exports); -private: - MyObject(); - ~MyObject(); + private: + MyObject(); + ~MyObject(); - static NAN_METHOD(New); - static NAN_METHOD(CallEmit); - static NanPersistent constructor; + static NAN_METHOD(New); + static NAN_METHOD(CallEmit); + static NanPersistent constructor; }; NanPersistent MyObject::constructor; @@ -30,40 +30,40 @@ MyObject::~MyObject() { } void MyObject::Init(v8::Handle exports) { - // Prepare constructor template - v8::Local tpl = NanNew(New); - tpl->SetClassName(NanNew("MyObject")); - tpl->InstanceTemplate()->SetInternalFieldCount(1); + // Prepare constructor template + v8::Local tpl = NanNew(New); + tpl->SetClassName(NanNew("MyObject").ToLocalChecked()); + tpl->InstanceTemplate()->SetInternalFieldCount(1); - NanSetPrototypeMethod(tpl, "call_emit", CallEmit); + NanSetPrototypeMethod(tpl, "call_emit", CallEmit); - constructor.Reset(tpl->GetFunction()); - exports->Set(NanNew("MyObject"), tpl->GetFunction()); + constructor.Reset(tpl->GetFunction()); + NanSet(exports, NanNew("MyObject").ToLocalChecked(), tpl->GetFunction()); } NAN_METHOD(MyObject::New) { - if (info.IsConstructCall()) { - MyObject* obj = new MyObject(); - obj->Wrap(info.This()); - info.GetReturnValue().Set(info.This()); - } - else { - v8::Local cons = NanNew(constructor); - info.GetReturnValue().Set(cons->NewInstance()); - } + if (info.IsConstructCall()) { + MyObject* obj = new MyObject(); + obj->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + } else { + v8::Local cons = NanNew(constructor); + info.GetReturnValue().Set(cons->NewInstance()); + } } NAN_METHOD(MyObject::CallEmit) { - v8::Handle argv[1] = { - NanNew("event"), // event name - }; + NanScope(); + v8::Handle argv[1] = { + NanNew("event").ToLocalChecked(), // event name + }; - NanMakeCallback(info.This(), "emit", 1, argv); - info.GetReturnValue().SetUndefined(); + NanMakeCallback(info.This(), "emit", 1, argv); + info.GetReturnValue().SetUndefined(); } void Init(v8::Handle exports) { - MyObject::Init(exports); + MyObject::Init(exports); } NODE_MODULE(makecallback, Init) diff --git a/test/cpp/morenews.cpp b/test/cpp/morenews.cpp index a986f679..eef689a5 100644 --- a/test/cpp/morenews.cpp +++ b/test/cpp/morenews.cpp @@ -22,17 +22,17 @@ NAN_METHOD(NewPositiveInteger) { NAN_METHOD(NewUtf8String) { const char s[] = "strïng"; - info.GetReturnValue().Set(NanNew(s)); + info.GetReturnValue().Set(NanNew(s).ToLocalChecked()); } NAN_METHOD(NewLatin1String) { const uint8_t s[] = "str\xefng"; - info.GetReturnValue().Set(NanNew(s)); + info.GetReturnValue().Set(NanNew(s).ToLocalChecked()); } NAN_METHOD(NewUcs2String) { uint16_t s[] = {'s', 't', 'r', 0xef, 'n', 'g', '\0'}; - info.GetReturnValue().Set(NanNew(s)); + info.GetReturnValue().Set(NanNew(s).ToLocalChecked()); } static const uint16_t ws[] = {'s', 't', 'r', 0xef, 'n', 'g', '\0'}; @@ -54,46 +54,46 @@ class ExtAsciiString : public NanExternalOneByteStringResource { }; NAN_METHOD(NewExternalStringResource) { - v8::Local ext = NanNew(new ExtString()); + v8::Local ext = NanNew(new ExtString()).ToLocalChecked(); info.GetReturnValue().Set(ext); } NAN_METHOD(NewExternalAsciiStringResource) { - v8::Local ext = NanNew(new ExtAsciiString()); + v8::Local ext = NanNew(new ExtAsciiString()).ToLocalChecked(); info.GetReturnValue().Set(ext); } void Init(v8::Handle target) { - target->Set( - NanNew("newNumber") + NanSet(target + , NanNew("newNumber").ToLocalChecked() , NanNew(NewNumber)->GetFunction() ); - target->Set( - NanNew("newNegativeInteger") + NanSet(target + , NanNew("newNegativeInteger").ToLocalChecked() , NanNew(NewNegativeInteger)->GetFunction() ); - target->Set( - NanNew("newPositiveInteger") + NanSet(target + , NanNew("newPositiveInteger").ToLocalChecked() , NanNew(NewPositiveInteger)->GetFunction() ); - target->Set( - NanNew("newUtf8String") + NanSet(target + , NanNew("newUtf8String").ToLocalChecked() , NanNew(NewUtf8String)->GetFunction() ); - target->Set( - NanNew("newLatin1String") + NanSet(target + , NanNew("newLatin1String").ToLocalChecked() , NanNew(NewLatin1String)->GetFunction() ); - target->Set( - NanNew("newUcs2String") + NanSet(target + , NanNew("newUcs2String").ToLocalChecked() , NanNew(NewUcs2String)->GetFunction() ); - target->Set( - NanNew("newExternalStringResource") + NanSet(target + , NanNew("newExternalStringResource").ToLocalChecked() , NanNew(NewExternalStringResource)->GetFunction() ); - target->Set( - NanNew("newExternalAsciiStringResource") + NanSet(target + , NanNew("newExternalAsciiStringResource").ToLocalChecked() , NanNew(NewExternalAsciiStringResource) ->GetFunction() ); diff --git a/test/cpp/multifile1.cpp b/test/cpp/multifile1.cpp index a1ce38f1..748168a4 100644 --- a/test/cpp/multifile1.cpp +++ b/test/cpp/multifile1.cpp @@ -10,8 +10,8 @@ #include "./multifile2.h" void Init (v8::Handle target) { - target->Set( - NanNew("r") + NanSet(target + , NanNew("r").ToLocalChecked() , NanNew(ReturnString)->GetFunction() ); } diff --git a/test/cpp/multifile2.cpp b/test/cpp/multifile2.cpp index d6ea56f7..e3d7422a 100644 --- a/test/cpp/multifile2.cpp +++ b/test/cpp/multifile2.cpp @@ -9,6 +9,7 @@ #include NAN_METHOD(ReturnString) { - v8::Local s = NanNew(*v8::String::Utf8Value(info[0])); + v8::Local s = + NanNew(*v8::String::Utf8Value(info[0])).ToLocalChecked(); info.GetReturnValue().Set(s); } diff --git a/test/cpp/namedinterceptors.cpp b/test/cpp/namedinterceptors.cpp index 01bf5ef4..342309f5 100644 --- a/test/cpp/namedinterceptors.cpp +++ b/test/cpp/namedinterceptors.cpp @@ -35,7 +35,7 @@ void NamedInterceptor::Init(v8::Handle target) { v8::Local tpl = NanNew(NamedInterceptor::New); namedinterceptors_constructor.Reset(tpl); - tpl->SetClassName(NanNew("NamedInterceptor")); + tpl->SetClassName(NanNew("NamedInterceptor").ToLocalChecked()); tpl->InstanceTemplate()->SetInternalFieldCount(1); v8::Local inst = tpl->InstanceTemplate(); @@ -49,7 +49,7 @@ void NamedInterceptor::Init(v8::Handle target) { v8::Local createnew = NanNew(CreateNew)->GetFunction(); - target->Set(NanNew("create"), createnew); + NanSet(target, NanNew("create").ToLocalChecked(), createnew); } v8::Handle NamedInterceptor::NewInstance () { @@ -72,9 +72,9 @@ NAN_PROPERTY_GETTER(NamedInterceptor::PropertyGetter) { NamedInterceptor* interceptor = NanObjectWrap::Unwrap(info.This()); if (!std::strcmp(*v8::String::Utf8Value(property), "prop")) { - info.GetReturnValue().Set(NanNew(interceptor->buf)); + info.GetReturnValue().Set(NanNew(interceptor->buf).ToLocalChecked()); } else { - info.GetReturnValue().Set(NanNew("bar")); + info.GetReturnValue().Set(NanNew("bar").ToLocalChecked()); } } @@ -94,7 +94,7 @@ NAN_PROPERTY_SETTER(NamedInterceptor::PropertySetter) { NAN_PROPERTY_ENUMERATOR(NamedInterceptor::PropertyEnumerator) { v8::Local arr = NanNew(); - arr->Set(0, NanNew("value")); + NanSet(arr, 0, NanNew("value").ToLocalChecked()); info.GetReturnValue().Set(arr); } diff --git a/test/cpp/nancallback.cpp b/test/cpp/nancallback.cpp index 68c4c5c8..7e744dd6 100644 --- a/test/cpp/nancallback.cpp +++ b/test/cpp/nancallback.cpp @@ -28,16 +28,16 @@ NAN_METHOD(CompareCallbacks) { } void Init (v8::Handle target) { - target->Set( - NanNew("globalContext") + NanSet(target + , NanNew("globalContext").ToLocalChecked() , NanNew(GlobalContext)->GetFunction() ); - target->Set( - NanNew("specificContext") + NanSet(target + , NanNew("specificContext").ToLocalChecked() , NanNew(SpecificContext)->GetFunction() ); - target->Set( - NanNew("compareCallbacks") + NanSet(target + , NanNew("compareCallbacks").ToLocalChecked() , NanNew(CompareCallbacks)->GetFunction() ); } diff --git a/test/cpp/nannew.cpp b/test/cpp/nannew.cpp index e1d45484..dc6f0557 100644 --- a/test/cpp/nannew.cpp +++ b/test/cpp/nannew.cpp @@ -121,7 +121,8 @@ NAN_METHOD(testDate) { t.plan(1); - t.ok(_( assertType( NanNew(static_cast(time(NULL)))))); + t.ok(_( assertType( + NanNew(static_cast(time(NULL))).ToLocalChecked()))); info.GetReturnValue().SetUndefined(); } @@ -144,7 +145,7 @@ NAN_METHOD(testFunction) { t.plan(2); t.ok(_( assertType(NanNew(testFunction)))); - v8::Local data = NanNew("plonk"); + v8::Local data = NanNew("plonk").ToLocalChecked(); t.ok(_( assertType(NanNew(testFunction, data)))); info.GetReturnValue().SetUndefined(); @@ -158,7 +159,7 @@ NAN_METHOD(testFunctionTemplate) { t.ok(_( assertType( NanNew()))); t.ok(_( assertType( NanNew(testFunctionTemplate)))); - v8::Local data = NanNew("plonk"); + v8::Local data = NanNew("plonk").ToLocalChecked(); t.ok(_( assertType( NanNew( testFunctionTemplate, data)))); v8::Local signature = NanNew(); @@ -210,7 +211,10 @@ NAN_METHOD(testNumberObject) { t.plan(2); t.ok(_( assertType( NanNew(M_PI)))); - t.ok(_( fabs(NanNew(M_PI)->NumberValue() - M_PI) < epsilon)); + t.ok(_( + fabs( + NanTo(NanNew(M_PI)).FromJust() - M_PI + ) < epsilon)); info.GetReturnValue().SetUndefined(); } @@ -240,20 +244,26 @@ NAN_METHOD(testScript) { t.plan(6); - ScriptOrigin origin(NanNew("foo"), NanNew(5)); + ScriptOrigin origin(NanNew("foo").ToLocalChecked(), NanNew(5)); - t.ok(_( assertType