test: extend async addon test · nodejs/node@ad1d745
@@ -28,6 +28,7 @@ void DoAsync(uv_work_t* r) {
2828 req->output = req->input * 2;
2929}
303031+template <bool use_makecallback>
3132void AfterAsync(uv_work_t* r) {
3233 async_req* req = reinterpret_cast<async_req*>(r->data);
3334 v8::Isolate* isolate = req->isolate;
@@ -40,9 +41,18 @@ void AfterAsync(uv_work_t* r) {
40414142 v8::TryCatch try_catch(isolate);
424344+ v8::Local<v8::Object> global = isolate->GetCurrentContext()->Global();
4345 v8::Local<v8::Function> callback =
4446 v8::Local<v8::Function>::New(isolate, req->callback);
45- callback->Call(isolate->GetCurrentContext()->Global(), 2, argv);
47+48+if (use_makecallback) {
49+ v8::Local<v8::Value> ret =
50+node::MakeCallback(isolate, global, callback, 2, argv);
51+// This should be changed to an empty handle.
52+assert(!ret.IsEmpty());
53+ } else {
54+ callback->Call(global, 2, argv);
55+ }
46564757// cleanup
4858 req->callback.Reset();
@@ -53,6 +63,7 @@ void AfterAsync(uv_work_t* r) {
5363 }
5464}
556566+template <bool use_makecallback>
5667void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
5768 v8::Isolate* isolate = args.GetIsolate();
5869@@ -69,11 +80,12 @@ void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
6980uv_queue_work(uv_default_loop(),
7081&req->req,
7182 DoAsync,
72- (uv_after_work_cb)AfterAsync);
83+ (uv_after_work_cb)AfterAsync<use_makecallback>);
7384}
74857586void init(v8::Local<v8::Object> exports, v8::Local<v8::Object> module) {
76-NODE_SET_METHOD(module, "exports", Method);
87+NODE_SET_METHOD(exports, "runCall", Method<false>);
88+NODE_SET_METHOD(exports, "runMakeCallback", Method<true>);
7789}
78907991NODE_MODULE(binding, init)