mirror of https://github.com/nodejs/node.git
test: extend async addon test
Test more current behaviour, based on discussions in https://github.com/nodejs/node/pull/14697. PR-URL: https://github.com/nodejs/node/pull/14922 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>pull/14579/merge
parent
7ce2555896
commit
7e544240d3
|
@ -28,6 +28,7 @@ void DoAsync(uv_work_t* r) {
|
|||
req->output = req->input * 2;
|
||||
}
|
||||
|
||||
template <bool use_makecallback>
|
||||
void AfterAsync(uv_work_t* r) {
|
||||
async_req* req = reinterpret_cast<async_req*>(r->data);
|
||||
v8::Isolate* isolate = req->isolate;
|
||||
|
@ -40,9 +41,18 @@ void AfterAsync(uv_work_t* r) {
|
|||
|
||||
v8::TryCatch try_catch(isolate);
|
||||
|
||||
v8::Local<v8::Object> global = isolate->GetCurrentContext()->Global();
|
||||
v8::Local<v8::Function> callback =
|
||||
v8::Local<v8::Function>::New(isolate, req->callback);
|
||||
callback->Call(isolate->GetCurrentContext()->Global(), 2, argv);
|
||||
|
||||
if (use_makecallback) {
|
||||
v8::Local<v8::Value> 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 <bool use_makecallback>
|
||||
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
|
||||
|
@ -69,11 +80,12 @@ void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
uv_queue_work(uv_default_loop(),
|
||||
&req->req,
|
||||
DoAsync,
|
||||
(uv_after_work_cb)AfterAsync);
|
||||
(uv_after_work_cb)AfterAsync<use_makecallback>);
|
||||
}
|
||||
|
||||
void init(v8::Local<v8::Object> exports, v8::Local<v8::Object> module) {
|
||||
NODE_SET_METHOD(module, "exports", Method);
|
||||
NODE_SET_METHOD(exports, "runCall", Method<false>);
|
||||
NODE_SET_METHOD(exports, "runMakeCallback", Method<true>);
|
||||
}
|
||||
|
||||
NODE_MODULE(binding, init)
|
||||
|
|
|
@ -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');
|
||||
}));
|
|
@ -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());
|
||||
}));
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue