From 3a96fa00305e33349a84406814f9b17470d5499a Mon Sep 17 00:00:00 2001 From: Andreas Madsen Date: Wed, 20 Jan 2016 18:20:43 +0100 Subject: [PATCH] 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 Reviewed-By: Sakthipriyan Vairamani --- src/async-wrap-inl.h | 7 +++++-- .../test-async-wrap-disabled-propagate-parent.js | 13 ++++++++++--- test/parallel/test-async-wrap-propagate-parent.js | 15 ++++++++++++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/async-wrap-inl.h b/src/async-wrap-inl.h index e68c6af4d6..e6b24af7fd 100644 --- a/src/async-wrap-inl.h +++ b/src/async-wrap-inl.h @@ -42,11 +42,14 @@ inline AsyncWrap::AsyncWrap(Environment* env, v8::Local 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 ret = init_fn->Call(env->context(), object, ARRAY_SIZE(argv), argv); diff --git a/test/parallel/test-async-wrap-disabled-propagate-parent.js b/test/parallel/test-async-wrap-disabled-propagate-parent.js index 0b987a5495..ee674c43ff 100644 --- a/test/parallel/test-async-wrap-disabled-propagate-parent.js +++ b/test/parallel/test-async-wrap-disabled-propagate-parent.js @@ -6,17 +6,24 @@ 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 server; 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'); }); } diff --git a/test/parallel/test-async-wrap-propagate-parent.js b/test/parallel/test-async-wrap-propagate-parent.js index 99322b03f7..c27803832d 100644 --- a/test/parallel/test-async-wrap-propagate-parent.js +++ b/test/parallel/test-async-wrap-propagate-parent.js @@ -4,17 +4,26 @@ 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 server; 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'); }); }