async_wrap: add parent uid to init hook
When the parent uid is required it is not necessary to store the uid in the parent handle object. PR-URL: https://github.com/nodejs/node/pull/4600 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
parent
c6c7d8b325
commit
11c672bc77
@ -42,11 +42,14 @@ inline AsyncWrap::AsyncWrap(Environment* env,
|
|||||||
v8::Local<v8::Value> argv[] = {
|
v8::Local<v8::Value> argv[] = {
|
||||||
v8::Integer::New(env->isolate(), get_uid()),
|
v8::Integer::New(env->isolate(), get_uid()),
|
||||||
v8::Int32::New(env->isolate(), provider),
|
v8::Int32::New(env->isolate(), provider),
|
||||||
|
Null(env->isolate()),
|
||||||
Null(env->isolate())
|
Null(env->isolate())
|
||||||
};
|
};
|
||||||
|
|
||||||
if (parent != nullptr)
|
if (parent != nullptr) {
|
||||||
argv[2] = parent->object();
|
argv[2] = v8::Integer::New(env->isolate(), parent->get_uid());
|
||||||
|
argv[3] = parent->object();
|
||||||
|
}
|
||||||
|
|
||||||
v8::MaybeLocal<v8::Value> ret =
|
v8::MaybeLocal<v8::Value> ret =
|
||||||
init_fn->Call(env->context(), object, ARRAY_SIZE(argv), argv);
|
init_fn->Call(env->context(), object, ARRAY_SIZE(argv), argv);
|
||||||
|
@ -6,17 +6,24 @@ const net = require('net');
|
|||||||
const async_wrap = process.binding('async_wrap');
|
const async_wrap = process.binding('async_wrap');
|
||||||
const providers = Object.keys(async_wrap.Providers);
|
const providers = Object.keys(async_wrap.Providers);
|
||||||
|
|
||||||
|
const uidSymbol = Symbol('uid');
|
||||||
|
|
||||||
let cntr = 0;
|
let cntr = 0;
|
||||||
let server;
|
let server;
|
||||||
let client;
|
let client;
|
||||||
|
|
||||||
function init(id, type, parent) {
|
function init(uid, type, parentUid, parentHandle) {
|
||||||
if (parent) {
|
this[uidSymbol] = uid;
|
||||||
|
|
||||||
|
if (parentHandle) {
|
||||||
cntr++;
|
cntr++;
|
||||||
// Cannot assert in init callback or will abort.
|
// Cannot assert in init callback or will abort.
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
assert.equal(providers[type], 'TCPWRAP');
|
assert.equal(providers[type], 'TCPWRAP');
|
||||||
assert.equal(parent, server._handle, 'server doesn\'t match parent');
|
assert.equal(parentUid, server._handle[uidSymbol],
|
||||||
|
'server uid doesn\'t match parent uid');
|
||||||
|
assert.equal(parentHandle, server._handle,
|
||||||
|
'server handle doesn\'t match parent handle');
|
||||||
assert.equal(this, client._handle, 'client doesn\'t match context');
|
assert.equal(this, client._handle, 'client doesn\'t match context');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,26 @@ const common = require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const async_wrap = process.binding('async_wrap');
|
const async_wrap = process.binding('async_wrap');
|
||||||
|
const providers = Object.keys(async_wrap.Providers);
|
||||||
|
|
||||||
|
const uidSymbol = Symbol('uid');
|
||||||
|
|
||||||
let cntr = 0;
|
let cntr = 0;
|
||||||
let server;
|
let server;
|
||||||
let client;
|
let client;
|
||||||
|
|
||||||
function init(id, type, parent) {
|
function init(uid, type, parentUid, parentHandle) {
|
||||||
if (parent) {
|
this[uidSymbol] = uid;
|
||||||
|
|
||||||
|
if (parentHandle) {
|
||||||
cntr++;
|
cntr++;
|
||||||
// Cannot assert in init callback or will abort.
|
// Cannot assert in init callback or will abort.
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
assert.equal(parent, server._handle, 'server doesn\'t match parent');
|
assert.equal(providers[type], 'TCPWRAP');
|
||||||
|
assert.equal(parentUid, server._handle[uidSymbol],
|
||||||
|
'server uid doesn\'t match parent uid');
|
||||||
|
assert.equal(parentHandle, server._handle,
|
||||||
|
'server handle doesn\'t match parent handle');
|
||||||
assert.equal(this, client._handle, 'client doesn\'t match context');
|
assert.equal(this, client._handle, 'client doesn\'t match context');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user