Browse Source

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.

Ref: https://github.com/nodejs/node/pull/7048
PR-URL: #4600
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
v4.x
Andreas Madsen 9 years ago
committed by Myles Borins
parent
commit
75ecf8eb07
  1. 7
      src/async-wrap-inl.h
  2. 13
      test/parallel/test-async-wrap-disabled-propagate-parent.js
  3. 15
      test/parallel/test-async-wrap-propagate-parent.js

7
src/async-wrap-inl.h

@ -42,11 +42,14 @@ inline AsyncWrap::AsyncWrap(Environment* env,
v8::Local<v8::Value> argv[] = {
v8::Integer::New(env->isolate(), get_uid()),
v8::Int32::New(env->isolate(), provider),
Null(env->isolate()),
Null(env->isolate())
};
if (parent != nullptr)
argv[2] = parent->object();
if (parent != nullptr) {
argv[2] = v8::Integer::New(env->isolate(), parent->get_uid());
argv[3] = parent->object();
}
v8::MaybeLocal<v8::Value> ret =
init_fn->Call(env->context(), object, arraysize(argv), argv);

13
test/parallel/test-async-wrap-disabled-propagate-parent.js

@ -6,16 +6,23 @@ const net = require('net');
const async_wrap = process.binding('async_wrap');
const providers = Object.keys(async_wrap.Providers);
const uidSymbol = Symbol('uid');
let cntr = 0;
let client;
function init(id, type, parent) {
if (parent) {
function init(uid, type, parentUid, parentHandle) {
this[uidSymbol] = uid;
if (parentHandle) {
cntr++;
// Cannot assert in init callback or will abort.
process.nextTick(() => {
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');
});
}

15
test/parallel/test-async-wrap-propagate-parent.js

@ -4,16 +4,25 @@ const common = require('../common');
const assert = require('assert');
const net = require('net');
const async_wrap = process.binding('async_wrap');
const providers = Object.keys(async_wrap.Providers);
const uidSymbol = Symbol('uid');
let cntr = 0;
let client;
function init(id, type, parent) {
if (parent) {
function init(uid, type, parentUid, parentHandle) {
this[uidSymbol] = uid;
if (parentHandle) {
cntr++;
// Cannot assert in init callback or will abort.
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');
});
}

Loading…
Cancel
Save