diff --git a/test/array_buffer.cc b/test/array_buffer.cc index 58edd2e86..2b07bd250 100644 --- a/test/array_buffer.cc +++ b/test/array_buffer.cc @@ -63,7 +63,7 @@ Value CreateExternalBufferWithFinalize(const CallbackInfo& info) { uint8_t* data = new uint8_t[testLength]; ArrayBuffer buffer = ArrayBuffer::New( - info.Env(), data, testLength, [](NogcEnv /*env*/, void* finalizeData) { + info.Env(), data, testLength, [](Env /*env*/, void* finalizeData) { delete[] static_cast(finalizeData); finalizeCount++; }); @@ -94,7 +94,7 @@ Value CreateExternalBufferWithFinalizeHint(const CallbackInfo& info) { info.Env(), data, testLength, - [](NogcEnv /*env*/, void* finalizeData, char* /*finalizeHint*/) { + [](Env /*env*/, void* finalizeData, char* /*finalizeHint*/) { delete[] static_cast(finalizeData); finalizeCount++; }, diff --git a/test/buffer.cc b/test/buffer.cc index 405fcdec0..c10300dc7 100644 --- a/test/buffer.cc +++ b/test/buffer.cc @@ -51,14 +51,11 @@ Value CreateExternalBufferWithFinalize(const CallbackInfo& info) { uint16_t* data = new uint16_t[testLength]; - Buffer buffer = - Buffer::New(info.Env(), - data, - testLength, - [](NogcEnv /*env*/, uint16_t* finalizeData) { - delete[] finalizeData; - finalizeCount++; - }); + Buffer buffer = Buffer::New( + info.Env(), data, testLength, [](Env /*env*/, uint16_t* finalizeData) { + delete[] finalizeData; + finalizeCount++; + }); if (buffer.Length() != testLength) { Error::New(info.Env(), "Incorrect buffer length.") @@ -86,7 +83,7 @@ Value CreateExternalBufferWithFinalizeHint(const CallbackInfo& info) { info.Env(), data, testLength, - [](NogcEnv /*env*/, uint16_t* finalizeData, char* /*finalizeHint*/) { + [](Env /*env*/, uint16_t* finalizeData, char* /*finalizeHint*/) { delete[] finalizeData; finalizeCount++; }, diff --git a/test/buffer_new_or_copy-inl.h b/test/buffer_new_or_copy-inl.h index 60e7a112e..4d68fbc91 100644 --- a/test/buffer_new_or_copy-inl.h +++ b/test/buffer_new_or_copy-inl.h @@ -24,14 +24,11 @@ Value CreateOrCopyExternalBufferWithFinalize(const CallbackInfo& info) { uint16_t* data = new uint16_t[testLength]; InitData(data, testLength); - Buffer buffer = - Buffer::NewOrCopy(info.Env(), - data, - testLength, - [](NogcEnv /*env*/, uint16_t* finalizeData) { - delete[] finalizeData; - finalizeCount++; - }); + Buffer buffer = Buffer::NewOrCopy( + info.Env(), data, testLength, [](Env /*env*/, uint16_t* finalizeData) { + delete[] finalizeData; + finalizeCount++; + }); if (buffer.Length() != testLength) { Error::New(info.Env(), "Incorrect buffer length.") @@ -54,7 +51,7 @@ Value CreateOrCopyExternalBufferWithFinalizeHint(const CallbackInfo& info) { info.Env(), data, testLength, - [](NogcEnv /*env*/, uint16_t* finalizeData, char* /*finalizeHint*/) { + [](Env /*env*/, uint16_t* finalizeData, char* /*finalizeHint*/) { delete[] finalizeData; finalizeCount++; }, diff --git a/test/external.cc b/test/external.cc index a67469e86..255b17f19 100644 --- a/test/external.cc +++ b/test/external.cc @@ -14,11 +14,10 @@ Value CreateExternal(const CallbackInfo& info) { Value CreateExternalWithFinalize(const CallbackInfo& info) { finalizeCount = 0; - return External::New( - info.Env(), new int(1), [](NogcEnv /*env*/, int* data) { - delete data; - finalizeCount++; - }); + return External::New(info.Env(), new int(1), [](Env /*env*/, int* data) { + delete data; + finalizeCount++; + }); } Value CreateExternalWithFinalizeHint(const CallbackInfo& info) { @@ -27,7 +26,7 @@ Value CreateExternalWithFinalizeHint(const CallbackInfo& info) { return External::New( info.Env(), new int(1), - [](NogcEnv /*env*/, int* data, char* /*hint*/) { + [](Env /*env*/, int* data, char* /*hint*/) { delete data; finalizeCount++; }, @@ -56,21 +55,6 @@ Value GetFinalizeCount(const CallbackInfo& info) { } Value CreateExternalWithFinalizeException(const CallbackInfo& info) { -#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER - auto o = External::New( - info.Env(), new int(1), [](NogcEnv /*env*/, int* data) { delete data; }); - - info.Env().AddPostFinalizer([](Env env) { - Error error = Error::New(env, "Finalizer exception"); -#ifdef NAPI_CPP_EXCEPTIONS - throw error; -#else - error.ThrowAsJavaScriptException(); -#endif - }); - - return o; -#else return External::New(info.Env(), new int(1), [](Env env, int* data) { Error error = Error::New(env, "Finalizer exception"); delete data; @@ -80,8 +64,8 @@ Value CreateExternalWithFinalizeException(const CallbackInfo& info) { error.ThrowAsJavaScriptException(); #endif }); -#endif } + } // end anonymous namespace Object InitExternal(Env env) { diff --git a/test/movable_callbacks.cc b/test/movable_callbacks.cc index 20edbb8d8..9959d4d38 100644 --- a/test/movable_callbacks.cc +++ b/test/movable_callbacks.cc @@ -4,21 +4,13 @@ using namespace Napi; Value createExternal(const CallbackInfo& info) { FunctionReference ref = Reference::New(info[0].As(), 1); - -#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER - auto env = info.Env(); - auto ret = External::New(env, nullptr); - - env.AddPostFinalizer( - [ref = std::move(ref)](Napi::Env /*env*/) { ref.Call({}); }); -#else auto ret = External::New( info.Env(), nullptr, [ref = std::move(ref)](Napi::Env /*env*/, char* /*data*/) { ref.Call({}); }); -#endif + return ret; } diff --git a/test/object/finalizer.cc b/test/object/finalizer.cc index 89e3e2af6..6122e5eb9 100644 --- a/test/object/finalizer.cc +++ b/test/object/finalizer.cc @@ -7,11 +7,7 @@ static int dummy; Value AddFinalizer(const CallbackInfo& info) { ObjectReference* ref = new ObjectReference; *ref = Persistent(Object::New(info.Env())); -#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER - info.Env().AddPostFinalizer( -#else info[0].As().AddFinalizer( -#endif [](Napi::Env /*env*/, ObjectReference* ref) { ref->Set("finalizerCalled", true); delete ref; @@ -23,11 +19,7 @@ Value AddFinalizer(const CallbackInfo& info) { Value AddFinalizerWithHint(const CallbackInfo& info) { ObjectReference* ref = new ObjectReference; *ref = Persistent(Object::New(info.Env())); -#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER - info.Env().AddPostFinalizer( -#else info[0].As().AddFinalizer( -#endif [](Napi::Env /*env*/, ObjectReference* ref, int* dummy_p) { ref->Set("finalizerCalledWithCorrectHint", dummy_p == &dummy); delete ref; diff --git a/test/objectwrap.cc b/test/objectwrap.cc index 9f01e089a..1ee0c9ad7 100644 --- a/test/objectwrap.cc +++ b/test/objectwrap.cc @@ -30,22 +30,7 @@ class Test : public Napi::ObjectWrap { public: Test(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { if (info.Length() > 0) { -#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER - info.Env().AddPostFinalizer( - [](Napi::Env env, Napi::FunctionReference* finalizeCb) { - if (finalizeCb->IsEmpty()) { - return; - } - - finalizeCb->Call(env.Global(), {Napi::Boolean::New(env, true)}); - finalizeCb->Unref(); - delete finalizeCb; - }, - new Napi::FunctionReference( - Napi::Persistent(info[0].As()))); -#else finalizeCb_ = Napi::Persistent(info[0].As()); -#endif } // Create an own instance property. info.This().As().DefineProperty( @@ -65,7 +50,7 @@ class Test : public Napi::ObjectWrap { Env(), static_cast(malloc(1)), 1, - [](Napi::NogcEnv, uint8_t* bufaddr) { free(bufaddr); })); + [](Napi::Env, uint8_t* bufaddr) { free(bufaddr); })); } static Napi::Value OwnPropertyGetter(const Napi::CallbackInfo& info) { @@ -280,12 +265,7 @@ class Test : public Napi::ObjectWrap { })); } -#ifdef NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER - void Finalize(NODE_ADDON_API_NOGC_ENV_CLASS /*env*/) override { - // Intentionally blank to ensure `override` works correctly. - } -#else - void Finalize(NODE_ADDON_API_NOGC_ENV_CLASS env) override { + void Finalize(Napi::Env env) { if (finalizeCb_.IsEmpty()) { return; } @@ -293,7 +273,6 @@ class Test : public Napi::ObjectWrap { finalizeCb_.Call(env.Global(), {Napi::Boolean::New(env, true)}); finalizeCb_.Unref(); } -#endif private: std::string value_;