diff --git a/test/addons/async-hello-world/binding.cc b/test/addons/async-hello-world/binding.cc index da2bd417cd9a6f..42291c49011fb3 100644 --- a/test/addons/async-hello-world/binding.cc +++ b/test/addons/async-hello-world/binding.cc @@ -28,6 +28,7 @@ void DoAsync(uv_work_t* r) { req->output = req->input * 2; } +template void AfterAsync(uv_work_t* r) { async_req* req = reinterpret_cast(r->data); v8::Isolate* isolate = req->isolate; @@ -40,9 +41,18 @@ void AfterAsync(uv_work_t* r) { v8::TryCatch try_catch(isolate); + v8::Local global = isolate->GetCurrentContext()->Global(); v8::Local callback = v8::Local::New(isolate, req->callback); - callback->Call(isolate->GetCurrentContext()->Global(), 2, argv); + + if (use_makecallback) { + v8::Local ret = + node::MakeCallback(isolate, global, callback, 2, argv); + // This should be changed to an empty handle. + assert(!ret.IsEmpty()); + } else { + callback->Call(global, 2, argv); + } // cleanup req->callback.Reset(); @@ -53,6 +63,7 @@ void AfterAsync(uv_work_t* r) { } } +template void Method(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); @@ -69,11 +80,12 @@ void Method(const v8::FunctionCallbackInfo& args) { uv_queue_work(uv_default_loop(), &req->req, DoAsync, - (uv_after_work_cb)AfterAsync); + (uv_after_work_cb)AfterAsync); } void init(v8::Local exports, v8::Local module) { - NODE_SET_METHOD(module, "exports", Method); + NODE_SET_METHOD(exports, "runCall", Method); + NODE_SET_METHOD(exports, "runMakeCallback", Method); } NODE_MODULE(binding, init) diff --git a/test/addons/async-hello-world/test-makecallback-uncaught.js b/test/addons/async-hello-world/test-makecallback-uncaught.js new file mode 100644 index 00000000000000..c207f535bee6eb --- /dev/null +++ b/test/addons/async-hello-world/test-makecallback-uncaught.js @@ -0,0 +1,9 @@ +'use strict'; +const common = require('../../common'); +const { runMakeCallback } = require(`./build/${common.buildType}/binding`); + +process.on('uncaughtException', common.mustCall()); + +runMakeCallback(5, common.mustCall(() => { + throw new Error('foo'); +})); diff --git a/test/addons/async-hello-world/test-makecallback.js b/test/addons/async-hello-world/test-makecallback.js new file mode 100644 index 00000000000000..0edf052e8c34fc --- /dev/null +++ b/test/addons/async-hello-world/test-makecallback.js @@ -0,0 +1,10 @@ +'use strict'; +const common = require('../../common'); +const assert = require('assert'); +const { runMakeCallback } = require(`./build/${common.buildType}/binding`); + +runMakeCallback(5, common.mustCall(function(err, val) { + assert.strictEqual(err, null); + assert.strictEqual(val, 10); + process.nextTick(common.mustCall()); +})); diff --git a/test/addons/async-hello-world/test.js b/test/addons/async-hello-world/test.js index fbd0d7eeb7ef13..f24071087c0629 100644 --- a/test/addons/async-hello-world/test.js +++ b/test/addons/async-hello-world/test.js @@ -1,9 +1,9 @@ 'use strict'; const common = require('../../common'); const assert = require('assert'); -const binding = require(`./build/${common.buildType}/binding`); +const { runCall } = require(`./build/${common.buildType}/binding`); -binding(5, common.mustCall(function(err, val) { +runCall(5, common.mustCall(function(err, val) { assert.strictEqual(err, null); assert.strictEqual(val, 10); process.nextTick(common.mustCall());