From 51a71c88c5c14ea24f82db442d5f9d4103ea06c9 Mon Sep 17 00:00:00 2001
From: Ali Ijaz Sheikh <ofrobots@google.com>
Date: Thu, 15 Feb 2018 18:39:49 -0800
Subject: [PATCH] test: fix warnings in addon tests

The legacy MakeCallback deprecation was resulting in compile time
warnings in adddon tests. Fix them.

Ref: https://github.com/nodejs/node/pull/18632
---
 test/addons/async-hello-world/binding.cc     | 6 +++++-
 test/addons/callback-scope/binding.cc        | 3 ++-
 test/addons/make-callback-recurse/binding.cc | 3 ++-
 test/addons/make-callback/binding.cc         | 6 ++++--
 test/addons/repl-domain-abort/binding.cc     | 9 ++++-----
 5 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/test/addons/async-hello-world/binding.cc b/test/addons/async-hello-world/binding.cc
index 5b3a800709f7d7..d4b74ed831f512 100644
--- a/test/addons/async-hello-world/binding.cc
+++ b/test/addons/async-hello-world/binding.cc
@@ -15,6 +15,7 @@ struct async_req {
   int output;
   v8::Isolate* isolate;
   v8::Persistent<v8::Function> callback;
+  node::async_context context;
 };
 
 void DoAsync(uv_work_t* r) {
@@ -47,7 +48,8 @@ void AfterAsync(uv_work_t* r) {
 
   if (use_makecallback) {
     v8::Local<v8::Value> ret =
-        node::MakeCallback(isolate, global, callback, 2, argv);
+        node::MakeCallback(isolate, global, callback, 2, argv, req->context)
+            .ToLocalChecked();
     // This should be changed to an empty handle.
     assert(!ret.IsEmpty());
   } else {
@@ -55,6 +57,7 @@ void AfterAsync(uv_work_t* r) {
   }
 
   // cleanup
+  node::EmitAsyncDestroy(isolate, req->context);
   req->callback.Reset();
   delete req;
 
@@ -73,6 +76,7 @@ void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
   req->input = args[0]->IntegerValue();
   req->output = 0;
   req->isolate = isolate;
+  req->context = node::EmitAsyncInit(isolate, v8::Object::New(isolate), "test");
 
   v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(args[1]);
   req->callback.Reset(isolate, callback);
diff --git a/test/addons/callback-scope/binding.cc b/test/addons/callback-scope/binding.cc
index 52ffe8e91f6dce..3b69d2d5725a8f 100644
--- a/test/addons/callback-scope/binding.cc
+++ b/test/addons/callback-scope/binding.cc
@@ -36,7 +36,8 @@ static v8::Persistent<v8::Promise::Resolver> persistent;
 static void Callback(uv_work_t* req, int ignored) {
   v8::Isolate* isolate = v8::Isolate::GetCurrent();
   v8::HandleScope scope(isolate);
-  node::CallbackScope callback_scope(isolate, v8::Object::New(isolate), {0, 0});
+  node::CallbackScope callback_scope(isolate, v8::Object::New(isolate),
+                                     node::async_context{0, 0});
 
   v8::Local<v8::Promise::Resolver> local =
       v8::Local<v8::Promise::Resolver>::New(isolate, persistent);
diff --git a/test/addons/make-callback-recurse/binding.cc b/test/addons/make-callback-recurse/binding.cc
index d1f9070f8a2a79..3fe3212ee3c8f5 100644
--- a/test/addons/make-callback-recurse/binding.cc
+++ b/test/addons/make-callback-recurse/binding.cc
@@ -19,7 +19,8 @@ void MakeCallback(const FunctionCallbackInfo<Value>& args) {
   Local<Object> recv = args[0].As<Object>();
   Local<Function> method = args[1].As<Function>();
 
-  node::MakeCallback(isolate, recv, method, 0, nullptr);
+  node::MakeCallback(isolate, recv, method, 0, nullptr,
+                     node::async_context{0, 0});
 }
 
 void Initialize(Local<Object> exports) {
diff --git a/test/addons/make-callback/binding.cc b/test/addons/make-callback/binding.cc
index 13daf21cff07ae..86ed203b98d8d9 100644
--- a/test/addons/make-callback/binding.cc
+++ b/test/addons/make-callback/binding.cc
@@ -19,11 +19,13 @@ void MakeCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
   if (args[1]->IsFunction()) {
     auto method = args[1].As<v8::Function>();
     result =
-        node::MakeCallback(isolate, recv, method, argv.size(), argv.data());
+        node::MakeCallback(isolate, recv, method, argv.size(), argv.data(),
+                           node::async_context{0, 0}).ToLocalChecked();
   } else if (args[1]->IsString()) {
     auto method = args[1].As<v8::String>();
     result =
-        node::MakeCallback(isolate, recv, method, argv.size(), argv.data());
+        node::MakeCallback(isolate, recv, method, argv.size(), argv.data(),
+                           node::async_context{0, 0}).ToLocalChecked();
   } else {
     assert(0 && "unreachable");
   }
diff --git a/test/addons/repl-domain-abort/binding.cc b/test/addons/repl-domain-abort/binding.cc
index d2f7560048fd46..3e716443540229 100644
--- a/test/addons/repl-domain-abort/binding.cc
+++ b/test/addons/repl-domain-abort/binding.cc
@@ -36,11 +36,10 @@ void Method(const FunctionCallbackInfo<Value>& args) {
     Boolean::New(isolate, true),
     Boolean::New(isolate, false)
   };
-  Local<Value> ret = node::MakeCallback(isolate,
-                                        isolate->GetCurrentContext()->Global(),
-                                        args[0].As<Function>(),
-                                        2,
-                                        params);
+  Local<Value> ret =
+      node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(),
+                         args[0].As<Function>(), 2, params,
+                         node::async_context{0, 0}).ToLocalChecked();
   assert(ret->IsTrue());
 }