From 13092b30f6f745238b363526c0d6ffd93c73ef55 Mon Sep 17 00:00:00 2001 From: Benjamin Byholm Date: Sat, 10 Oct 2015 19:57:09 +0300 Subject: [PATCH] New should return MaybeLocal --- nan_implementation_12_inl.h | 7 +++++++ nan_implementation_pre_12_inl.h | 4 ++-- nan_new.h | 2 +- test/cpp/nannew.cpp | 6 +++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/nan_implementation_12_inl.h b/nan_implementation_12_inl.h index a140f856..0cad0029 100644 --- a/nan_implementation_12_inl.h +++ b/nan_implementation_12_inl.h @@ -99,9 +99,16 @@ Factory::New( FunctionCallback callback obj->SetInternalField(imp::kDataIndex, val); } +#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ + (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) return scope.Escape(v8::Function::New( isolate , imp::FunctionCallbackWrapper , obj)); +#else + return Factory::return_t(scope.Escape(v8::Function::New( isolate + , imp::FunctionCallbackWrapper + , obj))); +#endif } //=== Function Template ======================================================== diff --git a/nan_implementation_pre_12_inl.h b/nan_implementation_pre_12_inl.h index 15a815cd..013deacf 100644 --- a/nan_implementation_pre_12_inl.h +++ b/nan_implementation_pre_12_inl.h @@ -72,10 +72,10 @@ Factory::New(void * value) { Factory::return_t Factory::New( FunctionCallback callback , v8::Local data) { - return Factory::New( callback + return Factory::return_t(Factory::New( callback , data , v8::Local() - )->GetFunction(); + )->GetFunction()); } diff --git a/nan_new.h b/nan_new.h index c6c4236a..f45ec74b 100644 --- a/nan_new.h +++ b/nan_new.h @@ -81,7 +81,7 @@ struct Factory : FactoryBase { }; template <> -struct Factory : FactoryBase { +struct Factory : MaybeFactoryBase { static inline return_t New( FunctionCallback callback diff --git a/test/cpp/nannew.cpp b/test/cpp/nannew.cpp index 3934588f..29d32c73 100644 --- a/test/cpp/nannew.cpp +++ b/test/cpp/nannew.cpp @@ -146,9 +146,9 @@ NAN_METHOD(testFunction) { Tap t(info[0]); t.plan(2); - t.ok(_( assertType(New(testFunction)))); + t.ok(_( assertType(New(testFunction).ToLocalChecked()))); v8::Local data = New("plonk").ToLocalChecked(); - t.ok(_( assertType(New(testFunction, data)))); + t.ok(_( assertType(New(testFunction, data).ToLocalChecked()))); info.GetReturnValue().SetUndefined(); } @@ -416,7 +416,7 @@ NAN_METHOD(testRegression242) { // These lines must *compile*. Not much to test at runtime. Local ft = New(overloaded); (void)ft; // not unused - Local f = New(overloaded); + Local f = New(overloaded).ToLocalChecked(); (void)f; // not unused t.plan(1);